123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- "use strict";
- var XmlRpcHelper = (function () {
- function XmlRpcHelper() {
- try {
- new ActiveXObject('MSXML2.DOMDocument');
- this._hasActiveX = true;
- }
- catch (e) {
- this._hasActiveX = false;
- }
- }
- Object.defineProperty(XmlRpcHelper.prototype, "hasActiveX", {
- /**
- *
- */
- get: function () {
- return this._hasActiveX;
- },
- enumerable: true,
- configurable: true
- });
- /**
- *
- */
- XmlRpcHelper.prototype.cloneArray = function (object) {
- var length = object.length;
- if (length > 0) {
- var result = new Array(length);
- for (var i = 0; i < length; i++) {
- result[i] = object[i];
- }
- return result;
- }
- return [];
- };
- /**
- *
- */
- XmlRpcHelper.prototype.createMsXmlDocument = function () {
- var doc = new ActiveXObject('MSXML2.DOMDocument');
- if (doc) {
- doc.resolveExternals = false;
- doc.validateOnParse = false;
- try {
- doc.setProperty('ProhibitDTD', true);
- doc.setProperty('MaxXMLSize', 2 * 1024);
- doc.setProperty('MaxElementDepth', 256);
- }
- catch (e) {
- console.log(e);
- }
- }
- return doc;
- };
- /**
- *
- */
- XmlRpcHelper.prototype.createDocument = function (rootTag, uriNamespace) {
- if (!rootTag && uriNamespace) {
- throw Error("Can't create document with namespace and no root tag");
- }
- if (this.hasActiveX) {
- var doc = this.createMsXmlDocument();
- if (doc) {
- if (rootTag) {
- doc.appendChild(doc.createNode(1, rootTag, uriNamespace || ''));
- }
- return doc;
- }
- }
- else if (document.implementation && document.implementation.createDocument) {
- return document.implementation.createDocument(uriNamespace || '', rootTag || '', null);
- }
- throw Error('Your browser does not support creating new documents');
- };
- /**
- *
- */
- XmlRpcHelper.prototype.type = function (object) {
- return Object.prototype.toString.call(object).slice(8, -1).toLowerCase();
- };
- /**
- *
- */
- XmlRpcHelper.prototype.createNode = function (doc, nodeName) {
- var children = [];
- for (var _i = 2; _i < arguments.length; _i++) {
- children[_i - 2] = arguments[_i];
- }
- var result = doc.createElement(nodeName);
- };
- /**
- *
- */
- XmlRpcHelper.prototype.appendChild = function (child) {
- if (this.type(child) == 'object' && child.nodeType != 1) {
- for (var item in child) {
- }
- }
- };
- /**
- *
- */
- XmlRpcHelper.prototype.generateId = function () {
- return 'xmlrpc-' + (new Date().getTime()) + ' - ' + Math.floor(Math.random() * 1000);
- };
- /**
- *
- */
- XmlRpcHelper.prototype.loadXml = function (xml) {
- if (this.hasActiveX) {
- var doc = this.createMsXmlDocument();
- doc.loadXML(xml);
- return doc;
- }
- else if (typeof DOMParser != 'undefined') {
- return new DOMParser().parseFromString(xml, 'application/xml');
- }
- throw Error('Your browser does not support loading xml documents');
- };
- /**
- *
- */
- XmlRpcHelper.prototype.getOwnerDocument = function (node) {
- return (node.nodeType == 9 ? node : node.ownerDocument || node.document);
- };
- /**
- *
- */
- XmlRpcHelper.prototype.selectSingleNode = function (node, path) {
- var doc = this.getOwnerDocument(node);
- if (typeof node.selectSingleNode != 'undefined') {
- if (typeof doc.setProperty != 'undefined') {
- doc.setProperty('SelectionLanguage', 'XPath');
- }
- return node.selectSingleNode(path);
- }
- else if (document.implementation.hasFeature('XPath', '3.0')) {
- var resolver = doc.createNSResolver(doc.documentElement);
- var result = doc.evaluate(path, node, resolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
- return result.singleNodeValue;
- }
- return null;
- };
- /**
- *
- */
- XmlRpcHelper.prototype.getTextContent = function (node, buffer, normalizeWhitespace) {
- var PREDEFINED_TAG_VALUES = { 'IMG': '', 'BR': '\n' };
- if (node.nodeName in ['SCRIPT', 'STYLE', 'HEAD', 'IFRAME', 'OBJECT']) {
- }
- else if (node.nodeType == 3) {
- if (normalizeWhitespace) {
- buffer.push(String(node.nodeValue).replace(/(\r\n|\r|\n)/g, ''));
- }
- else {
- buffer.push(node.nodeValue);
- }
- }
- else if (node.nodeName in PREDEFINED_TAG_VALUES) {
- buffer.push(PREDEFINED_TAG_VALUES[node.nodeName]);
- }
- else {
- var child = node.firstChild;
- while (child) {
- this.getTextContent(child, buffer, normalizeWhitespace);
- child = child.nextSibling;
- }
- }
- return buffer.join('');
- };
- /**
- *
- */
- XmlRpcHelper.prototype.selectNodes = function (node, path) {
- var doc = this.getOwnerDocument(node);
- if (typeof node.selectNodes != 'undefined') {
- if (typeof doc.setProperty != 'undefined') {
- doc.setProperty('SelectionLanguage', 'XPath');
- }
- return node.selectNodes(path);
- }
- else if (document.implementation.hasFeature('XPath', '3.0')) {
- var resolver = doc.createNSResolver(doc.documentElement);
- var nodes = doc.evaluate(path, node, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
- var results = [];
- var count = nodes.snapshotLength;
- for (var i = 0; i < count; i++) {
- results.push(nodes.snapshotItem(i));
- }
- return results;
- }
- else {
- return [];
- }
- };
- return XmlRpcHelper;
- }());
- exports.XmlRpcHelper = XmlRpcHelper;
|