You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2011/04/15 17:47:34 UTC
svn commit: r1092749 - in
/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security:
./ c14n/ c14n/implementations/ transforms/params/ utils/
Author: coheigea
Date: Fri Apr 15 15:47:34 2011
New Revision: 1092749
URL: http://svn.apache.org/viewvc?rev=1092749&view=rev
Log:
Committed a refactor of the C14n code.
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/Init.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/Canonicalizer.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/CanonicalizerSpi.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer11.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/NameSpaceSymbTable.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/params/InclusiveNamespaces.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/Init.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/Init.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/Init.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/Init.java Fri Apr 15 15:47:34 2011
@@ -34,6 +34,13 @@ import org.apache.xml.security.algorithm
import org.apache.xml.security.algorithms.implementations.SignatureDSA;
import org.apache.xml.security.algorithms.implementations.SignatureECDSA;
import org.apache.xml.security.c14n.Canonicalizer;
+import org.apache.xml.security.c14n.CanonicalizerSpi;
+import org.apache.xml.security.c14n.implementations.Canonicalizer11_OmitComments;
+import org.apache.xml.security.c14n.implementations.Canonicalizer11_WithComments;
+import org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments;
+import org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments;
+import org.apache.xml.security.c14n.implementations.Canonicalizer20010315OmitComments;
+import org.apache.xml.security.c14n.implementations.Canonicalizer20010315WithComments;
import org.apache.xml.security.encryption.XMLCipher;
import org.apache.xml.security.keys.keyresolver.KeyResolver;
import org.apache.xml.security.signature.XMLSignature;
@@ -86,6 +93,8 @@ public class Init {
new HashMap<String, Class<? extends SignatureAlgorithmSpi>>();
private static Map<String, JCEMapper.Algorithm> defaultAlgorithms =
new HashMap<String, JCEMapper.Algorithm>();
+ private static Map<String, Class<? extends CanonicalizerSpi>> defaultC14nAlgorithms =
+ new HashMap<String, Class<? extends CanonicalizerSpi>>();
static {
//
@@ -335,6 +344,28 @@ public class Init {
XMLCipher.AES_256_KeyWrap,
new JCEMapper.Algorithm("AES", "AESWrap")
);
+
+ //
+ // Default IRI-Canonicalizer class pairs
+ //
+ defaultC14nAlgorithms.put(
+ Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS, Canonicalizer20010315OmitComments.class
+ );
+ defaultC14nAlgorithms.put(
+ Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS, Canonicalizer20010315WithComments.class
+ );
+ defaultC14nAlgorithms.put(
+ Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS, Canonicalizer20010315ExclOmitComments.class
+ );
+ defaultC14nAlgorithms.put(
+ Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS, Canonicalizer20010315ExclWithComments.class
+ );
+ defaultC14nAlgorithms.put(
+ Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS, Canonicalizer11_OmitComments.class
+ );
+ defaultC14nAlgorithms.put(
+ Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS, Canonicalizer11_WithComments.class
+ );
}
/**
@@ -610,6 +641,14 @@ public class Init {
JCEMapper.register(key, defaultAlgorithms.get(key));
}
+ //
+ // Set the default c14n algorithms
+ //
+ for (String key : defaultC14nAlgorithms.keySet()) {
+ Canonicalizer.register(
+ key, (Class<CanonicalizerSpi>)defaultC14nAlgorithms.get(key)
+ );
+ }
} catch (Exception ex) {
log.error(ex);
ex.printStackTrace();
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/Canonicalizer.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/Canonicalizer.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/Canonicalizer.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/Canonicalizer.java Fri Apr 15 15:47:34 2011
@@ -79,11 +79,10 @@ public class Canonicalizer {
public static final String ALGO_ID_C14N11_WITH_COMMENTS =
ALGO_ID_C14N11_OMIT_COMMENTS + "#WithComments";
- protected CanonicalizerSpi canonicalizerSpi = null;
-
private static Map<String, Class<CanonicalizerSpi>> canonicalizerHash =
new ConcurrentHashMap<String, Class<CanonicalizerSpi>>();
-
+
+ private final CanonicalizerSpi canonicalizerSpi;
/**
* Constructor Canonicalizer
@@ -93,13 +92,12 @@ public class Canonicalizer {
*/
private Canonicalizer(String algorithmURI) throws InvalidCanonicalizerException {
try {
- Class<CanonicalizerSpi> implementingClass = getImplementingClass(algorithmURI);
+ Class<CanonicalizerSpi> implementingClass = canonicalizerHash.get(algorithmURI);
- this.canonicalizerSpi = implementingClass.newInstance();
- this.canonicalizerSpi.reset = true;
+ canonicalizerSpi = implementingClass.newInstance();
+ canonicalizerSpi.reset = true;
} catch (Exception e) {
Object exArgs[] = { algorithmURI };
-
throw new InvalidCanonicalizerException(
"signature.Canonicalizer.UnknownCanonicalizer", exArgs
);
@@ -129,19 +127,37 @@ public class Canonicalizer {
public static void register(String algorithmURI, String implementingClass)
throws AlgorithmAlreadyRegisteredException, ClassNotFoundException {
// check whether URI is already registered
- Class<CanonicalizerSpi> registeredClass = getImplementingClass(algorithmURI);
+ Class<CanonicalizerSpi> registeredClass = canonicalizerHash.get(algorithmURI);
if (registeredClass != null) {
Object exArgs[] = { algorithmURI, registeredClass };
-
throw new AlgorithmAlreadyRegisteredException("algorithm.alreadyRegistered", exArgs);
}
canonicalizerHash.put(
- algorithmURI,
- (Class<CanonicalizerSpi>)Class.forName(implementingClass)
+ algorithmURI, (Class<CanonicalizerSpi>)Class.forName(implementingClass)
);
}
+
+ /**
+ * Method register
+ *
+ * @param algorithmURI
+ * @param implementingClass
+ * @throws AlgorithmAlreadyRegisteredException
+ */
+ public static void register(String algorithmURI, Class<CanonicalizerSpi> implementingClass)
+ throws AlgorithmAlreadyRegisteredException, ClassNotFoundException {
+ // check whether URI is already registered
+ Class<CanonicalizerSpi> registeredClass = canonicalizerHash.get(algorithmURI);
+
+ if (registeredClass != null) {
+ Object exArgs[] = { algorithmURI, registeredClass };
+ throw new AlgorithmAlreadyRegisteredException("algorithm.alreadyRegistered", exArgs);
+ }
+
+ canonicalizerHash.put(algorithmURI, implementingClass);
+ }
/**
* Method getURI
@@ -149,7 +165,7 @@ public class Canonicalizer {
* @return the URI defined for this c14n instance.
*/
public final String getURI() {
- return this.canonicalizerSpi.engineGetURI();
+ return canonicalizerSpi.engineGetURI();
}
/**
@@ -158,7 +174,7 @@ public class Canonicalizer {
* @return true if the c14n respect the comments.
*/
public boolean getIncludeComments() {
- return this.canonicalizerSpi.engineGetIncludeComments();
+ return canonicalizerSpi.engineGetIncludeComments();
}
/**
@@ -182,7 +198,7 @@ public class Canonicalizer {
dfactory.setNamespaceAware(true);
- // needs to validate for ID attribute nomalization
+ // needs to validate for ID attribute normalization
dfactory.setValidating(true);
DocumentBuilder db = dfactory.newDocumentBuilder();
@@ -207,14 +223,11 @@ public class Canonicalizer {
* declaration are used to help create the canonical form, even
* though the document type declaration is not retained in the
* canonical form.
- *
*/
db.setErrorHandler(new org.apache.xml.security.utils.IgnoreAllErrorHandler());
Document document = db.parse(in);
- byte result[] = this.canonicalizeSubtree(document);
-
- return result;
+ return this.canonicalizeSubtree(document);
}
/**
@@ -226,7 +239,7 @@ public class Canonicalizer {
* @throws CanonicalizationException
*/
public byte[] canonicalizeSubtree(Node node) throws CanonicalizationException {
- return this.canonicalizerSpi.engineCanonicalizeSubTree(node);
+ return canonicalizerSpi.engineCanonicalizeSubTree(node);
}
/**
@@ -239,7 +252,7 @@ public class Canonicalizer {
*/
public byte[] canonicalizeSubtree(Node node, String inclusiveNamespaces)
throws CanonicalizationException {
- return this.canonicalizerSpi.engineCanonicalizeSubTree(node, inclusiveNamespaces);
+ return canonicalizerSpi.engineCanonicalizeSubTree(node, inclusiveNamespaces);
}
/**
@@ -252,7 +265,7 @@ public class Canonicalizer {
*/
public byte[] canonicalizeXPathNodeSet(NodeList xpathNodeSet)
throws CanonicalizationException {
- return this.canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet);
+ return canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet);
}
/**
@@ -268,7 +281,7 @@ public class Canonicalizer {
NodeList xpathNodeSet, String inclusiveNamespaces
) throws CanonicalizationException {
return
- this.canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet, inclusiveNamespaces);
+ canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet, inclusiveNamespaces);
}
/**
@@ -280,7 +293,7 @@ public class Canonicalizer {
*/
public byte[] canonicalizeXPathNodeSet(Set<Node> xpathNodeSet)
throws CanonicalizationException {
- return this.canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet);
+ return canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet);
}
/**
@@ -295,7 +308,7 @@ public class Canonicalizer {
Set<Node> xpathNodeSet, String inclusiveNamespaces
) throws CanonicalizationException {
return
- this.canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet, inclusiveNamespaces);
+ canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet, inclusiveNamespaces);
}
/**
@@ -304,7 +317,7 @@ public class Canonicalizer {
* @param os
*/
public void setWriter(OutputStream os) {
- this.canonicalizerSpi.setWriter(os);
+ canonicalizerSpi.setWriter(os);
}
/**
@@ -313,23 +326,14 @@ public class Canonicalizer {
* @return the name of the implementing {@link CanonicalizerSpi} class
*/
public String getImplementingCanonicalizerClass() {
- return this.canonicalizerSpi.getClass().getName();
+ return canonicalizerSpi.getClass().getName();
}
/**
* Set the canonicalizer behaviour to not reset.
*/
public void notReset() {
- this.canonicalizerSpi.reset = false;
+ canonicalizerSpi.reset = false;
}
- /**
- * Method getImplementingClass
- *
- * @param URI
- * @return the name of the class that implements the given URI
- */
- private static Class<CanonicalizerSpi> getImplementingClass(String URI) {
- return (Class<CanonicalizerSpi>) canonicalizerHash.get(URI);
- }
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/CanonicalizerSpi.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/CanonicalizerSpi.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/CanonicalizerSpi.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/CanonicalizerSpi.java Fri Apr 15 15:47:34 2011
@@ -42,16 +42,13 @@ public abstract class CanonicalizerSpi {
/**
* Method canonicalize
*
- *
* @param inputBytes
* @return the c14n bytes.
*
- *
* @throws CanonicalizationException
* @throws java.io.IOException
* @throws javax.xml.parsers.ParserConfigurationException
* @throws org.xml.sax.SAXException
- *
*/
public byte[] engineCanonicalize(byte[] inputBytes)
throws javax.xml.parsers.ParserConfigurationException, java.io.IOException,
@@ -61,39 +58,13 @@ public abstract class CanonicalizerSpi {
InputSource in = new InputSource(bais);
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
- // needs to validate for ID attribute nomalization
+ // needs to validate for ID attribute normalization
dfactory.setNamespaceAware(true);
DocumentBuilder db = dfactory.newDocumentBuilder();
- /*
- * for some of the test vectors from the specification,
- * there has to be a validation parser for ID attributes, default
- * attribute values, NMTOKENS, etc.
- * Unfortunately, the test vectors do use different DTDs or
- * even no DTD. So Xerces 1.3.1 fires many warnings about using
- * ErrorHandlers.
- *
- * Text from the spec:
- *
- * The input octet stream MUST contain a well-formed XML document,
- * but the input need not be validated. However, the attribute
- * value normalization and entity reference resolution MUST be
- * performed in accordance with the behaviors of a validating
- * XML processor. As well, nodes for default attributes (declared
- * in the ATTLIST with an AttValue but not specified) are created
- * in each element. Thus, the declarations in the document type
- * declaration are used to help create the canonical form, even
- * though the document type declaration is not retained in the
- * canonical form.
- *
- */
-
- // ErrorHandler eh = new C14NErrorHandler();
- // db.setErrorHandler(eh);
Document document = db.parse(in);
- byte result[] = this.engineCanonicalizeSubTree(document);
- return result;
+ return this.engineCanonicalizeSubTree(document);
}
/**
@@ -125,13 +96,15 @@ public abstract class CanonicalizerSpi {
);
}
- /** Returns the URI of this engine.
+ /**
+ * Returns the URI of this engine.
* @return the URI
*/
public abstract String engineGetURI();
- /** Returns the URI if include comments
- * @return true if include.
+ /**
+ * Returns true if comments are included
+ * @return true if comments are included
*/
public abstract boolean engineGetIncludeComments();
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer11.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer11.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer11.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer11.java Fri Apr 15 15:47:34 2011
@@ -52,13 +52,15 @@ import org.apache.xml.security.utils.XML
*/
public abstract class Canonicalizer11 extends CanonicalizerBase {
- static final String XMLNS_URI = Constants.NamespaceSpecNS;
- static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
-
- protected static org.apache.commons.logging.Log log =
+ private static final String XMLNS_URI = Constants.NamespaceSpecNS;
+ private static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
+ private static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(Canonicalizer11.class);
+
+ private boolean firstCall = true;
+ private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
- static class XmlAttrStack {
+ private static class XmlAttrStack {
static class XmlsStackElement {
int level;
boolean rendered = false;
@@ -176,11 +178,8 @@ public abstract class Canonicalizer11 ex
}
};
- XmlAttrStack xmlattrStack = new XmlAttrStack();
+ private XmlAttrStack xmlattrStack = new XmlAttrStack();
- boolean firstCall = true;
- final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
-
/**
* Constructor Canonicalizer11
*
@@ -205,7 +204,7 @@ public abstract class Canonicalizer11 ex
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
- Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
+ protected Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
throws CanonicalizationException {
if (!E.hasAttributes() && !firstCall) {
return null;
@@ -274,7 +273,7 @@ public abstract class Canonicalizer11 ex
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
- Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
+ protected Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be output
xmlattrStack.push(ns.getLevel());
@@ -404,7 +403,7 @@ public abstract class Canonicalizer11 ex
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
- void circumventBugIfNeeded(XMLSignatureInput input)
+ protected void circumventBugIfNeeded(XMLSignatureInput input)
throws CanonicalizationException, ParserConfigurationException,
IOException, SAXException {
if (!input.isNeedsToBeExpanded()) {
@@ -419,7 +418,7 @@ public abstract class Canonicalizer11 ex
XMLUtils.circumventBug2650(doc);
}
- void handleParent(Element e, NameSpaceSymbTable ns) {
+ protected void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes()) {
return;
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315.java Fri Apr 15 15:47:34 2011
@@ -48,13 +48,13 @@ import org.xml.sax.SAXException;
* @author Christian Geuer-Pollmann <ge...@apache.org>
*/
public abstract class Canonicalizer20010315 extends CanonicalizerBase {
- boolean firstCall = true;
- final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
+ private static final String XMLNS_URI = Constants.NamespaceSpecNS;
+ private static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
- static final String XMLNS_URI = Constants.NamespaceSpecNS;
- static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
+ private boolean firstCall = true;
+ private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
- static class XmlAttrStack {
+ private static class XmlAttrStack {
static class XmlsStackElement {
int level;
boolean rendered = false;
@@ -138,7 +138,7 @@ public abstract class Canonicalizer20010
}
- XmlAttrStack xmlattrStack = new XmlAttrStack();
+ private XmlAttrStack xmlattrStack = new XmlAttrStack();
/**
* Constructor Canonicalizer20010315
@@ -163,7 +163,7 @@ public abstract class Canonicalizer20010
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
- Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns )
+ protected Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns )
throws CanonicalizationException {
if (!E.hasAttributes() && !firstCall) {
return null;
@@ -229,7 +229,7 @@ public abstract class Canonicalizer20010
* @return the Attr[]s to be outputted
* @throws CanonicalizationException
*/
- Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
+ protected Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be outputted
xmlattrStack.push(ns.getLevel());
@@ -349,7 +349,7 @@ public abstract class Canonicalizer20010
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
- void circumventBugIfNeeded(XMLSignatureInput input)
+ protected void circumventBugIfNeeded(XMLSignatureInput input)
throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
if (!input.isNeedsToBeExpanded()) {
return;
@@ -363,7 +363,7 @@ public abstract class Canonicalizer20010
XMLUtils.circumventBug2650(doc);
}
- void handleParent(Element e, NameSpaceSymbTable ns) {
+ protected void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes()) {
return;
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/Canonicalizer20010315Excl.java Fri Apr 15 15:47:34 2011
@@ -54,15 +54,15 @@ import org.xml.sax.SAXException;
*/
public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
- private static final String XML_LANG_URI=Constants.XML_LANG_SPACE_SpecNS;
+ private static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
+ private static final String XMLNS_URI = Constants.NamespaceSpecNS;
/**
* This Set contains the names (Strings like "xmlns" or "xmlns:foo") of
* the inclusive namespaces.
*/
- TreeSet<String> inclusiveNSSet = new TreeSet<String>();
- static final String XMLNS_URI = Constants.NamespaceSpecNS;
- final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
+ private TreeSet<String> inclusiveNSSet = new TreeSet<String>();
+ private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
/**
* Constructor Canonicalizer20010315Excl
@@ -137,7 +137,7 @@ public abstract class Canonicalizer20010
* @throws CanonicalizationException
*/
@SuppressWarnings("unchecked")
- Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
+ protected Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be outputted
SortedSet<Attr> result = this.result;
@@ -195,7 +195,7 @@ public abstract class Canonicalizer20010
}
visiblyUtilized.add(prefix);
- // This can be optimezed by I don't have time
+ // This can be optimized by I don't have time
Iterator<String> it = visiblyUtilized.iterator();
while (it.hasNext()) {
String s = it.next();
@@ -230,7 +230,7 @@ public abstract class Canonicalizer20010
* @throws CanonicalizationException
*/
@SuppressWarnings("unchecked")
- final Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
+ protected final Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be outputted
SortedSet<Attr> result = this.result;
@@ -294,7 +294,7 @@ public abstract class Canonicalizer20010
}
if (ns.addMapping(NName, NNodeValue, N)) {
- // New definiton check if it is relative
+ // New definition check if it is relative
if (C14nHelper.namespaceIsRelative(NNodeValue)) {
Object exArgs[] =
{ E.getTagName(), NName, N.getNodeValue() };
@@ -339,7 +339,7 @@ public abstract class Canonicalizer20010
return result.iterator();
}
- void circumventBugIfNeeded(XMLSignatureInput input)
+ protected void circumventBugIfNeeded(XMLSignatureInput input)
throws CanonicalizationException, ParserConfigurationException,
IOException, SAXException {
if (!input.isNeedsToBeExpanded() || inclusiveNSSet.isEmpty()) {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java Fri Apr 15 15:47:34 2011
@@ -52,6 +52,12 @@ import org.xml.sax.SAXException;
* @author Christian Geuer-Pollmann <ge...@apache.org>
*/
public abstract class CanonicalizerBase extends CanonicalizerSpi {
+ public static final String XML = "xml";
+ public static final String XMLNS = "xmlns";
+
+ protected static final AttrCompare COMPARE = new AttrCompare();
+ protected static final Attr nullNode;
+
private static final byte[] END_PI = {'?','>'};
private static final byte[] BEGIN_PI = {'<','?'};
private static final byte[] END_COMM = {'-','-','>'};
@@ -64,18 +70,13 @@ public abstract class CanonicalizerBase
private static final byte[] LT = {'&','l','t',';'};
private static final byte[] END_TAG = {'<','/'};
private static final byte[] AMP = {'&','a','m','p',';'};
+ private static final byte[] equalsStr = {'=','\"'};
+ private static final int NODE_BEFORE_DOCUMENT_ELEMENT = -1;
+ private static final int NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT = 0;
+ private static final int NODE_AFTER_DOCUMENT_ELEMENT = 1;
- static final AttrCompare COMPARE = new AttrCompare();
- static final String XML = "xml";
- static final String XMLNS = "xmlns";
- static final byte[] equalsStr = {'=','\"'};
- 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 {
+ // The null xmlns definiton.
try {
nullNode = DocumentBuilderFactory.newInstance().
newDocumentBuilder().newDocument().createAttributeNS(Constants.NamespaceSpecNS, XMLNS);
@@ -85,16 +86,16 @@ public abstract class CanonicalizerBase
}
}
- List<NodeFilter> nodeFilter;
+ private List<NodeFilter> nodeFilter;
- boolean includeComments;
- Set<Node> xpathNodeSet = null;
+ private boolean includeComments;
+ private Set<Node> xpathNodeSet = null;
/**
- * The node to be skiped/excluded from the DOM tree
+ * The node to be skipped/excluded from the DOM tree
* in subtree canonicalizations.
*/
- Node excludeNode =null;
- OutputStream writer = new ByteArrayOutputStream();
+ private Node excludeNode =null;
+ private OutputStream writer = new ByteArrayOutputStream();
/**
* Constructor CanonicalizerBase
@@ -184,7 +185,7 @@ public abstract class CanonicalizerBase
* @return The canonicalize stream.
* @throws CanonicalizationException
*/
- byte[] engineCanonicalizeSubTree(Node rootNode, Node excludeNode)
+ protected byte[] engineCanonicalizeSubTree(Node rootNode, Node excludeNode)
throws CanonicalizationException {
this.excludeNode = excludeNode;
try {
@@ -223,7 +224,7 @@ public abstract class CanonicalizerBase
* @throws CanonicalizationException
* @throws IOException
*/
- final void canonicalizeSubTree(
+ protected final void canonicalizeSubTree(
Node currentNode, NameSpaceSymbTable ns, Node endnode, int documentLevel
) throws CanonicalizationException, IOException {
if (isVisibleInt(currentNode) == -1) {
@@ -330,7 +331,7 @@ public abstract class CanonicalizerBase
}
- private byte[] engineCanonicalizeXPathNodeSetInternal(Node doc)
+ private byte[] engineCanonicalizeXPathNodeSetInternal(Node doc)
throws CanonicalizationException {
try {
this.canonicalizeXPathNodeSet(doc, doc);
@@ -359,15 +360,16 @@ public abstract class CanonicalizerBase
* @throws CanonicalizationException
* @throws IOException
*/
- final void canonicalizeXPathNodeSet(Node currentNode, Node endnode)
+ protected final void canonicalizeXPathNodeSet(Node currentNode, Node endnode)
throws CanonicalizationException, IOException {
if (isVisibleInt(currentNode) == -1) {
return;
}
boolean currentNodeIsVisible = false;
NameSpaceSymbTable ns = new NameSpaceSymbTable();
- if (currentNode != null && Node.ELEMENT_NODE == currentNode.getNodeType())
+ if (currentNode != null && Node.ELEMENT_NODE == currentNode.getNodeType()) {
getParentNameSpaces((Element)currentNode, ns);
+ }
Node sibling = null;
Node parentNode = null;
OutputStream writer = this.writer;
@@ -499,7 +501,7 @@ public abstract class CanonicalizerBase
} while(true);
}
- int isVisibleDO(Node currentNode, int level) {
+ protected int isVisibleDO(Node currentNode, int level) {
if (nodeFilter != null) {
Iterator<NodeFilter> it = nodeFilter.iterator();
while (it.hasNext()) {
@@ -515,7 +517,7 @@ public abstract class CanonicalizerBase
return 1;
}
- int isVisibleInt(Node currentNode) {
+ protected int isVisibleInt(Node currentNode) {
if (nodeFilter != null) {
Iterator<NodeFilter> it = nodeFilter.iterator();
while (it.hasNext()) {
@@ -532,8 +534,8 @@ public abstract class CanonicalizerBase
return 1;
}
- boolean isVisible(Node currentNode) {
- if (nodeFilter!=null) {
+ protected boolean isVisible(Node currentNode) {
+ if (nodeFilter != null) {
Iterator<NodeFilter> it = nodeFilter.iterator();
while (it.hasNext()) {
if (it.next().isNodeInclude(currentNode) != 1) {
@@ -547,7 +549,7 @@ public abstract class CanonicalizerBase
return true;
}
- void handleParent(Element e, NameSpaceSymbTable ns) {
+ protected void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes()) {
return;
}
@@ -574,7 +576,7 @@ public abstract class CanonicalizerBase
* @param el
* @param ns
*/
- final void getParentNameSpaces(Element el, NameSpaceSymbTable ns) {
+ protected final void getParentNameSpaces(Element el, NameSpaceSymbTable ns) {
List<Element> parents = new ArrayList<Element>(10);
Node n1 = el.getParentNode();
if (n1 == null || Node.ELEMENT_NODE != n1.getNodeType()) {
@@ -611,7 +613,7 @@ public abstract class CanonicalizerBase
* @return the attributes nodes to output.
* @throws CanonicalizationException
*/
- abstract Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns )
+ abstract Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
throws CanonicalizationException;
/**
@@ -647,7 +649,7 @@ public abstract class CanonicalizerBase
* @param writer
* @throws IOException
*/
- static final void outputAttrToWriter(
+ protected static final void outputAttrToWriter(
final String name, final String value,
final OutputStream writer, final Map<String, byte[]> cache
) throws IOException {
@@ -707,7 +709,7 @@ public abstract class CanonicalizerBase
* @param writer where to write the things
* @throws IOException
*/
- static final void outputPItoWriter(
+ protected static final void outputPItoWriter(
ProcessingInstruction currentPI, OutputStream writer, int position
) throws IOException {
if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
@@ -761,7 +763,7 @@ public abstract class CanonicalizerBase
* @param writer writer where to write the things
* @throws IOException
*/
- static final void outputCommentToWriter(
+ protected static final void outputCommentToWriter(
Comment currentComment, OutputStream writer, int position
) throws IOException {
if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
@@ -798,7 +800,7 @@ public abstract class CanonicalizerBase
* @param writer writer where to write the things
* @throws IOException
*/
- static final void outputTextToWriter(
+ protected static final void outputTextToWriter(
final String text, final OutputStream writer
) throws IOException {
final int length = text.length();
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/NameSpaceSymbTable.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/NameSpaceSymbTable.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/NameSpaceSymbTable.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/NameSpaceSymbTable.java Fri Apr 15 15:47:34 2011
@@ -33,8 +33,9 @@ import org.w3c.dom.Node;
*/
public class NameSpaceSymbTable {
- static final String XMLNS = "xmlns";
- static final SymbMap initialMap = new SymbMap();
+ private static final String XMLNS = "xmlns";
+ private static final SymbMap initialMap = new SymbMap();
+
static {
NameSpaceSymbEntry ne = new NameSpaceSymbEntry("", null, true, XMLNS);
ne.lastrendered = "";
@@ -42,14 +43,14 @@ public class NameSpaceSymbTable {
}
/**The map betwen prefix-> entry table. */
- SymbMap symb;
+ private SymbMap symb;
/**The level of nameSpaces (for Inclusive visibility).*/
- int nameSpaces = 0;
+ private int nameSpaces = 0;
/**The stacks for removing the definitions when doing pop.*/
- List<SymbMap> level;
- boolean cloned = true;
+ private List<SymbMap> level;
+ private boolean cloned = true;
/**
* Default constractor
@@ -65,7 +66,7 @@ public class NameSpaceSymbTable {
* For Inclusive rendering
* @param result the list where to fill the unrendered xmlns definitions.
**/
- public void getUnrenderedNodes(Collection<Attr> result) {
+ public void getUnrenderedNodes(Collection<Attr> result) {
Iterator<NameSpaceSymbEntry> it = symb.entrySet().iterator();
while (it.hasNext()) {
NameSpaceSymbEntry n = it.next();
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/params/InclusiveNamespaces.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/params/InclusiveNamespaces.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/params/InclusiveNamespaces.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/params/InclusiveNamespaces.java Fri Apr 15 15:47:34 2011
@@ -122,7 +122,6 @@ public class InclusiveNamespaces extends
* @return A set to string
*/
public static SortedSet<String> prefixStr2Set(String inclusiveNamespaces) {
-
SortedSet<String> prefixes = new TreeSet<String>();
if ((inclusiveNamespaces == null) || (inclusiveNamespaces.length() == 0)) {
@@ -135,7 +134,7 @@ public class InclusiveNamespaces extends
String prefix = st.nextToken();
if (prefix.equals("#default")) {
- prefixes.add("xmlns" );
+ prefixes.add("xmlns");
} else {
prefixes.add(prefix);
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java?rev=1092749&r1=1092748&r2=1092749&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java Fri Apr 15 15:47:34 2011
@@ -21,8 +21,10 @@ import java.io.IOException;
import java.io.OutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import org.apache.xml.security.c14n.CanonicalizationException;
@@ -43,14 +45,13 @@ import org.w3c.dom.Text;
*/
public class XMLUtils {
- @SuppressWarnings("unchecked")
- private static boolean ignoreLineBreaks = ((Boolean)
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
+ private static boolean ignoreLineBreaks =
+ AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
return Boolean.valueOf(Boolean.getBoolean
("org.apache.xml.security.ignoreLineBreaks"));
}
- })).booleanValue();
+ }).booleanValue();
private static volatile String dsPrefix = "ds";
private static volatile String xencPrefix = "xenc";
@@ -99,7 +100,7 @@ public class XMLUtils {
getSetRec(rootNode, result, exclude, com);
}
- static final void getSetRec(final Node rootNode, final Set<Node> result,
+ private static void getSetRec(final Node rootNode, final Set<Node> result,
final Node exclude, final boolean com) {
if (rootNode == exclude) {
return;
@@ -109,7 +110,7 @@ public class XMLUtils {
result.add(rootNode);
Element el = (Element)rootNode;
if (el.hasAttributes()) {
- NamedNodeMap nl = ((Element)rootNode).getAttributes();
+ NamedNodeMap nl = el.getAttributes();
for (int i = 0;i < nl.getLength(); i++) {
result.add(nl.item(i));
}
@@ -162,8 +163,7 @@ public class XMLUtils {
* @param os the {@link OutputStream}
* @param addPreamble
*/
- public static void outputDOM(Node contextNode, OutputStream os,
- boolean addPreamble) {
+ public static void outputDOM(Node contextNode, OutputStream os, boolean addPreamble) {
try {
if (addPreamble) {
os.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes());
@@ -194,24 +194,19 @@ public class XMLUtils {
* @param os
*/
public static void outputDOMc14nWithComments(Node contextNode, OutputStream os) {
-
try {
os.write(Canonicalizer.getInstance(
Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS).canonicalizeSubtree(contextNode)
);
} catch (IOException ex) {
-
// throw new RuntimeException(ex.getMessage());
} catch (InvalidCanonicalizerException ex) {
-
// throw new RuntimeException(ex.getMessage());
} catch (CanonicalizationException ex) {
-
// throw new RuntimeException(ex.getMessage());
}
}
-
/**
* Method getFullTextChildrenFromElement
*
@@ -219,7 +214,6 @@ public class XMLUtils {
* @return the string of children
*/
public static String getFullTextChildrenFromElement(Element element) {
-
StringBuilder sb = new StringBuilder();
NodeList children = element.getChildNodes();
int iMax = children.getLength();
@@ -228,7 +222,7 @@ public class XMLUtils {
Node curr = children.item(i);
if (curr.getNodeType() == Node.TEXT_NODE) {
- sb.append(((Text) curr).getData());
+ sb.append(((Text)curr).getData());
}
}
@@ -332,7 +326,7 @@ public class XMLUtils {
}
/**
- * This method returns the first non-null owner document of the Node's in this Set.
+ * This method returns the first non-null owner document of the Nodes in this Set.
* This method is necessary because it <I>always</I> returns a
* {@link Document}. {@link Node#getOwnerDocument} returns <CODE>null</CODE>
* if the {@link Node} is a {@link Document}.
@@ -342,9 +336,7 @@ public class XMLUtils {
*/
public static Document getOwnerDocument(Set<Node> xpathNodeSet) {
NullPointerException npe = null;
- Iterator<Node> iterator = xpathNodeSet.iterator();
- while(iterator.hasNext()) {
- Node node = iterator.next();
+ for (Node node : xpathNodeSet) {
int nodeType = node.getNodeType();
if (nodeType == Node.DOCUMENT_NODE) {
return (Document) node;
@@ -357,8 +349,8 @@ public class XMLUtils {
} catch (NullPointerException e) {
npe = e;
}
-
}
+
throw new NullPointerException(I18n.translate("endorsed.jdk1.4.0")
+ " Original message was \""
+ (npe == null ? "" : npe.getMessage()) + "\"");
@@ -373,7 +365,6 @@ public class XMLUtils {
* @return the element.
*/
public static Element createDSctx(Document doc, String prefix, String namespace) {
-
if ((prefix == null) || (prefix.trim().length() == 0)) {
throw new IllegalArgumentException("You must supply a prefix");
}
@@ -417,7 +408,6 @@ public class XMLUtils {
* @return the set with the nodelist
*/
public static Set<Node> convertNodelistToSet(NodeList xpathNodeSet) {
-
if (xpathNodeSet == null) {
return new HashSet<Node>();
}
@@ -432,7 +422,6 @@ public class XMLUtils {
return set;
}
-
/**
* This method spreads all namespace attributes in a DOM document to their
* children. This is needed because the XML Signature XPath transform
@@ -549,9 +538,8 @@ public class XMLUtils {
* @param number
* @return nodes with the constrain
*/
-
public static Element selectXencNode(Node sibling, String nodeName, int number) {
- while (sibling!=null) {
+ while (sibling != null) {
if (EncryptionConstants.EncryptionSpecNS.equals(sibling.getNamespaceURI())
&& sibling.getLocalName().equals(nodeName)) {
if (number == 0){
@@ -609,7 +597,7 @@ public class XMLUtils {
* @param number
* @return nodes with the constrain
*/
- public static Element selectNode(Node sibling, String uri,String nodeName, int number) {
+ public static Element selectNode(Node sibling, String uri, String nodeName, int number) {
while (sibling != null) {
if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
&& sibling.getLocalName().equals(nodeName)) {
@@ -639,27 +627,15 @@ public class XMLUtils {
* @return nodes with the constraint
*/
public static Element[] selectNodes(Node sibling, String uri, String nodeName) {
- int size = 20;
- Element[] a = new Element[size];
- int curr = 0;
- //List list=new ArrayList();
+ List<Element> list = new ArrayList<Element>();
while (sibling != null) {
if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
&& sibling.getLocalName().equals(nodeName)) {
- a[curr++] = (Element)sibling;
- if (size <= curr) {
- int cursize = size<<2;
- Element []cp = new Element[cursize];
- System.arraycopy(a, 0, cp, 0, size);
- a = cp;
- size = cursize;
- }
+ list.add((Element)sibling);
}
sibling = sibling.getNextSibling();
}
- Element[] af = new Element[curr];
- System.arraycopy(a, 0, af, 0, curr);
- return af;
+ return list.toArray(new Element[list.size()]);
}
/**
@@ -690,7 +666,6 @@ public class XMLUtils {
* @return true if the node is descendant
*/
static public boolean isDescendantOrSelf(Node ctx, Node descendantOrSelf) {
-
if (ctx == descendantOrSelf) {
return true;
}