source: trunk/instant_messenger/js/xtools.js @ 151

Revision 151, 2.3 KB checked in by niltonneto, 16 years ago (diff)

Commit da nova versão do módulo, usando agente em C.
Vide Página do módulo do Trac:
http://www.expressolivre.org/dev/wiki/messenger

A versão anterior encontra-se na subpasta bkp (32/64).

Line 
1function XTools()
2{
3}
4
5XTools.prototype = {
6        'convert' : function(pString)
7        {
8                if ( typeof pString != 'string' )
9                        return false;
10
11                if (window.ActiveXObject)
12                {
13                        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
14                        xmlDoc.async = "false";
15                        xmlDoc.loadXML(pString);
16                }
17                else
18                {
19                        var parser = new DOMParser();
20                        var xmlDoc = parser.parseFromString(pString, "text/xml");
21                }
22
23                return xmlDoc;
24        },
25        'load' : function(pFile)
26        {
27                var data = null;
28                if ( document.implementation.createDocument )
29                        data = document.implementation.createDocument("", "", null);
30                else
31                        data = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
32
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
40                {
41                        switch ( typeof pXML )
42                        {
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'}
63                        }
64
65                        var fragment = null;
66                        if ( window.XSLTProcessor )
67                        {
68                                var xslProc = new XSLTProcessor();
69                                xslProc.importStylesheet(pXSL);
70                                fragment = xslProc.transformToFragment(pXML, document);
71
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;
81
82                                var myXslProc = xslTemplate.createProcessor();
83                                myXslProc.input = pXML;
84
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()
96        {
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");
104
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};
Note: See TracBrowser for help on using the repository browser.