xmlrpc.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { XmlRpcHelper } from "./xmlrpc-helper";
  2. import { JsToXml } from "./js-to-xml";
  3. import { Xml2Js } from "./xml-to-js";
  4. export class XmlRpc {
  5. configuration: {
  6. host: string,
  7. }
  8. constructor(
  9. private helper: XmlRpcHelper,
  10. private jsToXml: JsToXml,
  11. private xmlToJs: Xml2Js
  12. ) {
  13. }
  14. /**
  15. *
  16. */
  17. serialize(xml: any): any {
  18. let text = xml.xml;
  19. if (text) {
  20. return text;
  21. }
  22. if (typeof XMLSerializer != undefined) {
  23. return new XMLSerializer().serializeToString(xml);
  24. }
  25. throw new Error('Your browser does not support serializing XML documents');
  26. }
  27. /**
  28. *
  29. */
  30. createCall(method: any, params: any): any {
  31. var doc = this.helper.createDocument('methodCall');
  32. doc.firstChild.appendChild(this.helper.createNode(doc, 'methodName', method));
  33. if (arguments.length > 2) {
  34. params = this.helper.cloneArray(arguments);
  35. params.shift();
  36. }
  37. if (params && params.length > 0) {
  38. let paramsNode = this.helper.createNode(doc, params);
  39. for (let i = 0; i < params.length; i++) {
  40. paramsNode.appendChild(this.helper.createNode(doc, 'param', this.jsToXml.jsToXml(doc, params[i])));
  41. }
  42. doc.firstChild.appendChild(paramsNode);
  43. }
  44. return (this.serialize(doc)).replace(/[\s\xa0]+$/, '');
  45. }
  46. /**
  47. *
  48. */
  49. callMethod(method: any, params: any): any {
  50. let xmlStr = this.createCall(method, params);
  51. let targetUrl =
  52. }
  53. }