[6785] | 1 | /** |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 3 | * contributor license agreements. See the NOTICE file distributed with this |
---|
| 4 | * work for additional information regarding copyright ownership. The ASF |
---|
| 5 | * licenses this file to you under the Apache License, Version 2.0 (the |
---|
| 6 | * "License"); you may not use this file except in compliance with the License. |
---|
| 7 | * You may obtain a copy of the License at |
---|
| 8 | * |
---|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | * |
---|
| 11 | * Unless required by applicable law or agreed to in writing, software |
---|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
---|
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
---|
| 14 | * License for the specific language governing permissions and limitations under |
---|
| 15 | * the License. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | // This code is structured on to require a 'new' of an object of type |
---|
| 19 | // CxfApacheOrgUtil. |
---|
| 20 | // Alternative, it could be made 'static', but this allowed us to use this same |
---|
| 21 | // object to carry some state. |
---|
| 22 | var org_apache_cxf_XSI_namespace_uri = "http://www.w3.org/2001/XMLSchema-instance"; |
---|
| 23 | var org_apache_cxf_XSD_namespace_uri = "http://www.w3.org/2001/XMLSchema"; |
---|
| 24 | |
---|
| 25 | function cxf_apache_org_util_null_trace(message) { |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | function CxfApacheOrgUtil() { |
---|
| 29 | // Set up tracing if there is a trace object. |
---|
| 30 | if ("function" == typeof(org_apache_cxf_trace)) { |
---|
| 31 | this.trace = org_apache_cxf_trace.trace; |
---|
| 32 | this.trace("Javascript tracing enabled."); |
---|
| 33 | } else { |
---|
| 34 | this.trace = cxf_apache_org_util_null_trace; |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | // define a constant for the DOM node type for an element. |
---|
| 39 | CxfApacheOrgUtil.prototype.ELEMENT_NODE = 1; |
---|
| 40 | |
---|
| 41 | // compensate for Microsoft's weakness here. |
---|
| 42 | function org_apache_cxf_getNodeLocalName(node) { |
---|
| 43 | if ("localName" in node) { |
---|
| 44 | return node.localName; |
---|
| 45 | } else { |
---|
| 46 | return node.baseName; |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | CxfApacheOrgUtil.prototype.getNodeLocalName = org_apache_cxf_getNodeLocalName; |
---|
| 51 | |
---|
| 52 | // compensate for lack of namespace support in IE. |
---|
| 53 | function org_apache_cxf_getNamespaceURI(elementNode, namespacePrefix) { |
---|
| 54 | var namespaceURI = null; |
---|
| 55 | if (elementNode.nodeType == 9) |
---|
| 56 | return null; |
---|
| 57 | else { |
---|
| 58 | namespaceURI = org_apache_cxf_findNamespace(elementNode, |
---|
| 59 | namespacePrefix); |
---|
| 60 | if (namespaceURI == null) |
---|
| 61 | namespaceURI = org_apache_cxf_getNamespaceURI( |
---|
| 62 | elementNode.parentNode, namespacePrefix); |
---|
| 63 | else |
---|
| 64 | return namespaceURI; |
---|
| 65 | } |
---|
| 66 | return namespaceURI; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | // Search through the attributes of one node to find a namespace prefix definition. |
---|
| 70 | function org_apache_cxf_findNamespace(elementNode, namespacePrefix) { |
---|
| 71 | var attributes = elementNode.attributes; |
---|
| 72 | if ((attributes != null) && (attributes.length > 0)) { |
---|
| 73 | for (var x = 0;x < attributes.length; x++) { |
---|
| 74 | var attributeNodeName = attributes.item(x).nodeName; |
---|
| 75 | var attributeNamespacePrefix = org_apache_cxf_getPrefix(attributes |
---|
| 76 | .item(x).nodeName); |
---|
| 77 | var attributeNamespaceSuffix = org_apache_cxf_getLocalName(attributes |
---|
| 78 | .item(x).nodeName); |
---|
| 79 | |
---|
| 80 | if ((namespacePrefix == null) && (attributeNamespacePrefix == null) |
---|
| 81 | && (attributeNamespaceSuffix == "xmlns")) |
---|
| 82 | return attributes.item(x).nodeValue; |
---|
| 83 | else if ((attributeNamespacePrefix == "xmlns") |
---|
| 84 | && (attributeNamespaceSuffix == namespacePrefix)) |
---|
| 85 | return attributes.item(x).nodeValue; |
---|
| 86 | } |
---|
| 87 | return null; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | // Get namespace for a node. |
---|
| 92 | function org_apache_cxf_get_node_namespaceURI(elementNode) { |
---|
| 93 | var prefix = org_apache_cxf_getPrefix(elementNode.nodeName); |
---|
| 94 | return org_apache_cxf_getNamespaceURI(elementNode, prefix); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | CxfApacheOrgUtil.prototype.getElementNamespaceURI = org_apache_cxf_get_node_namespaceURI; |
---|
| 98 | |
---|
| 99 | // Supprt functions for xsd:any start here. |
---|
| 100 | |
---|
| 101 | // Object that can test an element against an 'any' specification. |
---|
| 102 | function org_apache_cxf_any_ns_matcher(style, tns, nslist, nextLocalPart) { |
---|
| 103 | this.style = style; |
---|
| 104 | this.tns = tns; |
---|
| 105 | this.nslist = nslist; |
---|
| 106 | this.nextLocalPart = nextLocalPart; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | org_apache_cxf_any_ns_matcher.ANY = "##any"; |
---|
| 110 | org_apache_cxf_any_ns_matcher.OTHER = "##other"; |
---|
| 111 | org_apache_cxf_any_ns_matcher.LOCAL = "##local"; |
---|
| 112 | org_apache_cxf_any_ns_matcher.LISTED = "listed"; |
---|
| 113 | |
---|
| 114 | function org_apache_cxf_any_ns_matcher_match(namespaceURI, localName) { |
---|
| 115 | switch (this.style) { |
---|
| 116 | // should this match local elements? |
---|
| 117 | case org_apache_cxf_any_ns_matcher.ANY : |
---|
| 118 | return true; |
---|
| 119 | case org_apache_cxf_any_ns_matcher.OTHER : |
---|
| 120 | return namespaceURI != this.tns; |
---|
| 121 | case org_apache_cxf_any_ns_matcher.LOCAL : |
---|
| 122 | return namespaceURI == null || namespaceURI == ''; |
---|
| 123 | case org_apache_cxf_any_ns_matcher.LISTED : |
---|
| 124 | for (var x in this.nslist) { |
---|
| 125 | var ns = this.nslist[x]; |
---|
| 126 | if (ns == "##local") { |
---|
| 127 | if ((namespaceURI == null || namespaceURI == '') |
---|
| 128 | && (this.nextLocalPart != null && localName != this.nextLocalPart)) |
---|
| 129 | return true; |
---|
| 130 | } else { |
---|
| 131 | if (ns == namespaceURI) |
---|
| 132 | return true; |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | return false; |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | org_apache_cxf_any_ns_matcher.prototype.match = org_apache_cxf_any_ns_matcher_match; |
---|
| 140 | |
---|
| 141 | function org_apache_cxf_getPrefix(tagName) { |
---|
| 142 | var prefix; |
---|
| 143 | var prefixIndex = tagName.indexOf(":"); |
---|
| 144 | if (prefixIndex == -1) |
---|
| 145 | return null; |
---|
| 146 | else |
---|
| 147 | return prefix = tagName.substring(0, prefixIndex); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | function org_apache_cxf_getLocalName(tagName) { |
---|
| 151 | var suffix; |
---|
| 152 | var prefixIndex = tagName.indexOf(":"); |
---|
| 153 | |
---|
| 154 | if (prefixIndex == -1) |
---|
| 155 | return tagName; |
---|
| 156 | else |
---|
| 157 | return suffix = tagName.substring(prefixIndex + 1, tagName.length); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | function org_apache_cxf_element_name_for_trace(node) { |
---|
| 161 | if (node == null) |
---|
| 162 | return "Null"; |
---|
| 163 | else if (node == undefined) |
---|
| 164 | return "Undefined"; |
---|
| 165 | else { |
---|
| 166 | var n = ''; |
---|
| 167 | if (node.namespaceURI != null && node.namespaceURI != '') { |
---|
| 168 | n = n + "{" + node.namespaceURI + "}"; |
---|
| 169 | } |
---|
| 170 | return n + this.getNodeLocalName(node); |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | CxfApacheOrgUtil.prototype.traceElementName = org_apache_cxf_element_name_for_trace; |
---|
| 175 | |
---|
| 176 | function org_apache_cxf_escapeXmlEntities(val) { |
---|
| 177 | if (val == null || val == undefined) |
---|
| 178 | return ""; |
---|
| 179 | else { |
---|
| 180 | val = String(val); |
---|
| 181 | return val.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, |
---|
| 182 | ">"); |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | CxfApacheOrgUtil.prototype.escapeXmlEntities = org_apache_cxf_escapeXmlEntities; |
---|
| 187 | |
---|
| 188 | // Is an element xsi:nil? Note, in IE this requires the use of the prefix 'xsi', literally. |
---|
| 189 | function org_apache_cxf_isElementNil(node) { |
---|
| 190 | if (node == null) |
---|
| 191 | throw "null node passed to isElementNil"; |
---|
| 192 | // we need to look for an attribute xsi:nil, where xsi is |
---|
| 193 | // http://www.w3.org/2001/XMLSchema-instance. we have the usual |
---|
| 194 | // problem here with namespace-awareness. |
---|
| 195 | if ('function' == typeof node.getAttributeNS) { |
---|
| 196 | var nillness = node.getAttributeNS( |
---|
| 197 | "http://www.w3.org/2001/XMLSchema-instance", "nil"); |
---|
| 198 | return nillness != null && nillness == "true"; |
---|
| 199 | } else { // we assume the standard prefix and hope for the best. |
---|
| 200 | var nillness = node.getAttribute("xsi:nil"); |
---|
| 201 | return nillness != null && nillness == "true"; |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | CxfApacheOrgUtil.prototype.isElementNil = org_apache_cxf_isElementNil; |
---|
| 206 | |
---|
| 207 | function org_apache_cxf_getFirstElementChild(node) { |
---|
| 208 | if (node == undefined) |
---|
| 209 | throw "undefined node to getFirstElementChild"; |
---|
| 210 | |
---|
| 211 | var n; |
---|
| 212 | for (n = node.firstChild;n != null && n.nodeType != this.ELEMENT_NODE; n = n.nextSibling) { |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | return n; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | CxfApacheOrgUtil.prototype.getFirstElementChild = org_apache_cxf_getFirstElementChild; |
---|
| 219 | |
---|
| 220 | function org_apache_cxf_getNextElementSibling(node) { |
---|
| 221 | if (node == undefined) |
---|
| 222 | throw "undefined node to getNextElementSibling"; |
---|
| 223 | if (node == null) |
---|
| 224 | throw "null node to getNextElementSibling"; |
---|
| 225 | var n; |
---|
| 226 | for (n = node.nextSibling;n != null && n.nodeType != this.ELEMENT_NODE; n = n.nextSibling); |
---|
| 227 | return n; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | CxfApacheOrgUtil.prototype.getNextElementSibling = org_apache_cxf_getNextElementSibling; |
---|
| 231 | |
---|
| 232 | function org_apache_cxf_isNodeNamedNS(node, namespaceURI, localName) { |
---|
| 233 | if (node == undefined) |
---|
| 234 | throw "undefined node to isNodeNamedNS"; |
---|
| 235 | |
---|
| 236 | if (namespaceURI == '' || namespaceURI == null) { |
---|
| 237 | if (node.namespaceURI == '' || node.namespaceURI == null) { |
---|
| 238 | return localName == org_apache_cxf_getNodeLocalName(node); |
---|
| 239 | } else |
---|
| 240 | return false; |
---|
| 241 | } else { |
---|
| 242 | return namespaceURI == node.namespaceURI |
---|
| 243 | && localName == org_apache_cxf_getNodeLocalName(node); |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | CxfApacheOrgUtil.prototype.isNodeNamedNS = org_apache_cxf_isNodeNamedNS; |
---|
| 248 | |
---|
| 249 | // Firefox splits large text regions into multiple Text objects (4096 chars in |
---|
| 250 | // each). Glue it back together. |
---|
| 251 | function org_apache_cxf_getNodeText(node) { |
---|
| 252 | var r = ""; |
---|
| 253 | for (var x = 0;x < node.childNodes.length; x++) { |
---|
| 254 | r = r + node.childNodes[x].nodeValue; |
---|
| 255 | } |
---|
| 256 | return r; |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | CxfApacheOrgUtil.prototype.getNodeText = org_apache_cxf_getNodeText; |
---|
| 260 | |
---|
| 261 | // This always uses soap-env, soap, and xsi as prefixes. |
---|
| 262 | function org_apache_cxf_begin_soap11_message(namespaceAttributes) { |
---|
| 263 | var value = '<?xml version="1.0" encoding="UTF-8"?>' |
---|
| 264 | + '<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"' |
---|
| 265 | + ' xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"' |
---|
| 266 | + ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' |
---|
| 267 | + '><soap-env:Body ' + namespaceAttributes + '>'; |
---|
| 268 | return value; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | CxfApacheOrgUtil.prototype.beginSoap11Message = org_apache_cxf_begin_soap11_message; |
---|
| 272 | |
---|
| 273 | function org_apache_cxf_end_soap11_message() { |
---|
| 274 | return '</soap-env:Body></soap-env:Envelope>'; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | CxfApacheOrgUtil.prototype.endSoap11Message = org_apache_cxf_end_soap11_message; |
---|
| 278 | |
---|
| 279 | var org_apache_cxf_base64_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; |
---|
| 280 | |
---|
| 281 | function org_apache_cxf_base64_encode64array(input) { |
---|
| 282 | var output = ""; |
---|
| 283 | var chr1, chr2, chr3; |
---|
| 284 | var enc1, enc2, enc3, enc4; |
---|
| 285 | var i = 0; |
---|
| 286 | |
---|
| 287 | do { |
---|
| 288 | var count = 1; |
---|
| 289 | chr1 = chr2 = chr3 = 0; |
---|
| 290 | |
---|
| 291 | chr1 = input[i++]; |
---|
| 292 | if (i < input.length) { |
---|
| 293 | chr2 = input[i++]; |
---|
| 294 | count++; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | if (i < input.length) { |
---|
| 298 | chr3 = input[i++]; |
---|
| 299 | count++; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | enc1 = chr1 >> 2; |
---|
| 303 | enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); |
---|
| 304 | if (count > 1) { |
---|
| 305 | enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); |
---|
| 306 | if (count > 2) |
---|
| 307 | enc4 = chr3 & 63; |
---|
| 308 | else |
---|
| 309 | enc4 = 64; |
---|
| 310 | } else |
---|
| 311 | enc3 = enc4 = 64; |
---|
| 312 | |
---|
| 313 | output = output + org_apache_cxf_base64_keyStr.charAt(enc1) |
---|
| 314 | + org_apache_cxf_base64_keyStr.charAt(enc2) |
---|
| 315 | + org_apache_cxf_base64_keyStr.charAt(enc3) |
---|
| 316 | + org_apache_cxf_base64_keyStr.charAt(enc4); |
---|
| 317 | } while (i < input.length); |
---|
| 318 | |
---|
| 319 | return output; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | function org_apache_cxf_base64_encode64Unicode(input) { |
---|
| 323 | var data = new Array(2 + (input.length * 2)); |
---|
| 324 | data[0] = 0xff; |
---|
| 325 | data[1] = 0xfe; |
---|
| 326 | for (var x = 0;x < input.length; x++) { |
---|
| 327 | var c = input.charCodeAt(x); |
---|
| 328 | data[2 + (x * 2)] = c & 0xff; |
---|
| 329 | data[3 + (x * 2)] = (c >> 8) & 0xff; |
---|
| 330 | } |
---|
| 331 | return encode64array(data); |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | // we may be able to do this more cleanly with unescape( encodeURIComponent( |
---|
| 335 | // input ) ); |
---|
| 336 | function org_apache_cxf_base64_encode64UTF8(input) { |
---|
| 337 | |
---|
| 338 | // determine how many bytes are needed for the complete conversion |
---|
| 339 | var bytesNeeded = 0; |
---|
| 340 | for (var i = 0;i < input.length; i++) { |
---|
| 341 | if (input.charCodeAt(i) < 0x80) { |
---|
| 342 | ++bytesNeeded; |
---|
| 343 | } else if (input.charCodeAt(i) < 0x0800) { |
---|
| 344 | bytesNeeded += 2; |
---|
| 345 | } else if (input.charCodeAt(i) < 0x10000) { |
---|
| 346 | bytesNeeded += 3; |
---|
| 347 | } else { |
---|
| 348 | bytesNeeded += 4; |
---|
| 349 | } |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | // allocate a byte[] of the necessary size |
---|
| 353 | var data = new Array(bytesNeeded); |
---|
| 354 | // do the conversion from character code points to utf-8 |
---|
| 355 | var bytes = 0; |
---|
| 356 | for (var i = 0;i < input.length; i++) { |
---|
| 357 | if (input.charCodeAt(i) < 0x80) { |
---|
| 358 | data[bytes++] = input.charCodeAt(i); |
---|
| 359 | } else if (input.charCodeAt(i) < 0x0800) { |
---|
| 360 | data[bytes++] = ((input.charCodeAt(i) >> 6) | 0xC0); |
---|
| 361 | data[bytes++] = ((input.charCodeAt(i) & 0x3F) | 0x80); |
---|
| 362 | } else if (input.charCodeAt(i) < 0x10000) { |
---|
| 363 | data[bytes++] = ((input.charCodeAt(i) >> 12) | 0xE0); |
---|
| 364 | data[bytes++] = (((input.charCodeAt(i) >> 6) & 0x3F) | 0x80); |
---|
| 365 | data[bytes++] = ((input.charCodeAt(i) & 0x3F) | 0x80); |
---|
| 366 | } else { |
---|
| 367 | data[bytes++] = ((input.charCodeAt(i) >> 18) | 0xF0); |
---|
| 368 | data[bytes++] = (((input.charCodeAt(i) >> 12) & 0x3F) | 0x80); |
---|
| 369 | data[bytes++] = (((input.charCodeAt(i) >> 6) & 0x3F) | 0x80); |
---|
| 370 | data[bytes++] = ((input.charCodeAt(i) & 0x3F) | 0x80); |
---|
| 371 | } |
---|
| 372 | } |
---|
| 373 | return encode64array(data); |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | function org_apache_cxf_base64_decode64array(input) { |
---|
| 377 | var output = new Array(); |
---|
| 378 | var chr1, chr2, chr3; |
---|
| 379 | var enc1, enc2, enc3, enc4; |
---|
| 380 | var i = 0; |
---|
| 381 | |
---|
| 382 | // remove all characters that are not A-Z, a-z, 0-9, +, /, or = |
---|
| 383 | input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); |
---|
| 384 | |
---|
| 385 | do { |
---|
| 386 | enc1 = org_apache_cxf_base64_keyStr.indexOf(input.charAt(i++)); |
---|
| 387 | enc2 = org_apache_cxf_base64_keyStr.indexOf(input.charAt(i++)); |
---|
| 388 | enc3 = org_apache_cxf_base64_keyStr.indexOf(input.charAt(i++)); |
---|
| 389 | enc4 = org_apache_cxf_base64_keyStr.indexOf(input.charAt(i++)); |
---|
| 390 | |
---|
| 391 | chr1 = (enc1 << 2) | (enc2 >> 4); |
---|
| 392 | chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); |
---|
| 393 | chr3 = ((enc3 & 3) << 6) | enc4; |
---|
| 394 | |
---|
| 395 | output[output.length] = chr1; |
---|
| 396 | |
---|
| 397 | if (enc3 != 64) { |
---|
| 398 | output[output.length] = chr2; |
---|
| 399 | } |
---|
| 400 | if (enc4 != 64) { |
---|
| 401 | output[output.length] = chr3; |
---|
| 402 | } |
---|
| 403 | } while (i < input.length); |
---|
| 404 | |
---|
| 405 | return output; |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | var org_apache_cxf_base64_hD = "0123456789ABCDEF"; |
---|
| 409 | function org_apache_cxf_base64_d2h(d) { |
---|
| 410 | var h = org_apache_cxf_base64_hD.substr(d & 15, 1); |
---|
| 411 | while (d > 15) { |
---|
| 412 | d >>= 4; |
---|
| 413 | h = org_apache_cxf_base64_hD.substr(d & 15, 1) + h; |
---|
| 414 | } |
---|
| 415 | return h; |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | function org_apache_cxf_base64_decode64Unicode(input) { |
---|
| 419 | var bytes = org_apache_cxf_base64_decode64array(input); |
---|
| 420 | var swap; |
---|
| 421 | var output = ""; |
---|
| 422 | if (bytes[0] == 0xff && bytes[1] == 0xfe) { |
---|
| 423 | swap = true; |
---|
| 424 | } else if (bytes[0] == 0xfe && bytes[1] == 0xff) { |
---|
| 425 | swap = false; |
---|
| 426 | } else { |
---|
| 427 | confirm("Problem with decoding utf-16"); |
---|
| 428 | } |
---|
| 429 | for (var x = 2;x < bytes.length; x = x + 2) { |
---|
| 430 | var c; |
---|
| 431 | if (swap) |
---|
| 432 | c = (bytes[x + 1] << 8) | bytes[x]; |
---|
| 433 | else |
---|
| 434 | c = (bytes[x] << 8) | bytes[x + 1]; |
---|
| 435 | |
---|
| 436 | output = output + String.fromCharCode(c); |
---|
| 437 | } |
---|
| 438 | return output; |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | // we may be able to do this more cleanly with decodeURIComponent( escape( input |
---|
| 442 | // ) ); |
---|
| 443 | function org_apache_cxf_base64_decode64UTF8(input) { |
---|
| 444 | var utftext = org_apache_cxf_base64_decode64array(input); |
---|
| 445 | var plaintext = ""; |
---|
| 446 | var cRay = new Array(); |
---|
| 447 | var i = 0; |
---|
| 448 | var c; |
---|
| 449 | var c2; |
---|
| 450 | var c3; |
---|
| 451 | while (i < utftext.length) { |
---|
| 452 | c = utftext[i]; |
---|
| 453 | if (c < 128) { |
---|
| 454 | plaintext += String.fromCharCode(c); |
---|
| 455 | i++; |
---|
| 456 | } else if ((c > 191) && (c < 224)) { |
---|
| 457 | c2 = utftext[i + 1]; |
---|
| 458 | plaintext += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); |
---|
| 459 | i += 2; |
---|
| 460 | } else { |
---|
| 461 | c2 = utftext[i + 1]; |
---|
| 462 | c3 = utftext[i + 2]; |
---|
| 463 | plaintext += String.fromCharCode(((c & 15) << 12) |
---|
| 464 | | ((c2 & 63) << 6) | (c3 & 63)); |
---|
| 465 | i += 3; |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | return plaintext; |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | // MTOM deserialization. |
---|
| 472 | // This assumes that the only content type it will be asked to deal with is text/plain;charset=utf-8. |
---|
| 473 | // This only handles cid: xop URNs. |
---|
| 474 | |
---|
| 475 | var org_apache_cxf_XOP_NS = 'http://www.w3.org/2004/08/xop/include'; |
---|
| 476 | |
---|
| 477 | function org_apache_cxf_deserialize_MTOM_or_base64(element) { |
---|
| 478 | var elementChild = this.getFirstElementChild(element); |
---|
| 479 | if (elementChild == null) { // no MTOM, assume base64 |
---|
| 480 | var base64Text = this.getNodeText(element); |
---|
| 481 | // we assume this is text/plain;charset=utf-8. We could check for the |
---|
| 482 | // xmime attribute. |
---|
| 483 | return org_apache_cxf_base64_decode64UTF8(base64Text); |
---|
| 484 | } |
---|
| 485 | // |
---|
| 486 | if (!org_apache_cxf_isNodeNamedNS(elementChild, org_apache_cxf_XOP_NS, 'Include')) { |
---|
| 487 | this.trace('Invalid child element of base64 element'); |
---|
| 488 | return ''; // we don't knoww what this is, so we throw it out. We could |
---|
| 489 | // throw. |
---|
| 490 | } |
---|
| 491 | var href = elementChild.getAttribute('href'); |
---|
| 492 | if(!href) { |
---|
| 493 | this.trace('missing href for xop:Include'); |
---|
| 494 | return ''; // we don't knoww what this is, so we throw it out. We could |
---|
| 495 | // throw. |
---|
| 496 | } |
---|
| 497 | // we only support cid:, not URLs. |
---|
| 498 | if(href.length < 4 || href.substr(0, 4) != 'cid:') { |
---|
| 499 | this.trace('Non-cid href in xop:Include: ' + href); |
---|
| 500 | return ''; |
---|
| 501 | } |
---|
| 502 | var cid = href.substr(4); |
---|
| 503 | var partobject = this.client.parts[cid]; |
---|
| 504 | if(!partobject) { |
---|
| 505 | this.trace('xop:Include href points to missing attachment: ' + href); |
---|
| 506 | return ''; |
---|
| 507 | } |
---|
| 508 | // success. |
---|
| 509 | return partobject.data; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | CxfApacheOrgUtil.prototype.deserializeBase64orMom = org_apache_cxf_deserialize_MTOM_or_base64; |
---|
| 513 | |
---|
| 514 | /* |
---|
| 515 | * Client object sends requests and calls back with responses. |
---|
| 516 | */ |
---|
| 517 | function CxfApacheOrgClient(utils) { |
---|
| 518 | utils.trace("Client constructor"); |
---|
| 519 | this.utils = utils; |
---|
| 520 | utils.client = this; // we aren't worried about multithreading! |
---|
| 521 | this.mtomparts = []; |
---|
| 522 | this.soapAction = ""; |
---|
| 523 | this.messageType = "CALL"; |
---|
| 524 | // handler functions |
---|
| 525 | this.onsuccess = null; |
---|
| 526 | this.onerror = null; |
---|
| 527 | // Firefox is noncompliant with respect to the defined constants, |
---|
| 528 | // so we define our own. |
---|
| 529 | this.READY_STATE_UNINITIALIZED = 0; |
---|
| 530 | this.READY_STATE_LOADING = 1; |
---|
| 531 | this.READY_STATE_LOADED = 2; |
---|
| 532 | this.READY_STATE_INTERACTIVE = 3; |
---|
| 533 | this.READY_STATE_DONE = 4; |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | var org_apache_cxf_pad_string_PAD_LEFT = 0; |
---|
| 537 | var org_apache_cxf_pad_string_PAD_RIGHT = 1; |
---|
| 538 | var org_apache_cxf_pad_string_PAD_BOTH = 2; |
---|
| 539 | |
---|
| 540 | function org_apache_cxf_pad_string(string, len, pad, type) { |
---|
| 541 | var append = new String(); |
---|
| 542 | |
---|
| 543 | len = isNaN(len) ? 0 : len - string.length; |
---|
| 544 | pad = typeof(pad) == 'string' ? pad : ' '; |
---|
| 545 | |
---|
| 546 | if (type == org_apache_cxf_pad_string_PAD_BOTH) { |
---|
| 547 | string = org_apache_cxf_pad_sring(Math.floor(len / 2) + string.length, |
---|
| 548 | pad, org_apache_cxf_pad_string_PAD_LEFT); |
---|
| 549 | return (org_apache_cxf_pad_string(Math.ceil(len / 2) + string.length, |
---|
| 550 | pad, org_apache_cxf_pad_string_PAD_RIGHT)); |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | while ((len -= pad.length) > 0) |
---|
| 554 | append += pad; |
---|
| 555 | append += pad.substr(0, len + pad.length); |
---|
| 556 | |
---|
| 557 | return (type == org_apache_cxf_pad_string_PAD_LEFT |
---|
| 558 | ? append.concat(string) |
---|
| 559 | : string.concat(append)); |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | /* |
---|
| 563 | * Generate a uniformly distributed random integer within the range <min> .. |
---|
| 564 | * <max>. (min) - Lower limit: random >= min (default: 0) (max) - Upper limit: |
---|
| 565 | * random <= max (default: 1) |
---|
| 566 | */ |
---|
| 567 | function org_apache_cxf_random_int(min, max) { |
---|
| 568 | if (!isFinite(min)) |
---|
| 569 | min = 0; |
---|
| 570 | if (!isFinite(max)) |
---|
| 571 | max = 1; |
---|
| 572 | return Math.floor((Math.random() % 1) * (max - min + 1) + min); |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | function org_apache_cxf_random_hex_string(len) { |
---|
| 576 | var random = org_apache_cxf_random_int(0, Math.pow(16, len) - 1); |
---|
| 577 | return org_apache_cxf_pad_string(random.toString(16), len, '0', |
---|
| 578 | org_apache_cxf_pad_string_PAD_LEFT); |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | function org_apache_cxf_make_uuid(type) { |
---|
| 582 | switch ((type || 'v4').toUpperCase()) { |
---|
| 583 | // Version 4 UUID (Section 4.4 of RFC 4122) |
---|
| 584 | case 'V4' : |
---|
| 585 | var tl = org_apache_cxf_random_hex_string(8); |
---|
| 586 | // time_low |
---|
| 587 | var tm = org_apache_cxf_random_hex_string(4); |
---|
| 588 | // time_mid |
---|
| 589 | var thav = '4' + org_apache_cxf_random_hex_string(3); |
---|
| 590 | // time_hi_and_version |
---|
| 591 | var cshar = org_apache_cxf_random_int(0, 0xFF); |
---|
| 592 | // clock_seq_hi_and_reserved |
---|
| 593 | cshar = ((cshar & ~(1 << 6)) | (1 << 7)).toString(16); |
---|
| 594 | var csl = org_apache_cxf_random_hex_string(2); |
---|
| 595 | // clock_seq_low |
---|
| 596 | var n = org_apache_cxf_random_hex_string(12); |
---|
| 597 | // node |
---|
| 598 | |
---|
| 599 | return (tl + '-' + tm + '-' + thav + '-' + cshar + csl + '-' + n); |
---|
| 600 | |
---|
| 601 | // Nil UUID (Section 4.1.7 of RFC 4122) |
---|
| 602 | case 'NIL' : |
---|
| 603 | return '00000000-0000-0000-0000-000000000000'; |
---|
| 604 | } |
---|
| 605 | return null; |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | // |
---|
| 609 | // Returns XMLHttpRequest object. |
---|
| 610 | // |
---|
| 611 | var ORG_APACHE_CXF_XMLHTTPREQUEST_MS_PROGIDS = new Array( |
---|
| 612 | "Msxml2.XMLHTTP.7.0", |
---|
| 613 | "Msxml2.XMLHTTP.6.0", |
---|
| 614 | "Msxml2.XMLHTTP.5.0", |
---|
| 615 | "Msxml2.XMLHTTP.4.0", |
---|
| 616 | "MSXML2.XMLHTTP.3.0", |
---|
| 617 | "MSXML2.XMLHTTP", |
---|
| 618 | "Microsoft.XMLHTTP" |
---|
| 619 | ); |
---|
| 620 | |
---|
| 621 | function org_apache_cxf_getXMLHttpRequest() |
---|
| 622 | { |
---|
| 623 | var httpRequest = null; |
---|
| 624 | |
---|
| 625 | // Create the appropriate HttpRequest object for the browser. |
---|
| 626 | try { |
---|
| 627 | httpRequest = new XMLHttpRequest(); |
---|
| 628 | return httpRequest; |
---|
| 629 | } catch(ex) { |
---|
| 630 | } |
---|
| 631 | |
---|
| 632 | if (window.ActiveXObject != null) { |
---|
| 633 | // Must be IE, find the right ActiveXObject. |
---|
| 634 | |
---|
| 635 | var success = false; |
---|
| 636 | // |
---|
| 637 | // Define a list of Microsoft XML HTTP ProgIDs. |
---|
| 638 | // |
---|
| 639 | for (var i = 0; |
---|
| 640 | i < ORG_APACHE_CXF_XMLHTTPREQUEST_MS_PROGIDS.length && !success; |
---|
| 641 | i++) |
---|
| 642 | { |
---|
| 643 | try |
---|
| 644 | { |
---|
| 645 | httpRequest = new ActiveXObject(ORG_APACHE_CXF_XMLHTTPREQUEST_MS_PROGIDS[i]); |
---|
| 646 | success = true; |
---|
| 647 | } |
---|
| 648 | catch (ex) |
---|
| 649 | { |
---|
| 650 | // no reason to log unless we come up empty. |
---|
| 651 | } |
---|
| 652 | } |
---|
| 653 | if(!success) { |
---|
| 654 | this.utils.trace("Unable to get any Microsoft XML HttpRequest object."); |
---|
| 655 | throw "org_apache_cxf no Microsoft XMLHttpRequest"; |
---|
| 656 | } |
---|
| 657 | } |
---|
| 658 | // Return it. |
---|
| 659 | return httpRequest; |
---|
| 660 | } |
---|
| 661 | |
---|
| 662 | CxfApacheOrgClient.prototype.getXMLHttpRequest = org_apache_cxf_getXMLHttpRequest; |
---|
| 663 | |
---|
| 664 | var ORG_APACHE_CXF_MTOM_REQUEST_HEADER = 'Content-Type: application/xop+xml; type="text/xml"; charset=utf-8\r\n'; |
---|
| 665 | |
---|
| 666 | // Caller must avoid stupid mistakes like 'GET' with a request body. |
---|
| 667 | // This does not support attempts to cross-script. |
---|
| 668 | // This imposes a relatively straightforward set of HTTP options. |
---|
| 669 | function org_apache_cxf_client_request(url, requestXML, method, sync, headers) |
---|
| 670 | { |
---|
| 671 | this.utils.trace("request " + url); |
---|
| 672 | |
---|
| 673 | this.url = url; |
---|
| 674 | this.sync = sync; |
---|
| 675 | |
---|
| 676 | this.req = null; |
---|
| 677 | |
---|
| 678 | if (method) { |
---|
| 679 | this.method = method; |
---|
| 680 | } else { |
---|
| 681 | if (requestXML) |
---|
| 682 | this.method = "POST"; |
---|
| 683 | else |
---|
| 684 | this.method = "GET"; |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | try { |
---|
| 688 | this.req = this.getXMLHttpRequest(); |
---|
| 689 | } catch (err) { |
---|
| 690 | this.utils.trace("Error creating XMLHttpRequest: " + err); |
---|
| 691 | this.req = null; |
---|
| 692 | } |
---|
| 693 | |
---|
| 694 | if (this.req == null) { |
---|
| 695 | this.utils.trace("Unable to create request object."); |
---|
| 696 | throw "ORG_APACHE_CXF_NO_REQUEST_OBJECT"; |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | this.utils.trace("about to open " + this.method + " " + this.url); |
---|
| 700 | this.req.open(this.method, this.url, !this.sync); |
---|
| 701 | |
---|
| 702 | var mimeBoundary; |
---|
| 703 | |
---|
| 704 | // we can't do binary MTOM, but we can do 'text/plain' ! |
---|
| 705 | if (this.mtomparts.length > 0) { |
---|
| 706 | var uuid = org_apache_cxf_make_uuid('v4'); |
---|
| 707 | mimeBoundary = '@_bOuNDaRy_' + uuid; |
---|
| 708 | var ctHeader = 'multipart/related; start-info="text/xml"; type="application/xop+xml"; boundary="' |
---|
| 709 | + mimeBoundary + '"'; |
---|
| 710 | this.req.setRequestHeader("Content-Type", ctHeader); |
---|
| 711 | |
---|
| 712 | } else { |
---|
| 713 | // for now, assume SOAP 1.1. 1.2 calls for application/xml. |
---|
| 714 | // also assume we're talking Unicode here. |
---|
| 715 | this.req.setRequestHeader("Content-Type", "text/xml;charset=utf-8"); |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | if (headers) { // must be array indexed by header field. |
---|
| 719 | // avoid extra properties on the headers. |
---|
| 720 | for (var h in headers) { |
---|
| 721 | if(headers.hasOwnProperty(h)) { |
---|
| 722 | this.req.setRequestHeader(h, headers[h]); |
---|
| 723 | } |
---|
| 724 | } |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | this.req.setRequestHeader("SOAPAction", this.soapAction); |
---|
| 728 | this.req.setRequestHeader("MessageType", this.messageType); |
---|
| 729 | |
---|
| 730 | var requester = this; /* setup a closure */ |
---|
| 731 | |
---|
| 732 | this.req.onreadystatechange = function() { |
---|
| 733 | requester.onReadyState(); |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | // NOTE: we do not call the onerror callback for a synchronous error |
---|
| 737 | // at request time. We let the request object throw as it will. |
---|
| 738 | // onError will only be called for asynchronous errors. |
---|
| 739 | this.utils.trace("about to send data" + this.method + " " + this.url); |
---|
| 740 | var dataToSend; |
---|
| 741 | if (this.mtomparts.length == 0) { |
---|
| 742 | dataToSend = requestXML; |
---|
| 743 | } else { |
---|
| 744 | dataToSend = "--" + mimeBoundary + "\r\n"; |
---|
| 745 | dataToSend = dataToSend + ORG_APACHE_CXF_MTOM_REQUEST_HEADER + "\r\n"; |
---|
| 746 | dataToSend = dataToSend + requestXML; |
---|
| 747 | for (var bx in this.mtomparts) { |
---|
| 748 | var part = this.mtomparts[bx]; |
---|
| 749 | dataToSend += "\r\n\r\n--" + mimeBoundary + "\r\n"; |
---|
| 750 | dataToSend += part; |
---|
| 751 | } |
---|
| 752 | dataToSend += "--" + mimeBoundary + "--\r\n"; |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | this.req.send(dataToSend); |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | CxfApacheOrgClient.prototype.request = org_apache_cxf_client_request; |
---|
| 759 | |
---|
| 760 | function org_apache_cxf_trim_string(str) { |
---|
| 761 | return str.replace(/^\s+|\s+$/g, ''); |
---|
| 762 | } |
---|
| 763 | |
---|
| 764 | // this gets an array of a=b strings, and produces a dictionary of x[a]=b; |
---|
| 765 | function org_apache_cxf_parse_mime_keyword_value_pairs(strings) { |
---|
| 766 | var result = []; |
---|
| 767 | for (var x = 1;x < strings.length; x = x + 1) { |
---|
| 768 | var str = strings[x]; |
---|
| 769 | var valequal = str.indexOf("="); |
---|
| 770 | if (valequal != -1) { |
---|
| 771 | var k = str.substr(0, valequal); |
---|
| 772 | var v = str.substr(valequal + 1); |
---|
| 773 | v = org_apache_cxf_trim_string(v); |
---|
| 774 | if (v.charAt(0) == '"') { |
---|
| 775 | v = v.substr(1, v.length - 2); |
---|
| 776 | } |
---|
| 777 | if (v.charAt(0) == "'") { |
---|
| 778 | v = v.substr(1, v.length - 2); |
---|
| 779 | } |
---|
| 780 | |
---|
| 781 | result[org_apache_cxf_trim_string(k.toLowerCase())] = v; |
---|
| 782 | } |
---|
| 783 | } |
---|
| 784 | return result; |
---|
| 785 | } |
---|
| 786 | |
---|
| 787 | function org_apache_cxf_regexp_escape(text) { |
---|
| 788 | if (!arguments.callee.sRE) { |
---|
| 789 | var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', |
---|
| 790 | '}', '\\']; |
---|
| 791 | arguments.callee.sRE = new RegExp('(\\' + specials.join('|\\') + ')', |
---|
| 792 | 'g'); |
---|
| 793 | } |
---|
| 794 | return text.replace(arguments.callee.sRE, '\\$1'); |
---|
| 795 | } |
---|
| 796 | |
---|
| 797 | // Called when we don't have response XML. |
---|
| 798 | // returns true if we have multipart-related, false if we don't or can't parse |
---|
| 799 | // it. |
---|
| 800 | function org_apache_cxf_parse_multipart_related() { |
---|
| 801 | var contentType = this.req.getResponseHeader("content-type"); |
---|
| 802 | if (!contentType) |
---|
| 803 | return false; // not bloody likely. |
---|
| 804 | var ctPart = contentType.split(/\s*;\s*/); |
---|
| 805 | var ctMain = ctPart[0].toLowerCase(); |
---|
| 806 | if (ctMain != "multipart/related") |
---|
| 807 | return false; |
---|
| 808 | // now we have keyword-value pairs. |
---|
| 809 | var params = org_apache_cxf_parse_mime_keyword_value_pairs(ctPart); |
---|
| 810 | // there is a lot of noise we don't care about. all we really want is the |
---|
| 811 | // boundary. |
---|
| 812 | var boundary = params['boundary']; |
---|
| 813 | if (!boundary) |
---|
| 814 | return false; |
---|
| 815 | boundary = "--" + boundary; // the annoying 'extra-dash' convention. |
---|
| 816 | // var boundarySplitter = org_apache_cxf_regexp_escape(boundary); |
---|
| 817 | var text = this.req.responseText; |
---|
| 818 | // we are willing to use a lot of memory here. |
---|
| 819 | var parts = text.split(boundary); |
---|
| 820 | // now we have the parts. |
---|
| 821 | // now we have to pull headers off the parts. |
---|
| 822 | this.parts = []; |
---|
| 823 | // the first one is noise due to the initial boundary. The last will just be |
---|
| 824 | // -- due to MIME. |
---|
| 825 | for (var px = 1;px < parts.length - 1; px++) { |
---|
| 826 | var seenOneHeader = false; |
---|
| 827 | var x = 0; // misc index. |
---|
| 828 | var parttext = parts[px]; |
---|
| 829 | var headers = []; |
---|
| 830 | nextHeaderLine : for (var endX = parttext.indexOf('\r', x);endX != -1; x = endX |
---|
| 831 | + 1, endX = parttext.indexOf('\r', x)) { |
---|
| 832 | var headerLine = parttext.slice(x, endX); |
---|
| 833 | if (headerLine == "") { |
---|
| 834 | if (parttext.charAt(endX + 1) == '\n') |
---|
| 835 | endX++; |
---|
| 836 | if (seenOneHeader) { |
---|
| 837 | break nextHeaderLine; |
---|
| 838 | } else { |
---|
| 839 | continue nextHeaderLine; |
---|
| 840 | } |
---|
| 841 | } |
---|
| 842 | seenOneHeader = true; |
---|
| 843 | |
---|
| 844 | var colonIndex = headerLine.indexOf(":"); |
---|
| 845 | var headerName = headerLine.slice(0, colonIndex).toLowerCase(); |
---|
| 846 | var headerValue = headerLine.substr(colonIndex+1); |
---|
| 847 | headers[headerName] = org_apache_cxf_trim_string(headerValue); |
---|
| 848 | |
---|
| 849 | if (parttext.charAt(endX + 1) == '\n') |
---|
| 850 | endX++; |
---|
| 851 | } |
---|
| 852 | |
---|
| 853 | // Now, see about the mime type (if any) and the ID. |
---|
| 854 | var thispart = new Object(); // a constructor seems excessive. |
---|
| 855 | // at exit, x indicates the start of the blank line. |
---|
| 856 | if (parttext.charAt(x + 1) == '\n') |
---|
| 857 | x = x + 1; |
---|
| 858 | thispart.data = parttext.substr(x); |
---|
| 859 | thispart.contentType = headers['content-type']; |
---|
| 860 | if (px > 1) { |
---|
| 861 | var cid = headers['content-id']; |
---|
| 862 | // take of < and > |
---|
| 863 | cid = cid.substr(1, cid.length - 2); |
---|
| 864 | thispart.cid = cid; |
---|
| 865 | this.parts[cid] = thispart; |
---|
| 866 | } else { |
---|
| 867 | // the first part. |
---|
| 868 | var doc; |
---|
| 869 | if (window.ActiveXObject) { |
---|
| 870 | doc = new ActiveXObject("Microsoft.XMLDOM"); |
---|
| 871 | doc.async = "false"; |
---|
| 872 | doc.loadXML(thispart.data); |
---|
| 873 | } else { |
---|
| 874 | var parser = new DOMParser(); |
---|
| 875 | doc = parser.parseFromString(thispart.data, "text/xml"); |
---|
| 876 | } |
---|
| 877 | this.mpResponseXML = doc; |
---|
| 878 | } |
---|
| 879 | } |
---|
| 880 | return true; |
---|
| 881 | |
---|
| 882 | } |
---|
| 883 | |
---|
| 884 | CxfApacheOrgClient.prototype.parseMultipartRelated = org_apache_cxf_parse_multipart_related; |
---|
| 885 | |
---|
| 886 | function org_apache_cxf_client_onReadyState() { |
---|
| 887 | var req = this.req; |
---|
| 888 | var ready = req.readyState; |
---|
| 889 | |
---|
| 890 | this.utils.trace("onreadystatechange " + ready); |
---|
| 891 | |
---|
| 892 | if (ready == this.READY_STATE_DONE) { |
---|
| 893 | var httpStatus; |
---|
| 894 | try { |
---|
| 895 | httpStatus = req.status; |
---|
| 896 | } catch (e) { |
---|
| 897 | // Firefox throws when there was an error here. |
---|
| 898 | this.utils |
---|
| 899 | .trace("onreadystatechange DONE ERROR retrieving status (connection error?)"); |
---|
| 900 | if (this.onerror != null) { |
---|
| 901 | this.onerror(e); |
---|
| 902 | } |
---|
| 903 | return; |
---|
| 904 | |
---|
| 905 | } |
---|
| 906 | |
---|
| 907 | this.utils.trace("onreadystatechange DONE " + httpStatus); |
---|
| 908 | |
---|
| 909 | if (httpStatus == 200 || httpStatus == 0) { |
---|
| 910 | if (this.onsuccess != null) { |
---|
| 911 | // the onSuccess function is generated, and picks apart the |
---|
| 912 | // response. |
---|
| 913 | if (!req.responseXML) { |
---|
| 914 | if (this.parseMultipartRelated()) { |
---|
| 915 | this.onsuccess(this, this.mpResponseXML); |
---|
| 916 | return; |
---|
| 917 | } |
---|
| 918 | if (this.onerror != null) { |
---|
| 919 | this.onerror("Could not handle content of response."); |
---|
| 920 | return; |
---|
| 921 | } |
---|
| 922 | } |
---|
| 923 | this.onsuccess(this, req.responseXML); |
---|
| 924 | } |
---|
| 925 | } else { |
---|
| 926 | this.utils.trace("onreadystatechange DONE ERROR " |
---|
| 927 | + req.getAllResponseHeaders() + " " + req.statusText + " " |
---|
| 928 | + req.responseText); |
---|
| 929 | if (this.onerror != null) |
---|
| 930 | this.onerror(this); |
---|
| 931 | } |
---|
| 932 | } |
---|
| 933 | } |
---|
| 934 | |
---|
| 935 | CxfApacheOrgClient.prototype.onReadyState = org_apache_cxf_client_onReadyState; |
---|
| 936 | |
---|
| 937 | function org_apache_cxf_package_mtom(value) { |
---|
| 938 | var uuid = org_apache_cxf_make_uuid('v4'); |
---|
| 939 | var placeholder = '<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" ' |
---|
| 940 | + 'href="cid:' + uuid + '" />'; |
---|
| 941 | var mtomObject = 'Content-Type: text/plain; charset="utf-8";\r\nContent-ID: <' |
---|
| 942 | + uuid + '>\r\n\r\n' + value + '\r\n'; |
---|
| 943 | this.client.mtomparts.push(mtomObject); |
---|
| 944 | return placeholder; |
---|
| 945 | } |
---|
| 946 | |
---|
| 947 | CxfApacheOrgUtil.prototype.packageMtom = org_apache_cxf_package_mtom; |
---|
| 948 | |
---|
| 949 | // Holder object used for xs:any |
---|
| 950 | // The namespaceURI and localName identify the global element from the schema. |
---|
| 951 | // The object to go with it goes into object. |
---|
| 952 | // If the Any is an array, put the array into the object slot. |
---|
| 953 | |
---|
| 954 | function org_apache_cxf_any_holder(namespaceURI, localName, object) { |
---|
| 955 | this.typeMarker = "org_apache_cxf_any_holder"; |
---|
| 956 | this.namespaceURI = namespaceURI; |
---|
| 957 | this.localName = localName; |
---|
| 958 | this.qname = "{" + namespaceURI + "}" + localName; |
---|
| 959 | this.object = object; |
---|
| 960 | this.raw = false; |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | // the following will simply dump the supplied XML into the message. |
---|
| 964 | function org_apache_cxf_raw_any_holder(xml) { |
---|
| 965 | this.typeMarker = "org_apache_cxf_raw_any_holder"; |
---|
| 966 | this.xml = xml; |
---|
| 967 | this.raw = true; |
---|
| 968 | this.xsiType = false; |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | // The following will get an xsi:type attribute in addition to dumping the XML |
---|
| 972 | // into |
---|
| 973 | // the message. |
---|
| 974 | function org_apache_cxf_raw_typed_any_holder(namespaceURI, localName, xml) { |
---|
| 975 | this.typeMarker = "org_apache_cxf_raw_any_holder"; |
---|
| 976 | this.namespaceURI = namespaceURI; |
---|
| 977 | this.localName = localName; |
---|
| 978 | this.xml = xml; |
---|
| 979 | this.raw = true; |
---|
| 980 | this.xsiType = true; |
---|
| 981 | } |
---|
| 982 | |
---|
| 983 | function org_apache_cxf_get_xsi_type(elementNode) { |
---|
| 984 | var attributes = elementNode.attributes; |
---|
| 985 | if ((attributes != null) && (attributes.length > 0)) { |
---|
| 986 | for (var x = 0;x < attributes.length; x++) { |
---|
| 987 | var attributeNodeName = attributes.item(x).nodeName; |
---|
| 988 | var attributeNamespacePrefix = org_apache_cxf_getPrefix(attributes |
---|
| 989 | .item(x).nodeName); |
---|
| 990 | var attributeNamespaceSuffix = org_apache_cxf_getLocalName(attributes |
---|
| 991 | .item(x).nodeName); |
---|
| 992 | if (attributeNamespaceSuffix == 'type') { |
---|
| 993 | // perhaps this is ours |
---|
| 994 | var ns = org_apache_cxf_getNamespaceURI(elementNode, |
---|
| 995 | attributeNamespacePrefix); |
---|
| 996 | if (ns == org_apache_cxf_XSI_namespace_uri) { |
---|
| 997 | return attributes.item(x).nodeValue; |
---|
| 998 | } |
---|
| 999 | } |
---|
| 1000 | } |
---|
| 1001 | return null; |
---|
| 1002 | } |
---|
| 1003 | } |
---|
| 1004 | |
---|
| 1005 | // Return an object if we can deserialize an object, otherwise return the |
---|
| 1006 | // element itself. |
---|
| 1007 | function org_apache_cxf_deserialize_anyType(cxfjsutils, element) { |
---|
| 1008 | var type = org_apache_cxf_get_xsi_type(element); |
---|
| 1009 | if (type != null) { |
---|
| 1010 | // type is a :-qualified name. |
---|
| 1011 | var namespacePrefix = org_apache_cxf_getPrefix(type); |
---|
| 1012 | var localName = org_apache_cxf_getLocalName(type); |
---|
| 1013 | var uri = org_apache_cxf_getNamespaceURI(element, namespacePrefix); |
---|
| 1014 | if (uri == org_apache_cxf_XSD_namespace_uri) { |
---|
| 1015 | // we expect a Text node below |
---|
| 1016 | var textNode = element.firstChild; |
---|
| 1017 | if (textNode == null) |
---|
| 1018 | return null; |
---|
| 1019 | var text = textNode.nodeValue; |
---|
| 1020 | if (text == null) |
---|
| 1021 | return null; |
---|
| 1022 | // For any of the basic types, assume that the nodeValue is what the |
---|
| 1023 | // doctor ordered, |
---|
| 1024 | // converted to the appropriate type. |
---|
| 1025 | // For some of the more interesting types this needs more work. |
---|
| 1026 | if (localName == "int" || localName == "unsignedInt" |
---|
| 1027 | || localName == "long" || localName == "unsignedLong") { |
---|
| 1028 | return parseInt(text); |
---|
| 1029 | } |
---|
| 1030 | if (localName == "float" || localName == "double") |
---|
| 1031 | return parseFloat(text); |
---|
| 1032 | if (localName == "boolean") |
---|
| 1033 | return text == 'true'; |
---|
| 1034 | return text; |
---|
| 1035 | } |
---|
| 1036 | var qname = "{" + uri + "}" + localName; |
---|
| 1037 | var deserializer = cxfjsutils.interfaceObject.globalElementDeserializers[qname]; |
---|
| 1038 | if (deserializer != null) { |
---|
| 1039 | return deserializer(cxfjsutils, element); |
---|
| 1040 | } |
---|
| 1041 | } |
---|
| 1042 | return element; |
---|
| 1043 | } |
---|