Ignore:
Timestamp:
06/06/08 13:54:09 (16 years ago)
Author:
niltonneto
Message:

Correçoes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/instant_messenger/js/xtools.js

    r260 r305  
    1 function XTools() 
     1(function() 
    22{ 
    3 } 
     3        var _FILES = []; 
    44 
    5 XTools.prototype = { 
    6         'convert' : function(pString) 
     5        function _convert(pString) 
    76        { 
    87                if ( typeof pString != 'string' ) 
    98                        return false; 
    109 
    11                 if (window.ActiveXObject) 
     10                if ( window.ActiveXObject ) 
    1211                { 
    13                         var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
    14                         xmlDoc.async = "false"; 
    15                         xmlDoc.loadXML(pString); 
     12                        var _xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
     13                        _xmlDoc.async = "false"; 
     14                        _xmlDoc.loadXML(pString); 
    1615                } 
    1716                else 
    1817                { 
    1918                        var parser = new DOMParser(); 
    20                         var xmlDoc = parser.parseFromString(pString, "text/xml"); 
     19                        var _xmlDoc = parser.parseFromString(pString, "text/xml"); 
    2120                } 
    2221 
    23                 return xmlDoc; 
    24         }, 
    25         'load' : function(pFile) 
     22                return _xmlDoc; 
     23        } 
     24 
     25        function _load(pFile) 
    2626        { 
    27                 var data = null; 
    28                 if ( document.implementation.createDocument ) 
    29                         data = document.implementation.createDocument("", "", null); 
     27                pFile = this._PATH + 'xsl/' + pFile; 
     28                if ( !(_FILES[pFile]) ) 
     29                { 
     30                        var _data = null; 
     31                        if ( document.implementation.createDocument ) 
     32                                _data = document.implementation.createDocument("", "", null); 
     33                        else 
     34                                _data = new ActiveXObject("Msxml2.FreeThreadedDOMDocument"); 
     35 
     36                        _data.async = false; 
     37                        _data.load(pFile + '?' + Date.parse(new Date)); 
     38                        _FILES[pFile] = _data; 
     39                } 
     40                return _FILES[pFile]; 
     41        } 
     42 
     43        function _parse() 
     44        { 
     45                if ( arguments.length == 1 ) 
     46                { 
     47                        pXML = _xml('root'); 
     48                        pXSL = arguments[0]; 
     49                } 
    3050                else 
    31                         data = new ActiveXObject("Msxml2.FreeThreadedDOMDocument"); 
     51                { 
     52                        pXML = arguments[0]; 
     53                        pXSL = arguments[1]; 
     54                } 
     55                switch ( typeof pXML ) 
     56                { 
     57                        case 'object' : 
     58                        break; 
     59                        case 'string' : 
     60                                if ( pXML.indexOf('<') == 0 ) 
     61                                        pXML = _convert(pXML); 
     62                                else 
     63                                        pXML = _load.call(this, pXML); 
     64                        break; 
     65                        default : 
     66                                return {'error':'invalid xml'} 
     67                } 
     68                switch ( typeof pXSL ) 
     69                { 
     70                        case 'object' : 
     71                        break; 
     72                        case 'string' : 
     73                                pXSL = _load.call(this, pXSL); 
     74                        break; 
     75                        default : 
     76                                return {'error':'invalid xsl'} 
     77                } 
    3278 
    33                 data.async = false; 
    34                 data.load( path_im + 'xsl/' + pFile + '?' + Date.parse(new Date)); 
    35                 return data; 
    36         }, 
    37         'parse' : function(pXML, pXSL) 
    38         { 
    39                 try 
     79                var fragment = null; 
     80                if ( window.XSLTProcessor ) 
    4081                { 
    41                         switch ( typeof pXML ) 
     82                        var xslProc = new XSLTProcessor(); 
     83                        xslProc.importStylesheet(pXSL); 
     84 
     85                        if ( (arguments.length == 3) && (typeof arguments[2] == 'object') ) 
    4286                        { 
    43                                 case 'object' : 
    44                                 break; 
    45                                 case 'string' : 
    46                                         if ( pXML.indexOf('<') == 0 ) 
    47                                                 pXML = this.convert(pXML); 
    48                                         else 
    49                                                 pXML = this.load(pXML); 
    50                                 break; 
    51                                 default : 
    52                                         return {'error':'invalid xml'} 
    53                         } 
    54                         switch ( typeof pXSL ) 
    55                         { 
    56                                 case 'object' : 
    57                                 break; 
    58                                 case 'string' : 
    59                                         pXSL = this.load(pXSL); 
    60                                 break; 
    61                                 default : 
    62                                         return {'error':'invalid xsl'} 
     87                                var params = arguments[2]; 
     88                                for (var i in params ) 
     89                                         xslProc.setParameter(null, i, params[i]); 
    6390                        } 
    6491 
    65                         var fragment = null; 
    66                         if ( window.XSLTProcessor ) 
     92                        fragment = xslProc.transformToFragment(pXML, document); 
     93 
     94                        // para retornar valor igual ao ie. 
     95                        var aux = document.createElement("div"); 
     96                        aux.appendChild(fragment); 
     97                        fragment = aux.innerHTML; 
     98                } 
     99                else 
     100                { 
     101                        var xslTemplate = new ActiveXObject("MSXML2.XSLTemplate"); 
     102                        xslTemplate.stylesheet = pXSL; 
     103 
     104                        var xslProc = xslTemplate.createProcessor(); 
     105                        xslProc.input = pXML; 
     106 
     107                        if ( (arguments.length == 3) && (typeof arguments[2] == 'object') ) 
    67108                        { 
    68                                 var xslProc = new XSLTProcessor(); 
    69                                 xslProc.importStylesheet(pXSL); 
    70                                 fragment = xslProc.transformToFragment(pXML, document); 
     109                                var params = arguments[2]; 
     110                                for (var i in params ) 
     111                                         xslProc.addParameter(i, params[i], ''); 
     112                        } 
    71113 
    72                                 // para retornar valor igual ao ie. 
    73                                 var aux = document.createElement("div"); 
    74                                 aux.appendChild(fragment); 
    75                                 fragment = aux.innerHTML; 
    76                         } 
    77                         else 
    78                         { 
    79                                 var xslTemplate = new ActiveXObject("MSXML2.XSLTemplate"); 
    80                                 xslTemplate.stylesheet = pXSL; 
     114                        xslProc.transform(); 
     115                        fragment = xslProc.output; 
     116                } 
     117                return fragment; 
     118        } 
    81119 
    82                                 var myXslProc = xslTemplate.createProcessor(); 
    83                                 myXslProc.input = pXML; 
     120        function _xml() 
     121        { 
     122                var a = false; 
     123                if ( document.implementation.createDocument ) 
     124                        a = document.implementation.createDocument("", "", null); 
     125                else if ( ActiveXObject ) 
     126                        a = new ActiveXObject("Msxml2.DOMDocument"); 
    84127 
    85                                 myXslProc.transform(); 
    86                                 fragment = myXslProc.output; 
    87                         } 
    88                         return fragment; 
    89                 } 
    90                 catch(e) 
    91                 { 
    92                         alert("transform\n\n" + e + "\n\n" + e.description); 
    93                 } 
    94         }, 
    95         'xml' : function() 
     128                if ( arguments.length == 1 && typeof arguments[0] == 'string' ) 
     129                        a.appendChild(a.createElement(arguments[0])); 
     130                //with ( a ) 
     131                //      appendChild(createProcessingInstruction("xml", "version='1.0'")); 
     132 
     133                return a; 
     134        } 
     135 
     136        function XTools() 
    96137        { 
    97                 try 
    98                 { 
    99                         var a = false; 
    100                         if ( document.implementation.createDocument ) 
    101                                 a = document.implementation.createDocument("", "", null); 
    102                         else if ( ActiveXObject ) 
    103                                 a = new ActiveXObject("Msxml2.DOMDocument"); 
     138                var _argv = arguments; 
     139                this._PATH = ( _argv.length > 0 ) ? 
     140                        _argv[0] : ''; 
     141                if ( this._PATH != '' && this._PATH.lastIndexOf('/') != (this._PATH.length - 1) ) 
     142                        this._PATH += '/'; 
     143        } 
    104144 
    105                         //with ( a ) 
    106                         //      appendChild(createProcessingInstruction("xml", "version='1.0'")); 
    107  
    108                         return a; 
    109                 } 
    110                 catch(e) 
    111                 { 
    112                         alert("create\n\n" + e + "\n\n" + e.description); 
    113                 } 
    114         } 
    115 }; 
     145        XTools.prototype.convert = _convert; 
     146        XTools.prototype.load = _load; 
     147        XTools.prototype.parse = _parse; 
     148        XTools.prototype.xml = _xml; 
     149        window.XTools = XTools; 
     150} 
     151)(); 
Note: See TracChangeset for help on using the changeset viewer.