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

Revision 3687, 3.5 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                                        if ( params[ i ] && params[ i ].constructor != Function )
102                                                xslProc.setParameter(null, String( i ), String( params[i] ) );
103                        }
104
105                        fragment = xslProc.transformToFragment(pXML, document);
106
107                        // para retornar valor igual ao ie.
108                        var aux = document.createElement("div");
109                        aux.appendChild(fragment);
110                        fragment = aux.innerHTML;
111                }
112                else
113                {
114                        var xslTemplate = new ActiveXObject("MSXML2.XSLTemplate");
115                        xslTemplate.stylesheet = pXSL;
116
117                        var xslProc = xslTemplate.createProcessor();
118                        xslProc.input = pXML;
119
120                        if ( (arguments.length == 3) && (typeof arguments[2] == 'object') )
121                        {
122                                var params = arguments[2];
123                                for (var i in params )
124                                        if ( params[ i ] && params[ i ].constructor != Function )
125                                        {
126                                                xslProc.addParameter( String( i ), String( params[i] ), '');
127                                        }
128                        }
129
130                        xslProc.transform();
131                        fragment = xslProc.output;
132                }
133                return fragment;
134        }
135
136        function _xml()
137        {
138                var a = false;
139                if ( document.implementation.createDocument )
140                        a = document.implementation.createDocument("", "", null);
141                else if ( ActiveXObject )
142                        a = new ActiveXObject("Msxml2.DOMDocument");
143
144                if ( arguments.length == 1 && typeof arguments[0] == 'string' )
145                        a.appendChild(a.createElement(arguments[0]));
146                //with ( a )
147                //      appendChild(createProcessingInstruction("xml", "version='1.0'"));
148
149                return a;
150        }
151
152        function xtools()
153        {
154                var _argv = arguments;
155                this._PATH = ( _argv.length > 0 ) ? _argv[0] : '';
156
157                if ( this._PATH != '' && this._PATH.lastIndexOf('/') != (this._PATH.length - 1) )
158                        this._PATH += '/';
159        }
160
161        xtools.prototype.convert        = _convert;
162        xtools.prototype.load           = _load;
163        xtools.prototype.parse          = _parse;
164        xtools.prototype.xml            = _xml;
165       
166        window.xtools = xtools;
167}
168)();
Note: See TracBrowser for help on using the repository browser.