annotate inkscape/firefox/jqSOAPClient.js @ 272:01439f28d0bd

Check-in primitive integrated madbuilder code.
author wycc
date Mon, 26 Jan 2009 01:36:04 +0800
parents
children 892d86c1a409
rev   line source
272
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
1 /*
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
2 This program is free software: you can redistribute it and/or modify
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
3 it under the terms of the GNU General Public License as published by
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
4 the Free Software Foundation, either version 3 of the License, or
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
5 (at your option) any later version.
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
6
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
7 This program is distributed in the hope that it will be useful,
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
10 GNU General Public License for more details.
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
11
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
12 You should have received a copy of the GNU General Public License
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
13 along with this program. If not, see <http://www.gnu.org/licenses/>.
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
14 */
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
15 //Singleton SOAP Client
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
16 var SOAPClient = {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
17 Proxy: "",
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
18 SOAPServer: "",
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
19 ContentType: "text/xml",
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
20 CharSet: "utf-8",
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
21 ResponseXML: null,
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
22 ResponseText: "",
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
23 Status: 0,
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
24 ContentLength: 0,
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
25 Namespace: function(name, uri) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
26 return {"name":name, "uri":uri};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
27 },
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
28 SendRequest: function(soapReq, callback) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
29 if(!!SOAPClient.Proxy) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
30 SOAPClient.ResponseText = "";
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
31 SOAPClient.ResponseXML = null;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
32 SOAPClient.Status = 0;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
33
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
34 var content = soapReq.toString();
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
35 SOAPClient.ContentLength = content.length;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
36
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
37 function getResponse(xData) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
38 if(!!callback) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
39 SOAPClient.Status = xData.status;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
40 SOAPClient.ResponseText = xData.responseText;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
41 SOAPClient.ResponseXML = xData.responseXML;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
42 var jsOut = $.xmlToJSON(xData.responseXML);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
43 callback(jsOut);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
44 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
45 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
46 $.ajax({
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
47 type: "POST",
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
48 url: SOAPClient.Proxy,
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
49 dataType: "xml",
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
50 processData: false,
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
51 data: content,
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
52 complete: getResponse,
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
53 contentType: SOAPClient.ContentType + "; charset=\"" + SOAPClient.CharSet + "\"",
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
54 beforeSend: function(req) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
55 req.setRequestHeader("Method", "POST");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
56 req.setRequestHeader("Content-Length", SOAPClient.ContentLength);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
57 req.setRequestHeader("SOAPServer", SOAPClient.SOAPServer);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
58 req.setRequestHeader("SOAPAction", soapReq.Action);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
59 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
60 });
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
61 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
62 },
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
63 ToXML: function(soapObj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
64 var out = [];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
65 var isNSObj=false;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
66 try {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
67 if(!!soapObj&&typeof(soapObj)==="object"&&soapObj.typeOf==="SOAPObject") {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
68 //Namespaces
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
69 if(!!soapObj.ns) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
70 if(typeof(soapObj.ns)==="object") {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
71 isNSObj=true;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
72 out.push("<"+soapObj.ns.name+":"+soapObj.name);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
73 out.push(" xmlns:"+soapObj.ns.name+"=\""+soapObj.ns.uri+"\"");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
74 } else {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
75 out.push("<"+soapObj.name);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
76 out.push(" xmlns=\""+soapObj.ns+"\"");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
77 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
78 } else {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
79 out.push("<"+soapObj.name);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
80 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
81 //Node Attributes
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
82 if(soapObj.attributes.length > 0) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
83 var cAttr;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
84 var aLen=soapObj.attributes.length-1;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
85 do {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
86 cAttr=soapObj.attributes[aLen];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
87 if(isNSObj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
88 out.push(" "+soapObj.ns.name+":"+cAttr.name+"=\""+cAttr.value+"\"");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
89 } else {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
90 out.push(" "+cAttr.name+"=\""+cAttr.value+"\"");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
91 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
92 } while(aLen--);
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
93 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
94 out.push(">");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
95 //Node children
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
96 if(soapObj.hasChildren()) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
97 var cPos, cObj;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
98 for(cPos in soapObj.children){
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
99 cObj = soapObj.children[cPos];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
100 if(typeof(cObj)==="object"){out.push(SOAPClient.ToXML(cObj));}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
101 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
102 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
103 //Node Value
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
104 if(!!soapObj.value){out.push(soapObj.value);}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
105 //Close Tag
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
106 if(isNSObj){out.push("</"+soapObj.ns.name+":"+soapObj.name+">");}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
107 else {out.push("</"+soapObj.name+">");}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
108 return out.join("");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
109 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
110 } catch(e){alert("Unable to process SOAPObject! Object must be an instance of SOAPObject");}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
111 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
112 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
113 //Soap request - this is what being sent using SOAPClient.SendRequest
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
114 var SOAPRequest=function(action, soapObj) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
115 this.Action=action;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
116 var nss=[];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
117 var headers=[];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
118 var bodies=(!!soapObj)?[soapObj]:[];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
119 this.addNamespace=function(ns, uri){nss.push(new SOAPClient.Namespace(ns, uri));};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
120 this.addHeader=function(soapObj){headers.push(soapObj);};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
121 this.addBody=function(soapObj){bodies.push(soapObj);};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
122 this.toString=function() {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
123 var soapEnv = new SOAPObject("soapenv:Envelope");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
124 soapEnv.attr("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/");
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
125 //Add Namespace(s)
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
126 if(nss.length>0){
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
127 var tNs, tNo;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
128 for(tNs in nss){if(!nss.hasOwnProperty || nss.hasOwnProperty(tNs)){tNo=nss[tNs];if(typeof(tNo)==="object"){soapEnv.attr("xmlns:"+tNo.name, tNo.uri);}}}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
129 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
130 //Add Header(s)
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
131 if(headers.length>0) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
132 var soapHeader = soapEnv.appendChild(new SOAPObject("soapenv:Header"));
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
133 var tHdr;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
134 for(tHdr in headers){if(!headers.hasOwnProperty || headers.hasOwnProperty(tHdr)){soapHeader.appendChild(headers[tHdr]);}}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
135 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
136 //Add Body(s)
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
137 if(bodies.length>0) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
138 var soapBody = soapEnv.appendChild(new SOAPObject("soapenv:Body"));
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
139 var tBdy;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
140 for(tBdy in bodies){if(!bodies.hasOwnProperty || bodies.hasOwnProperty(tBdy)){soapBody.appendChild(bodies[tBdy]);}}
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
141 }
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
142 return soapEnv.toString();
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
143 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
144 };
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
145
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
146 //Soap Object - Used to build body envelope and other structures
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
147 var SOAPObject = function(name) {
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
148 this.typeOf="SOAPObject";
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
149 this.ns=null;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
150 this.name=name;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
151 this.attributes=[];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
152 this.children=[];
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
153 this.value=null;
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
154 this.attr=function(name, value){this.attributes.push({"name":name, "value":value});return this;};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
155 this.appendChild=function(obj){this.children.push(obj);return obj;};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
156 this.hasChildren=function(){return (this.children.length > 0)?true:false;};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
157 this.val=function(v){if(!v){return this.value;}else{this.value=v;return this;}};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
158 this.toString=function(){return SOAPClient.ToXML(this);};
01439f28d0bd Check-in primitive integrated madbuilder code.
wycc
parents:
diff changeset
159 };