芝麻web文件管理V1.00
编辑当前文件:/home/freeclou/app.optimyar.com/backend/node_modules/xml-crypto/lib/c14n-canonicalization.js
/* jshint laxcomma: true */ var utils = require('./utils'); exports.C14nCanonicalization = C14nCanonicalization; exports.C14nCanonicalizationWithComments = C14nCanonicalizationWithComments; function C14nCanonicalization() { this.includeComments = false; }; C14nCanonicalization.prototype.attrCompare = function(a,b) { if (!a.namespaceURI && b.namespaceURI) { return -1; } if (!b.namespaceURI && a.namespaceURI) { return 1; } var left = a.namespaceURI + a.localName var right = b.namespaceURI + b.localName if (left===right) return 0 else if (left
0){ // Remove namespaces which are already present in nsListToRender for(var p1 in ancestorNamespaces){ if(!ancestorNamespaces.hasOwnProperty(p1)) continue; var alreadyListed = false; for(var p2 in nsListToRender){ if(nsListToRender[p2].prefix === ancestorNamespaces[p1].prefix && nsListToRender[p2].namespaceURI === ancestorNamespaces[p1].namespaceURI) { alreadyListed = true; } } if(!alreadyListed){ nsListToRender.push(ancestorNamespaces[p1]); } } } nsListToRender.sort(this.nsCompare); //render namespaces for (a in nsListToRender) { if (!nsListToRender.hasOwnProperty(a)) { continue; } p = nsListToRender[a]; res.push(" xmlns:", p.prefix, '="', p.namespaceURI, '"'); } return {"rendered": res.join(""), "newDefaultNs": newDefaultNs}; }; C14nCanonicalization.prototype.processInner = function(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces) { if (node.nodeType === 8) { return this.renderComment(node); } if (node.data) { return utils.encodeSpecialCharactersInText(node.data); } var i, pfxCopy , ns = this.renderNs(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces) , res = ["<", node.tagName, ns.rendered, this.renderAttrs(node, ns.newDefaultNs), ">"]; for (i = 0; i < node.childNodes.length; ++i) { pfxCopy = prefixesInScope.slice(0); res.push(this.processInner(node.childNodes[i], pfxCopy, ns.newDefaultNs, defaultNsForPrefix, [])); } res.push("", node.tagName, ">"); return res.join(""); }; // Thanks to deoxxa/xml-c14n for comment renderer C14nCanonicalization.prototype.renderComment = function (node) { if (!this.includeComments) { return ""; } var isOutsideDocument = (node.ownerDocument === node.parentNode), isBeforeDocument = null, isAfterDocument = null; if (isOutsideDocument) { var nextNode = node, previousNode = node; while (nextNode !== null) { if (nextNode === node.ownerDocument.documentElement) { isBeforeDocument = true; break; } nextNode = nextNode.nextSibling; } while (previousNode !== null) { if (previousNode === node.ownerDocument.documentElement) { isAfterDocument = true; break; } previousNode = previousNode.previousSibling; } } return (isAfterDocument ? "\n" : "") + "" + (isBeforeDocument ? "\n" : ""); }; /** * Perform canonicalization of the given node * * @param {Node} node * @return {String} * @api public */ C14nCanonicalization.prototype.process = function(node, options) { options = options || {}; var defaultNs = options.defaultNs || ""; var defaultNsForPrefix = options.defaultNsForPrefix || {}; var ancestorNamespaces = options.ancestorNamespaces || []; var prefixesInScope = []; for (var i = 0; i < ancestorNamespaces.length; i++) { prefixesInScope.push(ancestorNamespaces[i].prefix); } var res = this.processInner(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces); return res; }; C14nCanonicalization.prototype.getAlgorithmName = function() { return "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"; }; // Add c14n#WithComments here (very simple subclass) exports.C14nCanonicalizationWithComments = C14nCanonicalizationWithComments; function C14nCanonicalizationWithComments() { C14nCanonicalization.call(this); this.includeComments = true; }; C14nCanonicalizationWithComments.prototype = Object.create(C14nCanonicalization.prototype); C14nCanonicalizationWithComments.prototype.constructor = C14nCanonicalizationWithComments; C14nCanonicalizationWithComments.prototype.getAlgorithmName = function() { return "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"; };