123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { XmlRpcHelper } from "./xmlrpc-helper";
- import { JsToXml } from "./js-to-xml";
- import { Xml2Js } from "./xml-to-js";
- export class XmlRpc {
- configuration: {
- host: string,
-
- }
- constructor(
- private helper: XmlRpcHelper,
- private jsToXml: JsToXml,
- private xmlToJs: Xml2Js
- ) {
- }
- /**
- *
- */
- serialize(xml: any): any {
- let text = xml.xml;
- if (text) {
- return text;
- }
- if (typeof XMLSerializer != undefined) {
- return new XMLSerializer().serializeToString(xml);
- }
- throw new Error('Your browser does not support serializing XML documents');
- }
- /**
- *
- */
- createCall(method: any, params: any): any {
- var doc = this.helper.createDocument('methodCall');
- doc.firstChild.appendChild(this.helper.createNode(doc, 'methodName', method));
- if (arguments.length > 2) {
- params = this.helper.cloneArray(arguments);
- params.shift();
- }
- if (params && params.length > 0) {
- let paramsNode = this.helper.createNode(doc, params);
- for (let i = 0; i < params.length; i++) {
- paramsNode.appendChild(this.helper.createNode(doc, 'param', this.jsToXml.jsToXml(doc, params[i])));
- }
- doc.firstChild.appendChild(paramsNode);
- }
- return (this.serialize(doc)).replace(/[\s\xa0]+$/, '');
- }
- /**
- *
- */
- callMethod(method: any, params: any): any {
- let xmlStr = this.createCall(method, params);
- let targetUrl =
- }
- }
|