Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*
* @package jsDAV
* @subpackage CalDAV
* @copyright Copyright(c) 2013 Mike de Boer.
* @author Oleg Elifantiev
* @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License
*/
"use strict";
var Base = require('./../shared/base');
var Util = require("./../shared/util");
var Exc = require("./../shared/exceptions");
var Xml = require("./../shared/xml");
var xpath = require('xpath');
var XPathResult = xpath.XPathResult;
var jsVObject_DateTimeParser = require('./../VObject/dateTimeParser');
function xSelect(expr, doc, single) {
var nodesWithXMLNS = xpath.select("//@*[starts-with(name(), 'xmlns:')]", doc);
var revmap = {};
for(var i = 0, l = nodesWithXMLNS.length; i < l; i++) {
var node = nodesWithXMLNS[i];
revmap[node.nodeName.substr(6)] = node.nodeValue;
}
// FIXME THIS IS UGLY!
var expression = xpath.createExpression(expr, {
let result: xpath.XPathResult = xpath.evaluate(
query, // xpathExpression
xdoc, // contextNode
resolver, // namespaceResolver
xpath.XPathResult.ANY_TYPE, // resultType
null // result
)
let evalResult = new EvaluatorResult();
evalResult.type = EvaluatorResultType.SCALAR_TYPE;
switch(result.resultType) {
case xpath.XPathResult.NUMBER_TYPE:
evalResult.result = result.numberValue;
break;
case xpath.XPathResult.STRING_TYPE:
evalResult.result = result.stringValue;
break;
case xpath.XPathResult.BOOLEAN_TYPE:
evalResult.result = result.booleanValue;
break;
case xpath.XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
case xpath.XPathResult.ORDERED_NODE_ITERATOR_TYPE:
evalResult.result = result.booleanValue;
let node: Node;
while (node = result.iterateNext()) {
nodes.push(node);
}
evalResult.result = nodes;
evalResult.type = EvaluatorResultType.NODE_COLLECTION;
break;
}
if (ignoreDefaultNamespace) {
xml = xml.replace(/xmlns=".+"/g, (match: string) => {
return match.replace(/xmlns/g, 'xmlns:default');
});
}
let nodes: Node[] = new Array();
let xdoc: Document = new DOMParser().parseFromString(xml, 'text/xml');
let resolver: xpath.XPathNSResolver = xpath.createNSResolver(xdoc);
let result: xpath.XPathResult = xpath.evaluate(
query, // xpathExpression
xdoc, // contextNode
resolver, // namespaceResolver
xpath.XPathResult.ANY_TYPE, // resultType
null // result
)
let evalResult = new EvaluatorResult();
evalResult.type = EvaluatorResultType.SCALAR_TYPE;
switch(result.resultType) {
case xpath.XPathResult.NUMBER_TYPE:
evalResult.result = result.numberValue;
break;
case xpath.XPathResult.STRING_TYPE:
evalResult.result = result.stringValue;
break;
case xpath.XPathResult.BOOLEAN_TYPE:
evalResult.result = result.booleanValue;
break;
function getXPathResult() {
if (typeof(XPathResult) === 'undefined') {
return xpath.XPathResult;
}
return XPathResult;
}