From 15e4f2d49e66f649923d9d93e310a50c958f938e Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Sat, 15 Jul 2017 11:19:23 +0200 Subject: [PATCH] Use 'xml-js-builder' npm package instead of built-in XML manager --- lib/helper/XML.d.ts | 29 -- lib/helper/XML.js | 308 +++++++++++------- lib/helper/export.d.ts | 1 - lib/helper/export.js | 1 - lib/helper/v2/export.d.ts | 1 - lib/helper/v2/export.js | 1 - lib/manager/v2/fileSystem/CommonTypes.d.ts | 2 +- lib/resource/IResource.d.ts | 2 +- lib/resource/lock/Lock.d.ts | 2 +- lib/resource/std/resourceTester/Properties.js | 4 +- lib/server/MethodCallArgs.d.ts | 2 +- lib/server/MethodCallArgs.js | 6 +- lib/server/commands/Lock.js | 6 +- lib/server/commands/Propfind.js | 8 +- lib/server/commands/Proppatch.js | 6 +- lib/server/v2/RequestContext.d.ts | 2 +- lib/server/v2/RequestContext.js | 6 +- lib/server/v2/commands/Lock.js | 6 +- lib/server/v2/commands/Propfind.js | 8 +- lib/server/v2/commands/Proppatch.js | 6 +- lib/server/webDAVServer/Events.d.ts | 2 +- package.json | 5 +- src/helper/XML.ts | 3 +- src/helper/export.ts | 1 - src/helper/v2/export.ts | 1 - src/manager/v2/fileSystem/CommonTypes.ts | 2 +- src/manager/v2/fileSystem/ContextInfo.ts | 1 - .../v2/fileSystem/ContextualFileSystem.ts | 1 - src/manager/v2/fileSystem/FileSystem.ts | 1 - src/manager/v2/fileSystem/LockManager.ts | 1 - src/manager/v2/fileSystem/PropertyManager.ts | 1 - src/manager/v2/fileSystem/Resource.ts | 1 - src/manager/v2/fileSystem/Serialization.ts | 1 - src/manager/v2/fileSystem/StandardMethods.ts | 1 - src/resource/IResource.ts | 2 +- src/resource/lock/Lock.ts | 2 +- src/resource/std/resourceTester/Properties.ts | 2 +- src/server/MethodCallArgs.ts | 2 +- src/server/commands/Lock.ts | 4 +- src/server/commands/Propfind.ts | 6 +- src/server/commands/Proppatch.ts | 4 +- src/server/commands/Unlock.ts | 2 +- src/server/v2/RequestContext.ts | 2 +- src/server/v2/commands/Lock.ts | 4 +- src/server/v2/commands/Propfind.ts | 6 +- src/server/v2/commands/Proppatch.ts | 4 +- src/server/v2/commands/Unlock.ts | 2 +- src/server/webDAVServer/Events.ts | 2 +- test/v2/root.js | 5 +- test/v2/tests.ts/Type.ts | 5 +- test/v2/tests.ts/lockUnlock/.createFiles.ts | 3 +- .../tests.ts/lockUnlock/lockPropfindMethod.ts | 3 +- .../lockUnlock/lockProppatchMethod.ts | 3 +- test/v2/tests.ts/properties/.createFiles.ts | 5 +- 54 files changed, 264 insertions(+), 233 deletions(-) diff --git a/lib/helper/XML.d.ts b/lib/helper/XML.d.ts index 51c9825a..e69de29b 100644 --- a/lib/helper/XML.d.ts +++ b/lib/helper/XML.d.ts @@ -1,29 +0,0 @@ -export interface XMLElement { - declaration?: any; - attributes?: any; - elements: XMLElement[]; - name?: string; - type?: string; - findIndex(name: string): number; - find(name: string): XMLElement; - findMany(name: string): XMLElement[]; - findText(): string; - findTexts(): string[]; -} -export declare abstract class XML { - static parse(xml: string | Int8Array): XMLElement; - static parseJSON(xml: string | Int8Array, compact?: boolean): XMLElement; - static parseXML(xml: string | Int8Array): XMLElement; - static toJSON(xml: string): string; - static toXML(xml: XMLElement | any, includeDeclaration?: boolean): string; - private static explodeName(name, attributes); - static createElement(name: string, attributes?: any, text?: string): { - type: string; - name: string; - attributes: any; - elements: any[]; - ele(name: string, attributes?: any, insertAtStart?: boolean): any; - add(element: any): any; - eleFn: (name: string, attributes?: any, text?: string) => any; - }; -} diff --git a/lib/helper/XML.js b/lib/helper/XML.js index 69deb75f..9fac8be1 100644 --- a/lib/helper/XML.js +++ b/lib/helper/XML.js @@ -1,124 +1,167 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Errors_1 = require("../Errors"); -var xmljs = require("xml-js"); -function seekForNS(node, parentNS) { - if (!node.attributes) +/*import { Errors } from '../Errors' +import * as xmljs from 'xml-js' + +function seekForNS(node : any, parentNS : any) : any +{ + if(!node.attributes) return parentNS; - var ns = {}; - for (var name_1 in parentNS) - ns[name_1] = parentNS[name_1]; - for (var name_2 in node.attributes) { - if (name_2.indexOf('xmlns:') === 0 || name_2 === 'xmlns') { - var value = node.attributes[name_2]; - if (name_2 === 'xmlns') + + const ns : any = {}; + for(const name in parentNS) + ns[name] = parentNS[name]; + + for(const name in node.attributes) + { + if(name.indexOf('xmlns:') === 0 || name === 'xmlns') + { + const value = node.attributes[name]; + if(name === 'xmlns') ns._default = value; else - ns[name_2.substring('xmlns:'.length)] = value; + ns[name.substring('xmlns:'.length)] = value; } } return ns; } -function mutateNodeNS(node, parentNS) { - if (parentNS === void 0) { parentNS = {}; } - if (!node) + +function mutateNodeNS(node : any, parentNS = { }) +{ + if(!node) return; - var nss = seekForNS(node, parentNS); - if (node.name) { - for (var ns in nss) { - if (ns === '_default' && node.name.indexOf(':') === -1) { + + const nss = seekForNS(node, parentNS); + + if(node.name) + { + for(const ns in nss) + { + if(ns === '_default' && node.name.indexOf(':') === -1) + { node.name = nss[ns] + node.name; break; } - else if (node.name.indexOf(ns + ':') === 0) { + else if(node.name.indexOf(ns + ':') === 0) + { node.name = nss[ns] + node.name.substring((ns + ':').length); break; } } } - node.findIndex = function (name) { - for (var index = 0; index < node.elements.length; ++index) - if (node.elements[index] && node.elements[index].name && node.elements[index].name === name) + + node.findIndex = function(name : string) : number + { + for(let index = 0; index < node.elements.length; ++index) + if(node.elements[index] && node.elements[index].name && node.elements[index].name === name) return index; return -1; - }; - node.find = function (name) { - for (var _i = 0, _a = node.elements; _i < _a.length; _i++) { - var element = _a[_i]; - if (element && element.name && element.name === name) + } + node.find = function(name : string) : XMLElement + { + for(const element of node.elements) + if(element && element.name && element.name === name) return element; - } - throw new Error(Errors_1.Errors.XMLNotFound.message + name); - }; - node.findMany = function (name) { - var elements = []; - for (var _i = 0, _a = node.elements; _i < _a.length; _i++) { - var element = _a[_i]; - if (element && element.name && element.name === name) + throw new Error(Errors.XMLNotFound.message + name); + } + node.findMany = function(name : string) : XMLElement[] + { + const elements : XMLElement[] = []; + + for(const element of node.elements) + if(element && element.name && element.name === name) elements.push(element); - } + return elements; - }; - node.findText = function () { - for (var _i = 0, _a = node.elements; _i < _a.length; _i++) { - var element = _a[_i]; - if (element && element.type === 'text') + } + node.findText = function() : string + { + for(const element of node.elements) + if(element && element.type === 'text') return element.text; - } return ''; - }; - node.findTexts = function () { - var texts = []; - for (var _i = 0, _a = node.elements; _i < _a.length; _i++) { - var element = _a[_i]; - if (element && element.type === 'text') + } + node.findTexts = function() : string[] + { + const texts = []; + + for(const element of node.elements) + if(element && element.type === 'text') texts.push(element.text); - } + return texts; - }; - if (node.elements) - node.elements.forEach(function (n) { return mutateNodeNS(n, nss); }); + } + + if(node.elements) + node.elements.forEach(n => mutateNodeNS(n, nss)) else node.elements = []; } -var XML = (function () { - function XML() { - } - XML.parse = function (xml) { - try { + +export interface XMLElement +{ + declaration ?: any + attributes ?: any + elements : XMLElement[] + name ?: string + type ?: string + + findIndex(name : string) : number + find(name : string) : XMLElement + findMany(name : string) : XMLElement[] + findText() : string + findTexts() : string[] +} + +export abstract class XML +{ + static parse(xml : string | Int8Array) : XMLElement + { + try + { return XML.parseXML(xml); } - catch (_) { - try { + catch(_) + { + try + { return XML.parseJSON(xml, true); } - catch (_) { + catch(_) + { return XML.parseJSON(xml, false); } } - }; - XML.parseJSON = function (xml, compact) { - if (compact === void 0) { compact = true; } - return XML.parseXML(xmljs.json2xml(xml.toString(), { compact: compact })); - }; - XML.parseXML = function (xml) { - var x = xmljs.xml2js(xml.constructor === String ? xml : new Buffer(xml).toString(), { + } + + static parseJSON(xml : string | Int8Array, compact : boolean = true) : XMLElement + { + return XML.parseXML(xmljs.json2xml(xml.toString(), { compact })); + } + + static parseXML(xml : string | Int8Array) : XMLElement + { + const x = xmljs.xml2js(xml.constructor === String ? xml as string : new Buffer(xml as Int8Array).toString(), { compact: false }); + mutateNodeNS(x); - return x; - }; - XML.toJSON = function (xml) { - if (xml === undefined || xml === null) + return x as XMLElement; + } + + static toJSON(xml : string) : string + { + if(xml === undefined || xml === null) return xml; - if (xml.constructor === Number || xml.constructor === Boolean) + if(xml.constructor === Number || xml.constructor === Boolean) return xml.toString(); + return xmljs.xml2json(xml, { compact: true, alwaysArray: true }); - }; - XML.toXML = function (xml, includeDeclaration) { - if (includeDeclaration === void 0) { includeDeclaration = true; } - var finalXml = xml; - if (includeDeclaration && !xml.declaration) + } + + static toXML(xml : XMLElement | any, includeDeclaration : boolean = true) : string + { + let finalXml : any = xml; + + if(includeDeclaration && !xml.declaration) finalXml = { declaration: { attributes: { @@ -130,20 +173,25 @@ var XML = (function () { xml ] }; + return xmljs.js2xml(finalXml, { compact: false }); - }; - XML.explodeName = function (name, attributes) { - var li1 = name.lastIndexOf(':'); - var li2 = name.indexOf(':'); - var lindex = Math.max(li1 === li2 && name.indexOf('DAV:') !== 0 ? -1 : li1, name.lastIndexOf('/')) + 1; - if (lindex !== 0) { - var kname = 'a'; - var value = name.substring(0, lindex); - while (attributes['xmlns:' + kname] !== undefined || value.indexOf(kname + ':') === 0) { - var newChar = kname.charCodeAt(0) + 1; - if (newChar > 'z'.charCodeAt(0)) + } + + private static explodeName(name, attributes) + { + const li1 = name.lastIndexOf(':'); + const li2 = name.indexOf(':'); + const lindex = Math.max(li1 === li2 && name.indexOf('DAV:') !== 0 ? -1 : li1, name.lastIndexOf('/')) + 1; + if(lindex !== 0) + { + let kname = 'a'; + const value = name.substring(0, lindex); + while(attributes['xmlns:' + kname] !== undefined || value.indexOf(kname + ':') === 0) + { + const newChar = kname.charCodeAt(0) + 1; + if(newChar > 'z'.charCodeAt(0)) kname = 'x' + String.fromCharCode(newChar); else kname = kname.substr(0, kname.length - 1) + String.fromCharCode(newChar); @@ -151,60 +199,78 @@ var XML = (function () { attributes['xmlns:' + kname] = value; name = kname + ':' + name.substring(lindex); } + return name; - }; - XML.createElement = function (name, attributes, text) { - if (!attributes) + } + + static createElement(name : string, attributes ?: any, text ?: string) + { + if(!attributes) attributes = {}; + name = XML.explodeName(name, attributes); - var result = { + + const result = { type: 'element', - name: name, - attributes: attributes, + name, + attributes, elements: [], - ele: function (name, attributes, insertAtStart) { - var el = result.eleFn(name, attributes); - if (insertAtStart) + ele(name : string, attributes ?: any, insertAtStart ?: boolean) + { + const el = result.eleFn(name, attributes); + if(insertAtStart) result.elements.unshift(el); else result.elements.push(el); return el; }, - add: function (element) { - if (element.constructor === String || element.constructor === Number || element.constructor === Boolean) + add(element : any) + { + if(element.constructor === String || element.constructor === Number || element.constructor === Boolean) element = { type: 'text', text: element.toString() }; - if (element.type === 'element') { - if (!element.attributes) - element.attributes = {}; + + if(element.type === 'element') + { + if(!element.attributes) + element.attributes = { }; + element.name = XML.explodeName(element.name, element.attributes); - if (element.elements) { - var list_1 = []; - element.elements.forEach(function (e) { return list_1.push(e); }); - while (list_1.length > 0) { - var current = list_1.shift(); - if (current.type !== 'element') + + if(element.elements) + { + const list = []; + element.elements.forEach((e) => list.push(e)); + + while(list.length > 0) + { + const current = list.shift(); + if(current.type !== 'element') continue; - if (current.elements) - current.elements.forEach(function (e) { return list_1.push(e); }); - if (!current.attributes) + + if(current.elements) + current.elements.forEach((e) => list.push(e)); + + if(!current.attributes) current.attributes = {}; current.name = XML.explodeName(current.name, current.attributes); } } } - if (element.constructor === Array) - element.forEach(result.add); + + if(element.constructor === Array) + (element as any).forEach(result.add); else result.elements.push(element); return element; }, eleFn: XML.createElement - }; + } + return result; - }; - return XML; -}()); -exports.XML = XML; + } +} + +*/ diff --git a/lib/helper/export.d.ts b/lib/helper/export.d.ts index c8112e52..91c7f5b0 100644 --- a/lib/helper/export.d.ts +++ b/lib/helper/export.d.ts @@ -1,3 +1,2 @@ export * from './IfParser'; export * from './Workflow'; -export * from './XML'; diff --git a/lib/helper/export.js b/lib/helper/export.js index 4db199d7..28f30214 100644 --- a/lib/helper/export.js +++ b/lib/helper/export.js @@ -5,4 +5,3 @@ function __export(m) { Object.defineProperty(exports, "__esModule", { value: true }); __export(require("./IfParser")); __export(require("./Workflow")); -__export(require("./XML")); diff --git a/lib/helper/v2/export.d.ts b/lib/helper/v2/export.d.ts index 5f2f1bb1..f9c15292 100644 --- a/lib/helper/v2/export.d.ts +++ b/lib/helper/v2/export.d.ts @@ -1,3 +1,2 @@ export * from './IfParser'; export * from '../Workflow'; -export * from '../XML'; diff --git a/lib/helper/v2/export.js b/lib/helper/v2/export.js index 25bb373a..5018aac8 100644 --- a/lib/helper/v2/export.js +++ b/lib/helper/v2/export.js @@ -5,4 +5,3 @@ function __export(m) { Object.defineProperty(exports, "__esModule", { value: true }); __export(require("./IfParser")); __export(require("../Workflow")); -__export(require("../XML")); diff --git a/lib/manager/v2/fileSystem/CommonTypes.d.ts b/lib/manager/v2/fileSystem/CommonTypes.d.ts index 6fa894fa..fa603e0e 100644 --- a/lib/manager/v2/fileSystem/CommonTypes.d.ts +++ b/lib/manager/v2/fileSystem/CommonTypes.d.ts @@ -1,4 +1,4 @@ -import { XMLElement } from '../../../helper/XML'; +import { XMLElement } from 'xml-js-builder'; export declare type SimpleCallback = (error?: Error) => void; export declare type ReturnCallback = (error?: Error, data?: T) => void; export declare type Return2Callback = (error?: Error, data1?: T1, data2?: T2) => void; diff --git a/lib/resource/IResource.d.ts b/lib/resource/IResource.d.ts index a40be718..79cea434 100644 --- a/lib/resource/IResource.d.ts +++ b/lib/resource/IResource.d.ts @@ -2,7 +2,7 @@ import { Readable, Writable } from 'stream'; import { FSManager, FSPath } from '../manager/FSManager'; import { RequestContext } from '../server/MethodCallArgs'; -import { XMLElement } from '../helper/XML'; +import { XMLElement } from 'xml-js-builder'; import { LockKind } from './lock/LockKind'; import { Lock } from './lock/Lock'; export declare type SimpleCallback = (error: Error) => void; diff --git a/lib/resource/lock/Lock.d.ts b/lib/resource/lock/Lock.d.ts index cb7f7538..061e7273 100644 --- a/lib/resource/lock/Lock.d.ts +++ b/lib/resource/lock/Lock.d.ts @@ -1,4 +1,4 @@ -import { XMLElement } from '../../helper/XML'; +import { XMLElement } from 'xml-js-builder'; import { LockKind } from './LockKind'; import { IUser } from '../../user/IUser'; export declare type LockOwner = string | XMLElement | XMLElement[]; diff --git a/lib/resource/std/resourceTester/Properties.js b/lib/resource/std/resourceTester/Properties.js index acf8e174..325f3425 100644 --- a/lib/resource/std/resourceTester/Properties.js +++ b/lib/resource/std/resourceTester/Properties.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var XML_1 = require("../../../helper/XML"); +var xml_js_builder_1 = require("xml-js-builder"); // ****************************** Properties ****************************** // function setProperty(callback) { callback = this.multiple(callback, 2); @@ -17,7 +17,7 @@ function setProperty(callback) { }); this.producer(false, function (r1) { var name = 'prop-test_test:test//test/test.test'; - var value = XML_1.XML.parse('TitiToto'); + var value = xml_js_builder_1.XML.parse('TitiToto'); r1.setProperty(name, value, function (e) { callback(e, !e, 'setProperty error', undefined, function () { r1.getProperty(name, function (e, v) { diff --git a/lib/server/MethodCallArgs.d.ts b/lib/server/MethodCallArgs.d.ts index 1453321e..3a48c735 100644 --- a/lib/server/MethodCallArgs.d.ts +++ b/lib/server/MethodCallArgs.d.ts @@ -2,7 +2,7 @@ import { IResource, ReturnCallback, ResourceType } from '../resource/IResource'; import { BasicPrivilege } from '../user/privilege/IPrivilegeManager'; import { EventsName, DetailsType } from './webDAVServer/Events'; -import { XMLElement } from '../helper/XML'; +import { XMLElement } from 'xml-js-builder'; import { WebDAVServer } from './webDAVServer/WebDAVServer'; import { FSPath } from '../manager/FSManager'; import { IUser } from '../user/IUser'; diff --git a/lib/server/MethodCallArgs.js b/lib/server/MethodCallArgs.js index f591f48e..73402797 100644 --- a/lib/server/MethodCallArgs.js +++ b/lib/server/MethodCallArgs.js @@ -1,7 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var IPrivilegeManager_1 = require("../user/privilege/IPrivilegeManager"); -var XML_1 = require("../helper/XML"); +var xml_js_builder_1 = require("xml-js-builder"); var IfParser_1 = require("../helper/IfParser"); var HTTPCodes_1 = require("./HTTPCodes"); var FSManager_1 = require("../manager/FSManager"); @@ -206,7 +206,7 @@ var MethodCallArgs = (function () { }); }); }; MethodCallArgs.prototype.writeXML = function (xmlObject) { - var content = XML_1.XML.toXML(xmlObject); + var content = xml_js_builder_1.XML.toXML(xmlObject); switch (this.accept([/[^a-z0-9A-Z]xml$/, /[^a-z0-9A-Z]json$/])) { default: case 0: @@ -215,7 +215,7 @@ var MethodCallArgs = (function () { this.response.write(content); break; case 1: - content = XML_1.XML.toJSON(content); + content = xml_js_builder_1.XML.toJSON(content); this.response.setHeader('Content-Type', 'application/json; charset="utf-8"'); this.response.setHeader('Content-Length', content.length.toString()); this.response.write(content); diff --git a/lib/server/commands/Lock.js b/lib/server/commands/Lock.js index d26b8373..2e123fe0 100644 --- a/lib/server/commands/Lock.js +++ b/lib/server/commands/Lock.js @@ -8,10 +8,10 @@ var LockKind_1 = require("../../resource/lock/LockKind"); var LockType_1 = require("../../resource/lock/LockType"); var Errors_1 = require("../../Errors"); var Lock_1 = require("../../resource/lock/Lock"); -var XML_1 = require("../../helper/XML"); +var xml_js_builder_1 = require("xml-js-builder"); var path = require("path"); function createResponse(arg, lock) { - var prop = XML_1.XML.createElement('D:prop', { + var prop = new xml_js_builder_1.XMLElementBuilder('D:prop', { 'xmlns:D': 'DAV:' }); var activelock = prop.ele('D:lockdiscovery').ele('D:activelock'); @@ -26,7 +26,7 @@ function createResponse(arg, lock) { } function createLock(arg, callback) { try { - var xml = XML_1.XML.parse(arg.data); + var xml = xml_js_builder_1.XML.parse(arg.data); var root = xml.find('DAV:lockinfo'); var scope = new LockScope_1.LockScope(root.find('DAV:lockscope').elements[0].name.substr(4).toLowerCase()); var type = new LockType_1.LockType(root.find('DAV:locktype').elements[0].name.substr(4).toLowerCase()); diff --git a/lib/server/commands/Propfind.js b/lib/server/commands/Propfind.js index 5229f80f..fe80578d 100644 --- a/lib/server/commands/Propfind.js +++ b/lib/server/commands/Propfind.js @@ -2,7 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); var IResource_1 = require("../../resource/IResource"); var WebDAVRequest_1 = require("../WebDAVRequest"); -var XML_1 = require("../../helper/XML"); +var xml_js_builder_1 = require("xml-js-builder"); var Workflow_1 = require("../../helper/Workflow"); var FSPath_1 = require("../../manager/FSPath"); var Errors_1 = require("../../Errors"); @@ -65,7 +65,7 @@ function parseRequestBody(arg) { if (arg.contentLength <= 0) return allTrue; try { - var xml = XML_1.XML.parse(arg.data); + var xml = xml_js_builder_1.XML.parse(arg.data); var propfind = xml.find('DAV:propfind'); if (propfind.findIndex('DAV:propname') !== -1) return onlyName; @@ -102,7 +102,7 @@ function method(arg, callback) { var lockDiscoveryCache = {}; arg.checkIfHeader(resource, function () { var targetSource = arg.isSource; - var multistatus = XML_1.XML.createElement('D:multistatus', { + var multistatus = new xml_js_builder_1.XMLElementBuilder('D:multistatus', { 'xmlns:D': 'DAV:' }); resource.type(function (e, type) { return process.nextTick(function () { @@ -146,7 +146,7 @@ function method(arg, callback) { }); }); function addXMLInfo(resource, multistatus, _callback) { var reqBody = parseRequestBody(arg); - var response = XML_1.XML.createElement('D:response'); + var response = new xml_js_builder_1.XMLElementBuilder('D:response'); var callback = function (e) { if (e === Errors_1.Errors.MustIgnore) e = null; diff --git a/lib/server/commands/Proppatch.js b/lib/server/commands/Proppatch.js index 083cdc33..0618b593 100644 --- a/lib/server/commands/Proppatch.js +++ b/lib/server/commands/Proppatch.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); var WebDAVRequest_1 = require("../WebDAVRequest"); var http_1 = require("http"); var Workflow_1 = require("../../helper/Workflow"); -var XML_1 = require("../../helper/XML"); +var xml_js_builder_1 = require("xml-js-builder"); function method(arg, callback) { arg.getResource(function (e, r) { if (e) { @@ -13,13 +13,13 @@ function method(arg, callback) { } arg.checkIfHeader(r, function () { arg.requirePrivilege(['canSetProperty', 'canRemoveProperty'], r, function () { - var multistatus = XML_1.XML.createElement('D:multistatus', { + var multistatus = new xml_js_builder_1.XMLElementBuilder('D:multistatus', { 'xmlns:D': 'DAV:' }); var response = multistatus.ele('D:response'); response.ele('D:href', undefined, true).add(encodeURI(arg.fullUri())); try { - var xml = XML_1.XML.parse(arg.data); + var xml = xml_js_builder_1.XML.parse(arg.data); var root_1 = xml.find('DAV:propertyupdate'); var finalize_1 = function () { finalize_1 = function () { diff --git a/lib/server/v2/RequestContext.d.ts b/lib/server/v2/RequestContext.d.ts index 28e14251..d59c3393 100644 --- a/lib/server/v2/RequestContext.d.ts +++ b/lib/server/v2/RequestContext.d.ts @@ -1,5 +1,5 @@ /// -import { XMLElement } from '../../helper/XML'; +import { XMLElement } from 'xml-js-builder'; import { WebDAVServer } from './webDAVServer/WebDAVServer'; import { FileSystem } from '../../manager/v2/fileSystem/FileSystem'; import { ReturnCallback } from '../../manager/v2/fileSystem/CommonTypes'; diff --git a/lib/server/v2/RequestContext.js b/lib/server/v2/RequestContext.js index b8e2098b..cc4d238a 100644 --- a/lib/server/v2/RequestContext.js +++ b/lib/server/v2/RequestContext.js @@ -10,7 +10,7 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -var XML_1 = require("../../helper/XML"); +var xml_js_builder_1 = require("xml-js-builder"); var IfParser_1 = require("../../helper/v2/IfParser"); var HTTPCodes_1 = require("../HTTPCodes"); var Path_1 = require("../../manager/v2/Path"); @@ -234,7 +234,7 @@ var HTTPRequestContext = (function (_super) { callback(null); }; HTTPRequestContext.prototype.writeBody = function (xmlObject) { - var content = XML_1.XML.toXML(xmlObject); + var content = xml_js_builder_1.XML.toXML(xmlObject); switch (this.headers.findBestAccept()) { default: case 'xml': @@ -243,7 +243,7 @@ var HTTPRequestContext = (function (_super) { this.response.write(content); break; case 'json': - content = XML_1.XML.toJSON(content); + content = xml_js_builder_1.XML.toJSON(content); this.response.setHeader('Content-Type', 'application/json; charset="utf-8"'); this.response.setHeader('Content-Length', content.length.toString()); this.response.write(content); diff --git a/lib/server/v2/commands/Lock.js b/lib/server/v2/commands/Lock.js index ccf8ea9f..68476be8 100644 --- a/lib/server/v2/commands/Lock.js +++ b/lib/server/v2/commands/Lock.js @@ -8,9 +8,9 @@ var LockKind_1 = require("../../../resource/lock/LockKind"); var LockType_1 = require("../../../resource/lock/LockType"); var Errors_1 = require("../../../Errors"); var Lock_1 = require("../../../resource/lock/Lock"); -var XML_1 = require("../../../helper/XML"); +var xml_js_builder_1 = require("xml-js-builder"); function createResponse(ctx, lock) { - var prop = XML_1.XML.createElement('D:prop', { + var prop = new xml_js_builder_1.XMLElementBuilder('D:prop', { 'xmlns:D': 'DAV:' }); var activelock = prop.ele('D:lockdiscovery').ele('D:activelock'); @@ -25,7 +25,7 @@ function createResponse(ctx, lock) { } function createLock(ctx, data, callback) { try { - var xml = XML_1.XML.parse(data); + var xml = xml_js_builder_1.XML.parse(data); var root = xml.find('DAV:lockinfo'); var scope = new LockScope_1.LockScope(root.find('DAV:lockscope').elements[0].name.substr(4).toLowerCase()); var type_1 = new LockType_1.LockType(root.find('DAV:locktype').elements[0].name.substr(4).toLowerCase()); diff --git a/lib/server/v2/commands/Propfind.js b/lib/server/v2/commands/Propfind.js index 1906be2d..7bbe998e 100644 --- a/lib/server/v2/commands/Propfind.js +++ b/lib/server/v2/commands/Propfind.js @@ -1,7 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var WebDAVRequest_1 = require("../WebDAVRequest"); -var XML_1 = require("../../../helper/XML"); +var xml_js_builder_1 = require("xml-js-builder"); var Workflow_1 = require("../../../helper/Workflow"); var Errors_1 = require("../../../Errors"); var http = require("http"); @@ -36,7 +36,7 @@ function parseRequestBody(ctx, data) { if (ctx.headers.contentLength <= 0) return allTrue; try { - var xml = XML_1.XML.parse(data); + var xml = xml_js_builder_1.XML.parse(data); var propfind = xml.find('DAV:propfind'); if (propfind.findIndex('DAV:propname') !== -1) return onlyName; @@ -71,7 +71,7 @@ var default_1 = (function () { var lockDiscoveryCache = {}; ctx.checkIfHeader(resource, function () { var targetSource = ctx.headers.isSource; - var multistatus = XML_1.XML.createElement('D:multistatus', { + var multistatus = new xml_js_builder_1.XMLElementBuilder('D:multistatus', { 'xmlns:D': 'DAV:' }); resource.type(function (e, type) { return process.nextTick(function () { @@ -120,7 +120,7 @@ var default_1 = (function () { }); }); function addXMLInfo(resource, multistatus, _callback) { var reqBody = parseRequestBody(ctx, data); - var response = XML_1.XML.createElement('D:response'); + var response = new xml_js_builder_1.XMLElementBuilder('D:response'); var callback = function (e) { if (e === Errors_1.Errors.MustIgnore) e = null; diff --git a/lib/server/v2/commands/Proppatch.js b/lib/server/v2/commands/Proppatch.js index 25400a33..e7dfba54 100644 --- a/lib/server/v2/commands/Proppatch.js +++ b/lib/server/v2/commands/Proppatch.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); var WebDAVRequest_1 = require("../WebDAVRequest"); var http_1 = require("http"); var Workflow_1 = require("../../../helper/Workflow"); -var XML_1 = require("../../../helper/XML"); +var xml_js_builder_1 = require("xml-js-builder"); var Errors_1 = require("../../../Errors"); var default_1 = (function () { function default_1() { @@ -12,13 +12,13 @@ var default_1 = (function () { ctx.getResource(function (e, r) { ctx.checkIfHeader(r, function () { //ctx.requirePrivilege([ 'canSetProperty', 'canRemoveProperty' ], r, () => { - var multistatus = XML_1.XML.createElement('D:multistatus', { + var multistatus = new xml_js_builder_1.XMLElementBuilder('D:multistatus', { 'xmlns:D': 'DAV:' }); var response = multistatus.ele('D:response'); response.ele('D:href', undefined, true).add(encodeURI(ctx.fullUri())); try { - var xml = XML_1.XML.parse(data); + var xml = xml_js_builder_1.XML.parse(data); var root_1 = xml.find('DAV:propertyupdate'); var notifications_1 = {}; var reverse_1 = []; diff --git a/lib/server/webDAVServer/Events.d.ts b/lib/server/webDAVServer/Events.d.ts index cb4fdb83..93c21fd1 100644 --- a/lib/server/webDAVServer/Events.d.ts +++ b/lib/server/webDAVServer/Events.d.ts @@ -1,5 +1,5 @@ import { MethodCallArgs } from '../WebDAVRequest'; -import { XMLElement } from '../../helper/XML'; +import { XMLElement } from 'xml-js-builder'; import { IResource } from '../../resource/IResource'; import { FSPath } from '../../manager/FSPath'; import { Lock } from '../../resource/lock/Lock'; diff --git a/package.json b/package.json index 8175f5b6..a421b2dd 100644 --- a/package.json +++ b/package.json @@ -36,14 +36,15 @@ "description": "WebDAV Server", "dependencies": { "mime-types": "^2.1.15", - "xml-js": "^1.2.2" + "xml-js-builder": "^1.0.1" }, "devDependencies": { "@types/mime-types": "^2.1.0", "@types/node": "^7.0.33", "@types/request": "0.0.44", "request": "^2.81.0", - "webdav-fs": "^1.0.0" + "webdav-fs": "^1.0.0", + "xml-js": "^1.3.2" }, "types": "./lib/index.d.ts" } diff --git a/src/helper/XML.ts b/src/helper/XML.ts index c1f92639..8d59072b 100644 --- a/src/helper/XML.ts +++ b/src/helper/XML.ts @@ -1,4 +1,4 @@ -import { Errors } from '../Errors' +/*import { Errors } from '../Errors' import * as xmljs from 'xml-js' function seekForNS(node : any, parentNS : any) : any @@ -273,3 +273,4 @@ export abstract class XML } } +*/ \ No newline at end of file diff --git a/src/helper/export.ts b/src/helper/export.ts index 97e9e950..5ba6132b 100644 --- a/src/helper/export.ts +++ b/src/helper/export.ts @@ -1,4 +1,3 @@ export * from './IfParser' export * from './Workflow' -export * from './XML' diff --git a/src/helper/v2/export.ts b/src/helper/v2/export.ts index 0f232b9c..ef4b1f91 100644 --- a/src/helper/v2/export.ts +++ b/src/helper/v2/export.ts @@ -1,4 +1,3 @@ export * from './IfParser' export * from '../Workflow' -export * from '../XML' diff --git a/src/manager/v2/fileSystem/CommonTypes.ts b/src/manager/v2/fileSystem/CommonTypes.ts index f4e8bbd2..ea918ba3 100644 --- a/src/manager/v2/fileSystem/CommonTypes.ts +++ b/src/manager/v2/fileSystem/CommonTypes.ts @@ -1,6 +1,6 @@ import { Readable, Writable } from 'stream' import { RequestContext } from '../../../server/v2/RequestContext' -import { XMLElement } from '../../../helper/XML' +import { XMLElement } from 'xml-js-builder' import { LockScope } from '../../../resource/lock/LockScope' import { LockType } from '../../../resource/lock/LockType' import { LockKind } from '../../../resource/lock/LockKind' diff --git a/src/manager/v2/fileSystem/ContextInfo.ts b/src/manager/v2/fileSystem/ContextInfo.ts index fa67a94a..e429485c 100644 --- a/src/manager/v2/fileSystem/ContextInfo.ts +++ b/src/manager/v2/fileSystem/ContextInfo.ts @@ -1,6 +1,5 @@ import { Readable, Writable } from 'stream' import { RequestContext } from '../../../server/v2/RequestContext' -import { XMLElement } from '../../../helper/XML' import { LockScope } from '../../../resource/lock/LockScope' import { LockType } from '../../../resource/lock/LockType' import { LockKind } from '../../../resource/lock/LockKind' diff --git a/src/manager/v2/fileSystem/ContextualFileSystem.ts b/src/manager/v2/fileSystem/ContextualFileSystem.ts index e9723018..2017f9e7 100644 --- a/src/manager/v2/fileSystem/ContextualFileSystem.ts +++ b/src/manager/v2/fileSystem/ContextualFileSystem.ts @@ -1,7 +1,6 @@ import { AvailableLocksInfo, CopyInfo, CreateInfo, CreationDateInfo, DeleteInfo, DisplayNameInfo, ETagInfo, IContextInfo, LastModifiedDateInfo, LockManagerInfo, MimeTypeInfo, MoveInfo, OpenReadStreamInfo, OpenWriteStreamInfo, PropertyManagerInfo, ReadDirInfo, RenameInfo, SizeInfo, TypeInfo, WebNameInfo } from './ContextInfo' import { Readable, Writable } from 'stream' import { RequestContext } from '../../../server/v2/RequestContext' -import { XMLElement } from '../../../helper/XML' import { LockScope } from '../../../resource/lock/LockScope' import { LockType } from '../../../resource/lock/LockType' import { LockKind } from '../../../resource/lock/LockKind' diff --git a/src/manager/v2/fileSystem/FileSystem.ts b/src/manager/v2/fileSystem/FileSystem.ts index 58d0750f..38c69ee0 100644 --- a/src/manager/v2/fileSystem/FileSystem.ts +++ b/src/manager/v2/fileSystem/FileSystem.ts @@ -2,7 +2,6 @@ import { PrivilegeManagerInfo, AvailableLocksInfo, CopyInfo, CreateInfo, Creatio import { Readable, Writable } from 'stream' import { RequestContext } from '../../../server/v2/RequestContext' import { BasicPrivilege, PrivilegeManager } from '../../../user/v2/privilege/PrivilegeManager' -import { XMLElement } from '../../../helper/XML' import { LockScope } from '../../../resource/lock/LockScope' import { LockType } from '../../../resource/lock/LockType' import { LockKind } from '../../../resource/lock/LockKind' diff --git a/src/manager/v2/fileSystem/LockManager.ts b/src/manager/v2/fileSystem/LockManager.ts index 3d3d62c9..b902dc94 100644 --- a/src/manager/v2/fileSystem/LockManager.ts +++ b/src/manager/v2/fileSystem/LockManager.ts @@ -1,6 +1,5 @@ import { Readable, Writable } from 'stream' import { RequestContext } from '../../../server/v2/RequestContext' -import { XMLElement } from '../../../helper/XML' import { LockScope } from '../../../resource/lock/LockScope' import { LockType } from '../../../resource/lock/LockType' import { LockKind } from '../../../resource/lock/LockKind' diff --git a/src/manager/v2/fileSystem/PropertyManager.ts b/src/manager/v2/fileSystem/PropertyManager.ts index a97b805a..4ff800c1 100644 --- a/src/manager/v2/fileSystem/PropertyManager.ts +++ b/src/manager/v2/fileSystem/PropertyManager.ts @@ -1,6 +1,5 @@ import { Readable, Writable } from 'stream' import { RequestContext } from '../../../server/v2/RequestContext' -import { XMLElement } from '../../../helper/XML' import { LockScope } from '../../../resource/lock/LockScope' import { LockType } from '../../../resource/lock/LockType' import { LockKind } from '../../../resource/lock/LockKind' diff --git a/src/manager/v2/fileSystem/Resource.ts b/src/manager/v2/fileSystem/Resource.ts index 17c6a52b..ac3a77ee 100644 --- a/src/manager/v2/fileSystem/Resource.ts +++ b/src/manager/v2/fileSystem/Resource.ts @@ -4,7 +4,6 @@ import { FileSystemSerializer, ISerializableFileSystem } from './Serialization' import { FileSystem } from './FileSystem' import { Readable, Writable } from 'stream' import { RequestContext } from '../../../server/v2/RequestContext' -import { XMLElement } from '../../../helper/XML' import { LockScope } from '../../../resource/lock/LockScope' import { LockType } from '../../../resource/lock/LockType' import { LockKind } from '../../../resource/lock/LockKind' diff --git a/src/manager/v2/fileSystem/Serialization.ts b/src/manager/v2/fileSystem/Serialization.ts index 94a89207..2f469ba0 100644 --- a/src/manager/v2/fileSystem/Serialization.ts +++ b/src/manager/v2/fileSystem/Serialization.ts @@ -1,6 +1,5 @@ import { Readable, Writable } from 'stream' import { RequestContext } from '../../../server/v2/RequestContext' -import { XMLElement } from '../../../helper/XML' import { LockScope } from '../../../resource/lock/LockScope' import { LockType } from '../../../resource/lock/LockType' import { LockKind } from '../../../resource/lock/LockKind' diff --git a/src/manager/v2/fileSystem/StandardMethods.ts b/src/manager/v2/fileSystem/StandardMethods.ts index f9a6ab35..0978aec1 100644 --- a/src/manager/v2/fileSystem/StandardMethods.ts +++ b/src/manager/v2/fileSystem/StandardMethods.ts @@ -1,6 +1,5 @@ import { Readable, Writable } from 'stream' import { RequestContext } from '../../../server/v2/RequestContext' -import { XMLElement } from '../../../helper/XML' import { LockScope } from '../../../resource/lock/LockScope' import { LockType } from '../../../resource/lock/LockType' import { LockKind } from '../../../resource/lock/LockKind' diff --git a/src/resource/IResource.ts b/src/resource/IResource.ts index 9fbe969c..978fef39 100644 --- a/src/resource/IResource.ts +++ b/src/resource/IResource.ts @@ -3,7 +3,7 @@ import { FSManager, FSPath } from '../manager/FSManager' import { StandardResource } from './std/StandardResource' import { RequestContext } from '../server/MethodCallArgs' import { WorkflowUnique } from '../helper/Workflow' -import { XMLElement } from '../helper/XML' +import { XMLElement } from 'xml-js-builder' import { LockKind } from './lock/LockKind' import { LockType } from './lock/LockType' import { Errors } from '../Errors' diff --git a/src/resource/lock/Lock.ts b/src/resource/lock/Lock.ts index 9760b317..81bea5c9 100644 --- a/src/resource/lock/Lock.ts +++ b/src/resource/lock/Lock.ts @@ -1,4 +1,4 @@ -import { XMLElement } from '../../helper/XML' +import { XMLElement } from 'xml-js-builder' import { LockKind } from './LockKind' import { IUser } from '../../user/IUser' diff --git a/src/resource/std/resourceTester/Properties.ts b/src/resource/std/resourceTester/Properties.ts index bd7136b7..8526875f 100644 --- a/src/resource/std/resourceTester/Properties.ts +++ b/src/resource/std/resourceTester/Properties.ts @@ -1,5 +1,5 @@ import { ResourceTesterTestCallback } from './Types' -import { XML } from '../../../helper/XML' +import { XML } from 'xml-js-builder' // ****************************** Properties ****************************** // export function setProperty(callback : ResourceTesterTestCallback) diff --git a/src/server/MethodCallArgs.ts b/src/server/MethodCallArgs.ts index ea81e6f0..4dc3e42a 100644 --- a/src/server/MethodCallArgs.ts +++ b/src/server/MethodCallArgs.ts @@ -1,7 +1,7 @@ import { IResource, ReturnCallback, ResourceType } from '../resource/IResource' import { requirePrivilege, BasicPrivilege } from '../user/privilege/IPrivilegeManager' import { EventsName, DetailsType } from './webDAVServer/Events' -import { XML, XMLElement } from '../helper/XML' +import { XML, XMLElement } from 'xml-js-builder' import { parseIfHeader } from '../helper/IfParser' import { WebDAVServer } from './webDAVServer/WebDAVServer' import { HTTPCodes } from './HTTPCodes' diff --git a/src/server/commands/Lock.ts b/src/server/commands/Lock.ts index 22ed74d3..34beb336 100644 --- a/src/server/commands/Lock.ts +++ b/src/server/commands/Lock.ts @@ -6,12 +6,12 @@ import { LockKind } from '../../resource/lock/LockKind' import { LockType } from '../../resource/lock/LockType' import { Errors } from '../../Errors' import { Lock } from '../../resource/lock/Lock' -import { XML } from '../../helper/XML' +import { XML, XMLElementBuilder } from 'xml-js-builder' import * as path from 'path' function createResponse(arg : MethodCallArgs, lock : Lock) { - const prop = XML.createElement('D:prop', { + const prop = new XMLElementBuilder('D:prop', { 'xmlns:D': 'DAV:' }); const activelock = prop.ele('D:lockdiscovery').ele('D:activelock'); diff --git a/src/server/commands/Propfind.ts b/src/server/commands/Propfind.ts index 73525988..605980ad 100644 --- a/src/server/commands/Propfind.ts +++ b/src/server/commands/Propfind.ts @@ -1,6 +1,6 @@ import { IResource, ETag, ReturnCallback, ResourceType } from '../../resource/IResource' import { HTTPCodes, MethodCallArgs, WebDAVRequest } from '../WebDAVRequest' -import { XML, XMLElement } from '../../helper/XML' +import { XMLElementBuilder, XML, XMLElement } from 'xml-js-builder' import { BasicPrivilege } from '../../user/privilege/IPrivilegeManager' import { Workflow } from '../../helper/Workflow' import { FSPath } from '../../manager/FSPath' @@ -139,7 +139,7 @@ export function method(arg : MethodCallArgs, callback) arg.checkIfHeader(resource, () => { const targetSource = arg.isSource; - const multistatus = XML.createElement('D:multistatus', { + const multistatus = new XMLElementBuilder('D:multistatus', { 'xmlns:D': 'DAV:' }) @@ -195,7 +195,7 @@ export function method(arg : MethodCallArgs, callback) { const reqBody = parseRequestBody(arg); - const response = XML.createElement('D:response'); + const response = new XMLElementBuilder('D:response'); const callback = (e ?: Error) => { if(e === Errors.MustIgnore) e = null; diff --git a/src/server/commands/Proppatch.ts b/src/server/commands/Proppatch.ts index 3ee8a347..a98dc35a 100644 --- a/src/server/commands/Proppatch.ts +++ b/src/server/commands/Proppatch.ts @@ -3,7 +3,7 @@ import { IResource, ResourceType } from '../../resource/IResource' import { STATUS_CODES } from 'http' import { EventsName } from '../../server/webDAVServer/events' import { Workflow } from '../../helper/Workflow' -import { XML } from '../../helper/XML' +import { XML, XMLElementBuilder } from 'xml-js-builder' export function method(arg : MethodCallArgs, callback) { @@ -17,7 +17,7 @@ export function method(arg : MethodCallArgs, callback) arg.checkIfHeader(r, () => { arg.requirePrivilege([ 'canSetProperty', 'canRemoveProperty' ], r, () => { - const multistatus = XML.createElement('D:multistatus', { + const multistatus = new XMLElementBuilder('D:multistatus', { 'xmlns:D': 'DAV:' }); const response = multistatus.ele('D:response'); diff --git a/src/server/commands/Unlock.ts b/src/server/commands/Unlock.ts index 8f48c195..c857a13a 100644 --- a/src/server/commands/Unlock.ts +++ b/src/server/commands/Unlock.ts @@ -6,7 +6,7 @@ import { LockKind } from '../../resource/lock/LockKind' import { LockType } from '../../resource/lock/LockType' import { Errors } from '../../Errors' import { Lock } from '../../resource/lock/Lock' -import { XML } from '../../helper/XML' +import { XML } from 'xml-js-builder' export function method(arg : MethodCallArgs, callback) { diff --git a/src/server/v2/RequestContext.ts b/src/server/v2/RequestContext.ts index db52de3e..37375aab 100644 --- a/src/server/v2/RequestContext.ts +++ b/src/server/v2/RequestContext.ts @@ -1,4 +1,4 @@ -import { XML, XMLElement } from '../../helper/XML' +import { XML, XMLElement } from 'xml-js-builder' import { parseIfHeader } from '../../helper/v2/IfParser' import { WebDAVServer } from './webDAVServer/WebDAVServer' import { HTTPCodes } from '../HTTPCodes' diff --git a/src/server/v2/commands/Lock.ts b/src/server/v2/commands/Lock.ts index 23e0f88b..d183a1b8 100644 --- a/src/server/v2/commands/Lock.ts +++ b/src/server/v2/commands/Lock.ts @@ -7,13 +7,13 @@ import { LockKind } from '../../../resource/lock/LockKind' import { LockType } from '../../../resource/lock/LockType' import { Errors } from '../../../Errors' import { Lock } from '../../../resource/lock/Lock' -import { XML } from '../../../helper/XML' +import { XML, XMLElementBuilder } from 'xml-js-builder' import { IUser } from '../../../user/v2/IUser' import * as path from 'path' function createResponse(ctx : HTTPRequestContext, lock : Lock) { - const prop = XML.createElement('D:prop', { + const prop = new XMLElementBuilder('D:prop', { 'xmlns:D': 'DAV:' }); const activelock = prop.ele('D:lockdiscovery').ele('D:activelock'); diff --git a/src/server/v2/commands/Propfind.ts b/src/server/v2/commands/Propfind.ts index 2cee4465..89bc4a5d 100644 --- a/src/server/v2/commands/Propfind.ts +++ b/src/server/v2/commands/Propfind.ts @@ -1,5 +1,5 @@ import { HTTPCodes, HTTPRequestContext, HTTPMethod } from '../WebDAVRequest' -import { XML, XMLElement } from '../../../helper/XML' +import { XML, XMLElementBuilder, XMLElement } from 'xml-js-builder' import { Workflow } from '../../../helper/Workflow' import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' import { Resource } from '../../../manager/v2/fileSystem/Resource' @@ -161,7 +161,7 @@ export default class implements HTTPMethod ctx.checkIfHeader(resource, () => { const targetSource = ctx.headers.isSource; - const multistatus = XML.createElement('D:multistatus', { + const multistatus = new XMLElementBuilder('D:multistatus', { 'xmlns:D': 'DAV:' }) @@ -222,7 +222,7 @@ export default class implements HTTPMethod { const reqBody = parseRequestBody(ctx, data); - const response = XML.createElement('D:response'); + const response = new XMLElementBuilder('D:response'); const callback = (e ?: Error) => { if(e === Errors.MustIgnore) e = null; diff --git a/src/server/v2/commands/Proppatch.ts b/src/server/v2/commands/Proppatch.ts index 5d8d3539..49115eb8 100644 --- a/src/server/v2/commands/Proppatch.ts +++ b/src/server/v2/commands/Proppatch.ts @@ -3,7 +3,7 @@ import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' import { IPropertyManager } from '../../../manager/v2/fileSystem/PropertyManager' import { STATUS_CODES } from 'http' import { Workflow } from '../../../helper/Workflow' -import { XML, XMLElement } from '../../../helper/XML' +import { XML, XMLElementBuilder, XMLElement } from 'xml-js-builder' import { Errors } from '../../../Errors' export default class implements HTTPMethod @@ -13,7 +13,7 @@ export default class implements HTTPMethod ctx.getResource((e, r) => { ctx.checkIfHeader(r, () => { //ctx.requirePrivilege([ 'canSetProperty', 'canRemoveProperty' ], r, () => { - const multistatus = XML.createElement('D:multistatus', { + const multistatus = new XMLElementBuilder('D:multistatus', { 'xmlns:D': 'DAV:' }); const response = multistatus.ele('D:response'); diff --git a/src/server/v2/commands/Unlock.ts b/src/server/v2/commands/Unlock.ts index f05df09e..40e247ad 100644 --- a/src/server/v2/commands/Unlock.ts +++ b/src/server/v2/commands/Unlock.ts @@ -6,7 +6,7 @@ import { LockKind } from '../../../resource/lock/LockKind' import { LockType } from '../../../resource/lock/LockType' import { Errors } from '../../../Errors' import { Lock } from '../../../resource/lock/Lock' -import { XML } from '../../../helper/XML' +import { XML } from 'xml-js-builder' export default class implements HTTPMethod { diff --git a/src/server/webDAVServer/Events.ts b/src/server/webDAVServer/Events.ts index d29a9de3..28f9513f 100644 --- a/src/server/webDAVServer/Events.ts +++ b/src/server/webDAVServer/Events.ts @@ -1,5 +1,5 @@ import { MethodCallArgs } from '../WebDAVRequest' -import { XMLElement } from '../../helper/XML' +import { XMLElement } from 'xml-js-builder' import { IResource } from '../../resource/IResource' import { FSPath } from '../../manager/FSPath' import { Lock } from '../../resource/lock/Lock' diff --git a/test/v2/root.js b/test/v2/root.js index 8afd564e..d993eceb 100644 --- a/test/v2/root.js +++ b/test/v2/root.js @@ -2,7 +2,8 @@ var webdav = require('../../lib/index.js').v2, request = require('request'), path = require('path'), - fs = require('fs') + fs = require('fs'), + xmljs = require('xml-js-builder') module.exports = (callback, options) => { var successes = []; @@ -111,7 +112,7 @@ module.exports = (callback, options) => { { try { - body = webdav.XML.parse(body); + body = xmljs.XML.parse(body); } catch(ex) { diff --git a/test/v2/tests.ts/Type.ts b/test/v2/tests.ts/Type.ts index 4564f9ff..7c9efa82 100644 --- a/test/v2/tests.ts/Type.ts +++ b/test/v2/tests.ts/Type.ts @@ -1,5 +1,6 @@ import { v2 } from '../../../lib/index.js' import { RequestResponse, Options, Request } from 'request' +import { XMLElementUtil } from 'xml-js-builder' export interface TestInfo { @@ -13,8 +14,8 @@ export interface TestInfo (config : Options, codeStatusExpected : number, callback : (res : RequestResponse, body ?: string) => void) : void } reqXML : { - (config : Options, callback : (res : RequestResponse, body ?: v2.XMLElement) => void) : void - (config : Options, codeStatusExpected : number, callback : (res : RequestResponse, body ?: v2.XMLElement) => void) : void + (config : Options, callback : (res : RequestResponse, body ?: XMLElementUtil) => void) : void + (config : Options, codeStatusExpected : number, callback : (res : RequestResponse, body ?: XMLElementUtil) => void) : void } reqStream : (config : Options, callback : () => void) => Request } diff --git a/test/v2/tests.ts/lockUnlock/.createFiles.ts b/test/v2/tests.ts/lockUnlock/.createFiles.ts index aeccbb37..bf0e28a0 100644 --- a/test/v2/tests.ts/lockUnlock/.createFiles.ts +++ b/test/v2/tests.ts/lockUnlock/.createFiles.ts @@ -1,12 +1,13 @@ import { TestCallback, TestInfo } from '../Type' import { v2 } from '../../../../lib/index.js' +import { XMLElementUtil } from 'xml-js-builder' export interface Lock { scope : string type : string depth : number - owner : string | v2.XMLElement | v2.XMLElement[] + owner : string | XMLElementUtil | XMLElementUtil[] timeoutSec : number uuid : string root : string diff --git a/test/v2/tests.ts/lockUnlock/lockPropfindMethod.ts b/test/v2/tests.ts/lockUnlock/lockPropfindMethod.ts index 8eb0e88b..efc8ec38 100644 --- a/test/v2/tests.ts/lockUnlock/lockPropfindMethod.ts +++ b/test/v2/tests.ts/lockUnlock/lockPropfindMethod.ts @@ -1,10 +1,11 @@ import { Test } from '../Type' import { v2 } from '../../../../lib/index.js' import { methodTesterNotBlocking } from './.createFiles' +import { XMLElementUtil } from 'xml-js-builder' export default ((info, isValid) => { - function testStatus(xml : v2.XMLElement, expectedCode : number, callback : () => void) + function testStatus(xml : XMLElementUtil, expectedCode : number, callback : () => void) { try { diff --git a/test/v2/tests.ts/lockUnlock/lockProppatchMethod.ts b/test/v2/tests.ts/lockUnlock/lockProppatchMethod.ts index 18167209..f3c75566 100644 --- a/test/v2/tests.ts/lockUnlock/lockProppatchMethod.ts +++ b/test/v2/tests.ts/lockUnlock/lockProppatchMethod.ts @@ -1,12 +1,13 @@ import { Test } from '../Type' import { v2 } from '../../../../lib/index.js' import { methodTesterBlocking } from './.createFiles' +import { XMLElementUtil } from 'xml-js-builder' export default ((info, isValid) => { const proppatch = 'Jim WhiteheadRoy Fielding'; - function testStatus(xml : v2.XMLElement, expectedCode : number, callback : () => void) + function testStatus(xml : XMLElementUtil, expectedCode : number, callback : () => void) { try { diff --git a/test/v2/tests.ts/properties/.createFiles.ts b/test/v2/tests.ts/properties/.createFiles.ts index bfc444d1..3863d9ac 100644 --- a/test/v2/tests.ts/properties/.createFiles.ts +++ b/test/v2/tests.ts/properties/.createFiles.ts @@ -1,7 +1,8 @@ import { TestCallback, TestInfo } from '../Type' import { v2 } from '../../../../lib/index.js' +import { XMLElementUtil } from 'xml-js-builder' -export function proppatch(server : v2.WebDAVServer, info : TestInfo, path : string, expectedStatusCode : number, bodySet : string[], bodyRemove : string[], callback : (xml : v2.XMLElement) => void) +export function proppatch(server : v2.WebDAVServer, info : TestInfo, path : string, expectedStatusCode : number, bodySet : string[], bodyRemove : string[], callback : (xml : XMLElementUtil) => void) { let body = ''; if(bodySet && bodySet.length > 0) @@ -19,7 +20,7 @@ export function proppatch(server : v2.WebDAVServer, info : TestInfo, path : stri }) } -export function propfind(server : v2.WebDAVServer, info : TestInfo, path : string, expectedStatusCode : number, depth : number, body : string, callback : (xml : v2.XMLElement) => void) +export function propfind(server : v2.WebDAVServer, info : TestInfo, path : string, expectedStatusCode : number, depth : number, body : string, callback : (xml : XMLElementUtil) => void) { info.reqXML({ url: 'http://localhost:' + server.options.port + '/' + path,