/* 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"]; 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(""); 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 res = this.processInner(node, [], defaultNs, defaultNsForPrefix); 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"; };