Mercurial > hg > release > icedtea7-forest-2.3 > jdk
changeset 6400:c31a79eedba2
8025026: Enhance canonicalization
Summary: Don't use cached null xmlns definition. Also reviewed by Alexander Fomin <alexander.fomin@oracle.com>
Reviewed-by: mullan, hawtin
author | xuelei |
---|---|
date | Mon, 14 Oct 2013 18:35:40 -0700 |
parents | 8903edf477cf |
children | 458e5fe61d94 |
files | src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/Canonicalizer11.java src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/Canonicalizer20010315.java src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/Canonicalizer20010315Excl.java src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java |
diffstat | 4 files changed, 28 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/Canonicalizer11.java Fri Sep 13 15:17:31 2013 +0800 +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/Canonicalizer11.java Mon Oct 14 18:35:40 2013 -0700 @@ -358,7 +358,8 @@ } else if (!isVisible(xmlns)) { // There is a defn but the xmlns is not selected by the xpath. // then xmlns="" - n = ns.addMappingAndRender(XMLNS, "", nullNode); + n = ns.addMappingAndRender(XMLNS, "", + getNullNode(xmlns.getOwnerDocument())); } // output the xmlns def if needed. if (n != null) {
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/Canonicalizer20010315.java Fri Sep 13 15:17:31 2013 +0800 +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/Canonicalizer20010315.java Mon Oct 14 18:35:40 2013 -0700 @@ -302,7 +302,8 @@ } else if ( !isVisible(xmlns)) { //There is a definition but the xmlns is not selected by the xpath. //then xmlns="" - n=ns.addMappingAndRender(XMLNS,"",nullNode); + n=ns.addMappingAndRender(XMLNS, "", + getNullNode(xmlns.getOwnerDocument())); } //output the xmlns def if needed. if (n!=null) {
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/Canonicalizer20010315Excl.java Fri Sep 13 15:17:31 2013 +0800 +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/Canonicalizer20010315Excl.java Mon Oct 14 18:35:40 2013 -0700 @@ -300,7 +300,7 @@ if ((xmlns!=null) && (!isVisible(xmlns))) { //There is a definition but the xmlns is not selected by the xpath. //then xmlns="" - ns.addMapping(XMLNS,"",nullNode); + ns.addMapping(XMLNS, "", getNullNode(xmlns.getOwnerDocument())); } if (E.getNamespaceURI() != null) {
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java Fri Sep 13 15:17:31 2013 +0800 +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java Mon Oct 14 18:35:40 2013 -0700 @@ -34,7 +34,6 @@ import java.util.Map; import java.util.Set; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException; @@ -48,6 +47,7 @@ import org.w3c.dom.Attr; import org.w3c.dom.Comment; import org.w3c.dom.Element; +import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.ProcessingInstruction; @@ -86,22 +86,10 @@ static final int NODE_BEFORE_DOCUMENT_ELEMENT = -1; static final int NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT = 0; static final int NODE_AFTER_DOCUMENT_ELEMENT = 1; - //The null xmlns definiton. - protected static final Attr nullNode; - static { - try { - nullNode=DocumentBuilderFactory.newInstance(). - newDocumentBuilder().newDocument().createAttributeNS(Constants.NamespaceSpecNS,XMLNS); - nullNode.setValue(""); - } catch (Exception e) { - throw new RuntimeException("Unable to create nullNode"/*,*/+e); - } - } - List nodeFilter; - boolean _includeComments; Set _xpathNodeSet = null; + /** * The node to be skiped/excluded from the DOM tree * in subtree canonicalizations. @@ -110,6 +98,11 @@ OutputStream _writer = new UnsyncByteArrayOutputStream();//null; /** + * The null xmlns definition. + */ + private Attr nullNode; + + /** * Constructor CanonicalizerBase * * @param includeComments @@ -613,7 +606,8 @@ Attr nsprefix; if (((nsprefix=ns.getMappingWithoutRendered("xmlns"))!=null) && "".equals(nsprefix.getValue())) { - ns.addMappingAndRender("xmlns","",nullNode); + ns.addMappingAndRender("xmlns", "", + getNullNode(nsprefix.getOwnerDocument())); } } /** @@ -841,4 +835,18 @@ } } + // The null xmlns definition. + protected Attr getNullNode(Document ownerDocument) { + if (nullNode == null) { + try { + nullNode = ownerDocument.createAttributeNS( + Constants.NamespaceSpecNS, XMLNS); + nullNode.setValue(""); + } catch (Exception e) { + throw new RuntimeException("Unable to create nullNode: " + e); + } + } + return nullNode; + } + }