source: branches/2.2/jabberit_messenger/js/xtools.js @ 3687

Revision 3687, 3.3 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1091 - Bloqueio das salas de bate-papo por OU dentro do modulo IM

  • Property svn:executable set to *
Line 
1(function()
2{
3        var _FILES = [];
4
5        function _convert(pString)
6        {
7                if ( typeof pString != 'string' )
8                        return false;
9
10                if ( window.ActiveXObject )
11                {
12                        var _xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
13                        _xmlDoc.async = "false";
14                        _xmlDoc.loadXML(pString);
15                }
16                else
17                {
18                        var parser = new DOMParser();
19                        var _xmlDoc = parser.parseFromString( pString, "text/xml" );
20                }
21
22                return _xmlDoc;
23        }
24
25        function _load(pFile)
26        {
27                pFile = this._PATH + 'xsl/' + pFile;
28                if ( !(_FILES[pFile]) )
29                {
30                        var _data = null;
31                       
32                        if ( document.implementation.createDocument )
33                        {
34                                var xmlHttp = new window.XMLHttpRequest();
35                                        xmlHttp.open("GET",pFile + '?' + Date.parse(new Date),false );
36                                        xmlHttp.send(null);
37                               
38                                _data = xmlHttp.responseXML.documentElement;
39                        }
40                        else
41                        {
42                                _data = new ActiveXObject( "Msxml2.FreeThreadedDOMDocument" );
43                                _data.async = false;
44                                _data.load( pFile + '?' + Date.parse(new Date) );
45                        }
46
47                        _FILES[pFile] = _data;
48                }
49                return _FILES[pFile];
50        }
51
52        function _parse()
53        {
54                if ( arguments.length == 1 )
55                {
56                        pXML = _xml('root');
57                        pXSL = arguments[0];
58                }
59                else
60                {
61                        pXML = arguments[0];
62                        pXSL = arguments[1];
63                }
64               
65                switch ( typeof pXML )
66                {
67                        case 'object' :
68                        break;
69                        case 'string' :
70                                if ( pXML.indexOf('<') == 0 )
71                                        pXML = _convert(pXML);
72                                else
73                                        pXML = _load.call(this, pXML);
74                        break;
75                        default :
76                                return { 'error' : 'invalid xml' }
77                }
78               
79                switch ( typeof pXSL )
80                {
81                        case 'object' :
82                        break;
83                        case 'string' :
84                                pXSL = _load.call(this, pXSL);
85                        break;
86                        default :
87                                return {'error':'invalid xsl'}
88                }
89
90                var fragment = null;
91               
92                if ( window.XSLTProcessor )
93                {
94                        var xslProc = new XSLTProcessor();
95                        xslProc.importStylesheet(pXSL);
96
97                        if ( (arguments.length == 3) && (typeof arguments[2] == 'object') )
98                        {
99                                var params = arguments[2];
100                                for (var i in params )
101                                         xslProc.setParameter(null, i, params[i]);
102                        }
103
104                        fragment = xslProc.transformToFragment(pXML, document);
105
106                        // para retornar valor igual ao ie.
107                        var aux = document.createElement("div");
108                        aux.appendChild(fragment);
109                        fragment = aux.innerHTML;
110                }
111                else
112                {
113                        var xslTemplate = new ActiveXObject("MSXML2.XSLTemplate");
114                        xslTemplate.stylesheet = pXSL;
115
116                        var xslProc = xslTemplate.createProcessor();
117                        xslProc.input = pXML;
118
119                        if ( (arguments.length == 3) && (typeof arguments[2] == 'object') )
120                        {
121                                var params = arguments[2];
122                                for (var i in params )
123                                         xslProc.addParameter(i, params[i], '');
124                        }
125
126                        xslProc.transform();
127                        fragment = xslProc.output;
128                }
129                return fragment;
130        }
131
132        function _xml()
133        {
134                var a = false;
135                if ( document.implementation.createDocument )
136                        a = document.implementation.createDocument("", "", null);
137                else if ( ActiveXObject )
138                        a = new ActiveXObject("Msxml2.DOMDocument");
139
140                if ( arguments.length == 1 && typeof arguments[0] == 'string' )
141                        a.appendChild(a.createElement(arguments[0]));
142                //with ( a )
143                //      appendChild(createProcessingInstruction("xml", "version='1.0'"));
144
145                return a;
146        }
147
148        function xtools()
149        {
150                var _argv = arguments;
151                this._PATH = ( _argv.length > 0 ) ? _argv[0] : '';
152
153                if ( this._PATH != '' && this._PATH.lastIndexOf('/') != (this._PATH.length - 1) )
154                        this._PATH += '/';
155        }
156
157        xtools.prototype.convert        = _convert;
158        xtools.prototype.load           = _load;
159        xtools.prototype.parse          = _parse;
160        xtools.prototype.xml            = _xml;
161       
162        window.JITXtools = xtools;
163}
164)();
Note: See TracBrowser for help on using the repository browser.