You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ru...@apache.org on 2008/08/27 03:06:55 UTC
svn commit: r689316 [1/3] - in
/webservices/commons/trunk/modules/axiom/modules/axiom-c14n: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/axiom/ src/main/java/org/apache/axiom/c14n/
src/main/java...
Author: ruchithf
Date: Tue Aug 26 18:06:53 2008
New Revision: 689316
URL: http://svn.apache.org/viewvc?rev=689316&view=rev
Log:
Adding Saliya's code from WSCOMMONS-218, Thanks Saliya
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/Canonicalizer.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/CanonicalizerSpi.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/AlgorithmAlreadyRegisteredException.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/C14NException.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/CanonicalizationException.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/InvalidCanonicalizerException.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/AttrCompare.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/C14nHelper.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315Excl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclOmitComments.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclWithComments.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315OmitComments.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315WithComments.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/CanonicalizerBase.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/NameSpaceSymbTable.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/UtfHelper.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/AttrImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/CommentImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DoctypeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DocumentImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NamedNodeMapImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeListImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ProcessingInstructionImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/TextImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/factory/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/factory/WrapperFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Attr.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Comment.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Doctype.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Document.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Element.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/NamedNodeMap.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Node.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/NodeList.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/ProcessingInstruction.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Text.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/utils/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/utils/Constants.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/utils/PropLoader.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/utils/UnsyncByteArrayOutputStream.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/resources/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/resources/META-INF/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/resources/META-INF/exceptions.properties
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/AllC14NTests.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/DataParser.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/ImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/WrapperTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/impl/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/impl/AbstractCanonicalizerTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/impl/Canonicalizer20010315OmitCommentTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/impl/Canonicalizer20010315WithCommentTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/omwrapper/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/omwrapper/AttrImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/omwrapper/CommentImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/omwrapper/DocumentImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/omwrapper/ElementImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/omwrapper/NamedNodeMapImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/omwrapper/NodeListImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/java/org/apache/axiom/c14n/omwrapper/TextImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/resources/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/resources/META-INF/
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/resources/META-INF/sample1.xml
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/resources/META-INF/sample2.xml
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/resources/META-INF/sample3.xml
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/resources/META-INF/sample4.xml
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/resources/META-INF/sample5.xml
webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/test/resources/META-INF/sample6.xml
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/Canonicalizer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/Canonicalizer.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/Canonicalizer.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/Canonicalizer.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n;
+
+
+import org.apache.axiom.c14n.exceptions.AlgorithmAlreadyRegisteredException;
+import org.apache.axiom.c14n.exceptions.CanonicalizationException;
+import org.apache.axiom.c14n.exceptions.InvalidCanonicalizerException;
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.om.OMElement;
+
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class Canonicalizer {
+
+ /**
+ * The URL defined in XML-SEC Rec for inclusive org.apache.axiom.c14n.impl <b>without</b> comments.
+ */
+ public static final String ALGO_ID_C14N_OMIT_COMMENTS = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
+ /**
+ * The URL defined in XML-SEC Rec for inclusive org.apache.axiom.c14n.impl <b>with</b> comments.
+ */
+ public static final String ALGO_ID_C14N_WITH_COMMENTS = ALGO_ID_C14N_OMIT_COMMENTS + "#WithComments";
+ /**
+ * The URL defined in XML-SEC Rec for exclusive org.apache.axiom.c14n.impl <b>without</b> comments.
+ */
+ public static final String ALGO_ID_C14N_EXCL_OMIT_COMMENTS = "http://www.w3.org/2001/10/xml-exc-c14n#";
+ /**
+ * The URL defined in XML-SEC Rec for exclusive org.apache.axiom.c14n.impl <b>with</b> comments.
+ */
+ public static final String ALGO_ID_C14N_EXCL_WITH_COMMENTS = ALGO_ID_C14N_EXCL_OMIT_COMMENTS + "WithComments";
+
+ static boolean _alreadyInitialized = false;
+ static Map _canonicalizerHash = null;
+
+ protected CanonicalizerSpi canonicalizerSpi = null;
+
+ /**
+ * Method init
+ */
+ public static synchronized void init() {
+
+ if (!Canonicalizer._alreadyInitialized) {
+ Canonicalizer._canonicalizerHash = new HashMap(10);
+ Canonicalizer._alreadyInitialized = true;
+ }
+ }
+
+ /**
+ * Constructor Canonicalizer
+ *
+ * @param algorithmURI
+ * @throws org.apache.axiom.c14n.exceptions.InvalidCanonicalizerException
+ *
+ */
+ private Canonicalizer(String algorithmURI)
+ throws InvalidCanonicalizerException {
+
+ try {
+ Class implementingClass = getImplementingClass(algorithmURI);
+ this.canonicalizerSpi = (CanonicalizerSpi) implementingClass.newInstance();
+ this.canonicalizerSpi.reset = true;
+ } catch (Exception e) {
+ Object exArgs[] = {algorithmURI};
+ throw new InvalidCanonicalizerException(
+ "c14n.Canonicalizer.UnknownCanonicalizer", exArgs);
+ }
+ }
+
+ /**
+ * Method getInstance
+ *
+ * @param algorithmURI
+ * @return an appropriate Canonicalizer instance
+ * @throws InvalidCanonicalizerException
+ */
+ public static synchronized final Canonicalizer getInstance(String algorithmURI)
+ throws InvalidCanonicalizerException {
+
+ Canonicalizer canonicalizer = new Canonicalizer(algorithmURI);
+
+ return canonicalizer;
+ }
+
+ /**
+ * Method register
+ *
+ * @param algorithmURI
+ * @param implementingClass
+ * @throws AlgorithmAlreadyRegisteredException
+ *
+ */
+ public static synchronized void register(String algorithmURI, String implementingClass)
+ throws AlgorithmAlreadyRegisteredException {
+
+ // check whether URI is already registered
+ Class registeredClass = getImplementingClass(algorithmURI);
+
+ if (registeredClass != null) {
+ Object exArgs[] = {algorithmURI, registeredClass};
+ throw new AlgorithmAlreadyRegisteredException(
+ "algorithm.alreadyRegistered", exArgs);
+ }
+
+ try {
+ _canonicalizerHash.put(algorithmURI, Class.forName(implementingClass));
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(implementingClass + " not found");
+ }
+ }
+
+ /**
+ * Method engineGetURI()
+ *
+ * @return the URI of the canonicalization method
+ */
+ public final String getURI() {
+ return this.canonicalizerSpi.engineGetURI();
+ }
+
+ /**
+ * Method engineGetIncludeComments
+ *
+ * @return true if comments are included or false otherwise
+ */
+ public boolean getIncludeComments() {
+ return this.canonicalizerSpi.engineGetIncludeComments();
+ }
+
+ /**
+ * Method canonicalize
+ *
+ * @param inputBytes
+ * @return the canonicalized array of bytes
+ * @throws CanonicalizationException
+ */
+ public byte[] canonicalize(byte[] inputBytes) throws CanonicalizationException {
+ return this.canonicalizerSpi.engineCanonicalize(inputBytes);
+ }
+
+ /**
+ * Canonicalizes the subtree rooted by <CODE>element</CODE>.
+ *
+ * @param element The element to canicalize
+ * @return the result of the org.apache.axiom.c14n.impl.
+ * @throws CanonicalizationException
+ */
+ public byte[] canonicalizeSubtree(OMElement element) throws CanonicalizationException {
+ return this.canonicalizerSpi.engineCanonicalizeSubTree(
+ new WrapperFactory().getNode(element));
+ }
+
+ /**
+ * Canonicalizes the subtree rooted by <CODE>element</CODE>.
+ *
+ * @param element
+ * @param inclusiveNamespaces
+ * @return the result of the org.apache.axiom.c14n.impl.
+ * @throws CanonicalizationException
+ */
+ public byte[] canonicalizeSubtree(OMElement element, String inclusiveNamespaces)
+ throws CanonicalizationException {
+ return this.canonicalizerSpi.engineCanonicalizeSubTree(new WrapperFactory().getNode(element),
+ inclusiveNamespaces);
+ }
+
+ /**
+ * Sets the writter where the cannocalization ends. ByteArrayOutputStream if
+ * none is setted.
+ *
+ * @param os
+ */
+ public void setWriter(OutputStream os) {
+ this.canonicalizerSpi.setWriter(os);
+ }
+
+ /**
+ * Method getImplementingCanonicalizerClss
+ *
+ * @return the name of the implementing {@link CanonicalizerSpi} class
+ */
+ public String getImplementingCanonicalizerClass() {
+ return this.canonicalizerSpi.getClass().getName();
+ }
+
+ /**
+ * Method getImplementingClass
+ *
+ * @param URI
+ * @return the class implementing the given URI
+ */
+ private static Class getImplementingClass(String URI) {
+ return (Class) _canonicalizerHash.get(URI);
+ }
+
+ /**
+ * Set the canonicalizator behaviour to not reset.
+ */
+ public void notReset() {
+ this.canonicalizerSpi.reset = false;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/CanonicalizerSpi.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/CanonicalizerSpi.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/CanonicalizerSpi.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/CanonicalizerSpi.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,76 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n;
+
+import org.apache.axiom.c14n.exceptions.CanonicalizationException;
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayInputStream;
+import java.io.OutputStream;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public abstract class CanonicalizerSpi {
+ protected boolean reset = false;
+
+ /**
+ * Method engineGetURI()
+ *
+ * @return the URI of the canonicalization method
+ */
+ public abstract String engineGetURI();
+
+ /**
+ * Method engineGetIncludeComments
+ *
+ * @return true if comments are included or false otherwise
+ */
+ public abstract boolean engineGetIncludeComments();
+
+ /**
+ * Method setWriter
+ * @param os
+ */
+ public abstract void setWriter(OutputStream os);
+
+ public byte[] engineCanonicalize(byte[] inputBytes) throws CanonicalizationException {
+ ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes);
+ StAXOMBuilder builder = null;
+ try {
+ builder = new StAXOMBuilder(bais);
+ } catch (XMLStreamException e) {
+ throw new CanonicalizationException(e);
+ }
+ byte [] result = this.engineCanonicalizeSubTree(
+ new WrapperFactory().getNode(builder.getDocument()));
+ return result;
+ }
+
+ public abstract byte[] engineCanonicalizeSubTree(Node node)
+ throws CanonicalizationException;
+
+ public abstract byte[] engineCanonicalizeSubTree(Node node, String inclusiveNamespaces)
+ throws CanonicalizationException;
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/AlgorithmAlreadyRegisteredException.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/AlgorithmAlreadyRegisteredException.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/AlgorithmAlreadyRegisteredException.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/AlgorithmAlreadyRegisteredException.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.exceptions;
+
+/**
+ * class AlgorithmAlreadyRegisteredException
+ *
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class AlgorithmAlreadyRegisteredException extends C14NException{
+ public AlgorithmAlreadyRegisteredException() {
+ }
+
+ public AlgorithmAlreadyRegisteredException(String msg){
+ super(msg);
+ }
+
+ public AlgorithmAlreadyRegisteredException(String msg, Object[] exArgs){
+ super(msg, exArgs);
+ }
+
+ public AlgorithmAlreadyRegisteredException(Exception e) {
+ super(e);
+ }
+
+ public AlgorithmAlreadyRegisteredException(String msg, Exception e) {
+ super(msg, e);
+ }
+
+ public AlgorithmAlreadyRegisteredException(String msg, Object [] exArgs, Exception e) {
+ super(msg, exArgs, e);
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/C14NException.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/C14NException.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/C14NException.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/C14NException.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,136 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.exceptions;
+
+import org.apache.axiom.c14n.utils.PropLoader;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.text.MessageFormat;
+
+/**
+ * class C14NException is the base class of all the exception classes
+ * used in org.apache.axiom.c14n
+ *
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class C14NException extends Exception {
+ public static final String baseName = "exceptions";
+ protected Exception e = null;
+
+ protected String msgID;
+
+ public C14NException() {
+ super("Missing message ID");
+ this.e = null;
+ this.msgID = null;
+ }
+
+ public C14NException(String msgID) {
+ super(PropLoader.getExceptionProperty(msgID, baseName));
+ this.e = null;
+ this.msgID = msgID;
+ }
+
+ public C14NException(String msgID, Object[] exArgs) {
+ super(MessageFormat.format(
+ PropLoader.getExceptionProperty(msgID, baseName), exArgs));
+ this.e = null;
+ this.msgID = msgID;
+ }
+
+ public C14NException(Exception e) {
+ super(e.getMessage());
+ this.e = e;
+ this.msgID = null;
+ }
+
+ public C14NException(String msgID, Exception e) {
+ super(MessageFormat.format(
+ PropLoader.getExceptionProperty(msgID, baseName), new Object[]{e.getMessage()}));
+ this.e = e;
+ this.msgID = msgID;
+ }
+
+ public C14NException(String msgID, Object [] exArgs, Exception e) {
+ super(MessageFormat.format(
+ PropLoader.getExceptionProperty(msgID, baseName), exArgs));
+ this.e = e;
+ this.msgID = msgID;
+ }
+
+ public String getMsgID() {
+ if (msgID == null) {
+ return "Missing message ID";
+ }
+ return msgID;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public String toString() {
+
+ String s = this.getClass().getName();
+ String message = super.getLocalizedMessage();
+
+ if (message != null) {
+ message = s + ": " + message;
+ } else {
+ message = s;
+ }
+
+ if (e != null) {
+ message = message + "\nOriginal Exception was "
+ + e.toString();
+ }
+ return message;
+ }
+
+ public void printStackTrace() {
+ synchronized (System.err) {
+ super.printStackTrace(System.err);
+ if (this.e != null) {
+ this.e.printStackTrace(System.err);
+ }
+ }
+ }
+
+ public void printStackTrace(PrintWriter printwriter) {
+ super.printStackTrace(printwriter);
+ if (this.e != null) {
+ this.e.printStackTrace(printwriter);
+ }
+ }
+
+ public void printStackTrace(PrintStream printstream) {
+ super.printStackTrace(printstream);
+ if (this.e != null) {
+ this.e.printStackTrace(printstream);
+ }
+ }
+
+ public Exception getOriginalException() {
+ return e;
+ }
+}
+
+
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/CanonicalizationException.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/CanonicalizationException.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/CanonicalizationException.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/CanonicalizationException.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.exceptions;
+
+/**
+ * class CanonicalizationException
+ *
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class CanonicalizationException extends C14NException{
+ public CanonicalizationException() {
+ }
+
+ public CanonicalizationException(String msg){
+ super(msg);
+ }
+
+ public CanonicalizationException(String msg, Object[] exArgs){
+ super(msg, exArgs);
+ }
+
+ public CanonicalizationException(Exception e) {
+ super(e);
+ }
+
+ public CanonicalizationException(String msg, Exception e) {
+ super(msg, e);
+ }
+
+ public CanonicalizationException(String msg, Object [] exArgs, Exception e) {
+ super(msg, exArgs, e);
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/InvalidCanonicalizerException.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/InvalidCanonicalizerException.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/InvalidCanonicalizerException.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/exceptions/InvalidCanonicalizerException.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.exceptions;
+
+/**
+ * class InvalidCanonicalizerException
+ *
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class InvalidCanonicalizerException extends C14NException {
+ public InvalidCanonicalizerException() {
+ }
+
+ public InvalidCanonicalizerException(String msg){
+ super(msg);
+ }
+
+ public InvalidCanonicalizerException(String msg, Object[] exArgs){
+ super(msg, exArgs);
+ }
+
+ public InvalidCanonicalizerException(Exception e) {
+ super(e);
+ }
+
+ public InvalidCanonicalizerException(String msg, Exception e) {
+ super(msg, e);
+ }
+
+ public InvalidCanonicalizerException(String msg, Object [] exArgs, Exception e) {
+ super(msg, exArgs, e);
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/AttrCompare.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/AttrCompare.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/AttrCompare.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/AttrCompare.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.helpers;
+
+import org.apache.axiom.c14n.omwrapper.interfaces.Attr;
+import org.apache.axiom.c14n.utils.Constants;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Compares two attributes based on the C14n specification.
+ * <p/>
+ * <UL>
+ * <LI>Namespace nodes have a lesser document order position than attribute
+ * nodes.
+ * <LI> An element's namespace nodes are sorted lexicographically by
+ * local name (the default namespace node, if one exists, has no
+ * local name and is therefore lexicographically least).
+ * <LI> An element's attribute nodes are sorted lexicographically with
+ * namespace URI as the primary key and local name as the secondary
+ * key (an empty namespace URI is lexicographically least).
+ * </UL>
+ *
+ * @author Christian Geuer-Pollmann <ge...@apache.org>
+ *
+ * modified to work with Axiom wrapper by Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class AttrCompare implements Comparator, Serializable {
+
+ private final static long serialVersionUID = -7113259629930576230L;
+ private final static int ATTR0_BEFORE_ATTR1 = -1;
+ private final static int ATTR1_BEFORE_ATTR0 = 1;
+ private final static String XMLNS = Constants.NamespaceSpecNS;
+
+ /**
+ * Compares two attributes based on the C14n specification.
+ * <p/>
+ * <UL>
+ * <LI>Namespace nodes have a lesser document order position than
+ * attribute nodes.
+ * <LI> An element's namespace nodes are sorted lexicographically by
+ * local name (the default namespace node, if one exists, has no
+ * local name and is therefore lexicographically least).
+ * <LI> An element's attribute nodes are sorted lexicographically with
+ * namespace URI as the primary key and local name as the secondary
+ * key (an empty namespace URI is lexicographically least).
+ * </UL>
+ *
+ * @param obj0 casted org.apache.axiom.c14n.omwrapper.interfaces.Attr
+ * @param obj1 casted org.apache.axiom.c14n.omwrapper.interfaces.Attr
+ * @return returns a negative integer, zero, or a positive integer as
+ * obj0 is less than, equal to, or greater than obj1
+ */
+ public int compare(Object obj0, Object obj1) {
+
+ Attr attr0 = (Attr) obj0;
+ Attr attr1 = (Attr) obj1;
+ String namespaceURI0 = attr0.getNamespaceURI();
+ String namespaceURI1 = attr1.getNamespaceURI();
+
+ boolean isNamespaceAttr0 = XMLNS == namespaceURI0;
+ boolean isNamespaceAttr1 = XMLNS == namespaceURI1;
+
+ if (isNamespaceAttr0) {
+ if (isNamespaceAttr1) {
+ // both are namespaces
+ String localname0 = attr0.getLocalName();
+ String localname1 = attr1.getLocalName();
+
+ if (localname0.equals("xmlns")) {
+ localname0 = "";
+ }
+
+ if (localname1.equals("xmlns")) {
+ localname1 = "";
+ }
+
+ return localname0.compareTo(localname1);
+ }
+ // attr0 is a namespace, attr1 is not
+ return ATTR0_BEFORE_ATTR1;
+ }
+
+ if (isNamespaceAttr1) {
+ // attr1 is a namespace, attr0 is not
+ return ATTR1_BEFORE_ATTR0;
+ }
+
+ // none is a namespace
+ if (namespaceURI0 == null) {
+ if (namespaceURI1 == null) {
+ String name0 = attr0.getName();
+ String name1 = attr1.getName();
+ return name0.compareTo(name1);
+ }
+ return ATTR0_BEFORE_ATTR1;
+ }
+
+ if (namespaceURI1 == null) {
+ return ATTR1_BEFORE_ATTR0;
+ }
+
+ int a = namespaceURI0.compareTo(namespaceURI1);
+ if (a != 0) {
+ return a;
+ }
+
+ return (attr0.getLocalName()).compareTo(attr1.getLocalName());
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/C14nHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/C14nHelper.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/C14nHelper.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/helpers/C14nHelper.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.helpers;
+
+import org.apache.axiom.c14n.exceptions.CanonicalizationException;
+import org.apache.axiom.c14n.omwrapper.interfaces.Attr;
+import org.apache.axiom.c14n.omwrapper.interfaces.Element;
+import org.apache.axiom.c14n.omwrapper.interfaces.NamedNodeMap;
+
+/**
+ * @author Christian Geuer-Pollmann <ge...@apache.org>
+ *
+ * modified to work with Axiom wrapper by Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class C14nHelper {
+
+ /**
+ * Constructor C14nHelper
+ */
+ private C14nHelper() {
+
+ // don't allow instantiation
+ }
+
+ /**
+ * Method namespaceIsRelative
+ *
+ * @param namespace
+ * @return true if the given namespace is relative.
+ */
+ public static boolean namespaceIsRelative(Attr namespace) {
+ return !namespaceIsAbsolute(namespace);
+ }
+
+ /**
+ * Method namespaceIsRelative
+ *
+ * @param namespaceValue
+ * @return true if the given namespace is relative.
+ */
+ public static boolean namespaceIsRelative(String namespaceValue) {
+ return !namespaceIsAbsolute(namespaceValue);
+ }
+
+ /**
+ * Method namespaceIsAbsolute
+ *
+ * @param namespace
+ * @return true if the given namespace is absolute.
+ */
+ public static boolean namespaceIsAbsolute(Attr namespace) {
+ return namespaceIsAbsolute(namespace.getValue());
+ }
+
+ /**
+ * Method namespaceIsAbsolute
+ *
+ * @param namespaceValue
+ * @return true if the given namespace is absolute.
+ */
+ public static boolean namespaceIsAbsolute(String namespaceValue) {
+
+ // assume empty namespaces are absolute
+ if (namespaceValue.length() == 0) {
+ return true;
+ }
+ return namespaceValue.indexOf(':') > 0;
+ }
+
+ /**
+ * This method throws an exception if the Attribute value contains
+ * a relative URI.
+ *
+ * @param attr
+ * @throws org.apache.axiom.c14n.exceptions.CanonicalizationException
+ */
+ public static void assertNotRelativeNS(Attr attr)
+ throws CanonicalizationException {
+
+ if (attr == null) {
+ return;
+ }
+
+ String nodeAttrName = attr.getNodeName();
+ boolean definesDefaultNS = nodeAttrName.equals("xmlns");
+ boolean definesNonDefaultNS = nodeAttrName.startsWith("xmlns:");
+
+ if (definesDefaultNS || definesNonDefaultNS) {
+ if (namespaceIsRelative(attr)) {
+ String parentName = attr.getOwnerElement().getTagName();
+ String attrValue = attr.getValue();
+ Object exArgs[] = {parentName, nodeAttrName, attrValue};
+
+ throw new CanonicalizationException(
+ "c14n.Canonicalizer.RelativeNamespace", exArgs);
+ }
+ }
+ }
+
+ /**
+ * This method throws a CanonicalizationException if the supplied Element
+ * contains any relative namespaces.
+ *
+ * @param ctxNode
+ * @throws CanonicalizationException
+ * @see C14nHelper#assertNotRelativeNS(Attr)
+ */
+ public static void checkForRelativeNamespace(Element ctxNode)
+ throws CanonicalizationException {
+
+ if (ctxNode != null) {
+ NamedNodeMap attributes = ctxNode.getAttributes();
+
+ for (int i = 0; i < attributes.getLength(); i++) {
+ C14nHelper.assertNotRelativeNS((Attr) attributes.item(i));
+ }
+ } else {
+ throw new CanonicalizationException(
+ "Called checkForRelativeNamespace() on null");
+ }
+ }
+}
+
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.impl;
+
+import org.apache.axiom.c14n.exceptions.CanonicalizationException;
+import org.apache.axiom.c14n.helpers.C14nHelper;
+import org.apache.axiom.c14n.omwrapper.interfaces.Attr;
+import org.apache.axiom.c14n.omwrapper.interfaces.Element;
+import org.apache.axiom.c14n.omwrapper.interfaces.NamedNodeMap;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.c14n.utils.Constants;
+
+import java.util.*;
+
+/**
+ * @author Christian Geuer-Pollmann <ge...@apache.org>
+ *
+ * modified to work with Axiom wrapper by Saliya Ekanayake (esaliya@gmail.com)
+ */
+public abstract class Canonicalizer20010315 extends CanonicalizerBase {
+ boolean firstCall = true;
+ final SortedSet result = new TreeSet(COMPARE);
+ static final String XMLNS_URI = Constants.NamespaceSpecNS;
+ static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
+
+ static class XmlAttrStack {
+ int currentLevel = 0;
+ int lastlevel = 0;
+ XmlsStackElement cur;
+
+ static class XmlsStackElement {
+ int level;
+ boolean rendered = false;
+ List nodes = new ArrayList();
+ }
+
+ ;
+ List levels = new ArrayList();
+
+ void push(int level) {
+ currentLevel = level;
+ if (currentLevel == -1)
+ return;
+ cur = null;
+ while (lastlevel > currentLevel) {
+ levels.remove(levels.size() - 1);
+ if (levels.size() == 0) {
+ lastlevel = 0;
+ return;
+ }
+ lastlevel = ((XmlsStackElement) levels.get(levels.size() - 1)).level;
+ }
+ }
+
+ void addXmlnsAttr(Attr n) {
+ if (cur == null) {
+ cur = new XmlsStackElement();
+ cur.level = currentLevel;
+ levels.add(cur);
+ lastlevel = currentLevel;
+ }
+ cur.nodes.add(n);
+ }
+
+ void getXmlnsAttr(Collection col) {
+ int size = levels.size() - 1;
+ if (cur == null) {
+ cur = new XmlsStackElement();
+ cur.level = currentLevel;
+ lastlevel = currentLevel;
+ levels.add(cur);
+ }
+ boolean parentRendered = false;
+ XmlsStackElement e = null;
+ if (size == -1) {
+ parentRendered = true;
+ } else {
+ e = (XmlsStackElement) levels.get(size);
+ if (e.rendered && e.level + 1 == currentLevel)
+ parentRendered = true;
+
+ }
+ if (parentRendered) {
+ col.addAll(cur.nodes);
+ cur.rendered = true;
+ return;
+ }
+
+ Map loa = new HashMap();
+ for (; size >= 0; size--) {
+ e = (XmlsStackElement) levels.get(size);
+ Iterator it = e.nodes.iterator();
+ while (it.hasNext()) {
+ Attr n = (Attr) it.next();
+ if (!loa.containsKey(n.getName()))
+ loa.put(n.getName(), n);
+ }
+
+ }
+ ;
+ cur.rendered = true;
+ col.addAll(loa.values());
+ }
+
+ }
+
+ XmlAttrStack xmlattrStack = new XmlAttrStack();
+
+ /**
+ * Constructor Canonicalizer20010315
+ *
+ * @param includeComments
+ */
+ public Canonicalizer20010315(boolean includeComments) {
+ super(includeComments);
+ }
+
+ /**
+ * @param E
+ * @param ns
+ * @return the Attr[]s to be outputted
+ * @throws CanonicalizationException
+ */
+ Iterator handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
+ throws CanonicalizationException {
+ if (!E.hasAttributes() && !firstCall) {
+ return null;
+ }
+ // result will contain the attrs which have to be outputted
+ final SortedSet result = this.result;
+ result.clear();
+ NamedNodeMap attrs = E.getAttributes();
+ int attrsLength = attrs.getLength();
+
+ for (int i = 0; i < attrsLength; i++) {
+ Attr N = (Attr) attrs.item(i);
+ String NUri = N.getNamespaceURI();
+
+ if (XMLNS_URI != NUri) {
+ //It's not a namespace attr node. Add to the result and continue.
+ result.add(N);
+ continue;
+ }
+
+ String NName = N.getLocalName();
+ String NValue = N.getValue();
+ if (XML.equals(NName)
+ && XML_LANG_URI.equals(NValue)) {
+ //The default mapping for xml must not be output.
+ continue;
+ }
+
+ Node n = ns.addMappingAndRender(NName, NValue, N);
+
+ if (n != null) {
+ //Render the ns definition
+ result.add(n);
+ if (C14nHelper.namespaceIsRelative(N)) {
+ Object exArgs[] = {E.getTagName(), NName, N.getNodeValue()};
+ throw new CanonicalizationException(
+ "c14n.Canonicalizer.RelativeNamespace", exArgs);
+ }
+ }
+ }
+
+ if (firstCall) {
+ //It is the first node of the subtree
+ //Obtain all the namespaces defined in the parents, and added to the output.
+ ns.getUnrenderedNodes(result);
+ //output the attributes in the xml namespace.
+ xmlattrStack.getXmlnsAttr(result);
+ firstCall = false;
+ }
+
+ return result.iterator();
+ }
+
+ /**
+ * Always throws a CanonicalizationException because this is inclusive org.apache.axiom.c14n.impl.
+ *
+ * @param rootNode
+ * @param inclusiveNamespaces
+ * @return none it always fails
+ * @throws org.apache.axiom.c14n.exceptions.CanonicalizationException
+ *
+ */
+ public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
+ throws CanonicalizationException {
+
+ throw new CanonicalizationException("All Namespaces are Included by Default");
+ }
+
+ void handleParent(Element e, NameSpaceSymbTable ns) {
+ if (!e.hasAttributes()) {
+ return;
+ }
+ xmlattrStack.push(-1);
+ NamedNodeMap attrs = e.getAttributes();
+ int attrsLength = attrs.getLength();
+ for (int i = 0; i < attrsLength; i++) {
+ Attr N = (Attr) attrs.item(i);
+ if (Constants.NamespaceSpecNS != N.getNamespaceURI()) {
+ //Not a namespace definition, ignore.
+ if (XML_LANG_URI == N.getNamespaceURI()) {
+ xmlattrStack.addXmlnsAttr(N);
+ }
+ continue;
+ }
+
+ String NName = N.getLocalName();
+ String NValue = N.getNodeValue();
+ if (XML.equals(NName)
+ && Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
+ continue;
+ }
+ ns.addMapping(NName, NValue, N);
+ }
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315Excl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315Excl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315Excl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315Excl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.impl;
+
+import org.apache.axiom.c14n.exceptions.CanonicalizationException;
+import org.apache.axiom.c14n.helpers.C14nHelper;
+import org.apache.axiom.c14n.omwrapper.interfaces.Attr;
+import org.apache.axiom.c14n.omwrapper.interfaces.Element;
+import org.apache.axiom.c14n.omwrapper.interfaces.NamedNodeMap;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.c14n.utils.Constants;
+
+import java.util.Iterator;
+import java.util.SortedSet;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
+
+/**
+ * @author Christian Geuer-Pollmann <ge...@apache.org>
+ *
+ * modified to work with Axiom wrapper by Saliya Ekanayake (esaliya@gmail.com)
+ */
+public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
+ /**
+ * This Set contains the names (Strings like "xmlns" or "xmlns:foo") of
+ * the inclusive namespaces.
+ */
+ TreeSet _inclusiveNSSet = new TreeSet();
+ static final String XMLNS_URI = Constants.NamespaceSpecNS;
+ final SortedSet result = new TreeSet(COMPARE);
+
+ /**
+ * Constructor Canonicalizer20010315Excl
+ *
+ * @param includeComments
+ */
+ public Canonicalizer20010315Excl(boolean includeComments) {
+ super(includeComments);
+ }
+
+ /**
+ * Method engineCanonicalizeSubTree
+ *
+ * @param rootNode
+ * @throws org.apache.axiom.c14n.exceptions.CanonicalizationException
+ *
+ * @inheritDoc
+ */
+ public byte[] engineCanonicalizeSubTree(Node rootNode)
+ throws CanonicalizationException {
+ return this.engineCanonicalizeSubTree(rootNode, "", null);
+ }
+
+ /**
+ * Method engineCanonicalizeSubTree
+ *
+ * @param rootNode
+ * @param inclusiveNamespaces
+ * @throws CanonicalizationException
+ * @inheritDoc
+ */
+ public byte[] engineCanonicalizeSubTree(Node rootNode,
+ String inclusiveNamespaces) throws CanonicalizationException {
+ return this.engineCanonicalizeSubTree(rootNode, inclusiveNamespaces, null);
+ }
+
+ /**
+ * Method engineCanonicalizeSubTree
+ *
+ * @param rootNode
+ * @param inclusiveNamespaces
+ * @param excl A element to exclude from the org.apache.axiom.c14n.impl process.
+ * @return the rootNode org.apache.axiom.c14n.impl.
+ * @throws CanonicalizationException
+ */
+ public byte[] engineCanonicalizeSubTree(Node rootNode,
+ String inclusiveNamespaces, Node excl) throws CanonicalizationException {
+ this._inclusiveNSSet = (TreeSet) prefixStr2Set(inclusiveNamespaces);
+ return super.engineCanonicalizeSubTree(rootNode, excl);
+ }
+
+
+
+ /**
+ * Method handleAttributesSubtree
+ *
+ * @param E
+ * @throws CanonicalizationException
+ * @inheritDoc
+ */
+ Iterator handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
+ throws CanonicalizationException {
+ SortedSet result = this.result;
+ result.clear();
+ NamedNodeMap attrs = null;
+
+ int attrsLength = 0;
+ if (E.hasAttributes()) {
+ attrs = E.getAttributes();
+ attrsLength = attrs.getLength();
+ }
+ //The prefix visibly utilized(in the attribute or in the name) in the element
+ SortedSet visiblyUtilized = (SortedSet) _inclusiveNSSet.clone();
+
+ for (int i = 0; i < attrsLength; i++) {
+ Attr N = (Attr) attrs.item(i);
+
+ if (XMLNS_URI != N.getNamespaceURI()) {
+ //Not a namespace definition.
+ //The Element is output element, add his prefix(if used) to visibyUtilized
+ String prefix = N.getPrefix();
+ if ((prefix != null) && (!prefix.equals(XML) && !prefix.equals(XMLNS))) {
+ visiblyUtilized.add(prefix);
+ }
+ //Add to the result.
+ result.add(N);
+ continue;
+ }
+ String NName = N.getLocalName();
+ String NNodeValue = N.getNodeValue();
+
+ if (ns.addMapping(NName, NNodeValue, N)) {
+ //New definition check if it is relative.
+ if (C14nHelper.namespaceIsRelative(NNodeValue)) {
+ Object exArgs[] = {E.getTagName(), NName,
+ N.getNodeValue()};
+ throw new CanonicalizationException(
+ "c14n.Canonicalizer.RelativeNamespace", exArgs);
+ }
+ }
+ }
+ String prefix;
+ if (E.getNamespaceURI() != null) {
+ prefix = E.getPrefix();
+ if ((prefix == null) || (prefix.length() == 0)) {
+ prefix = XMLNS;
+ }
+
+ } else {
+ prefix = XMLNS;
+ }
+ visiblyUtilized.add(prefix);
+
+ Iterator it = visiblyUtilized.iterator();
+ while (it.hasNext()) {
+ String s = (String) it.next();
+ Attr key = ns.getMapping(s);
+ if (key == null) {
+ continue;
+ }
+ result.add(key);
+ }
+
+ return result.iterator();
+ }
+
+ /**
+ * Decodes the <code>inclusiveNamespaces</code> String and returns all
+ * selected namespace prefixes as a Set. The <code>#default</code>
+ * namespace token is represented as an empty namespace prefix
+ * (<code>"xmlns"</code>).
+ * <BR/>
+ * The String <code>inclusiveNamespaces=" xenc ds #default"</code>
+ * is returned as a Set containing the following Strings:
+ * <UL>
+ * <LI><code>xmlns</code></LI>
+ * <LI><code>xenc</code></LI>
+ * <LI><code>ds</code></LI>
+ * </UL>
+ *
+ * @param inclusiveNamespaces
+ * @return A set to string
+ */
+ public static SortedSet prefixStr2Set(String inclusiveNamespaces) {
+
+ SortedSet prefixes = new TreeSet();
+
+ if ((inclusiveNamespaces == null)
+ || (inclusiveNamespaces.length() == 0)) {
+ return prefixes;
+ }
+
+ StringTokenizer st = new StringTokenizer(inclusiveNamespaces, " \t\r\n");
+
+ while (st.hasMoreTokens()) {
+ String prefix = st.nextToken();
+
+ if (prefix.equals("#default")) {
+ prefixes.add("xmlns");
+ } else {
+ prefixes.add(prefix);
+ }
+ }
+ return prefixes;
+ }
+
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclOmitComments.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclOmitComments.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclOmitComments.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclOmitComments.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.impl;
+
+import org.apache.axiom.c14n.Canonicalizer;
+
+public class Canonicalizer20010315ExclOmitComments extends Canonicalizer20010315Excl {
+//public class Canonicalizer20010315ExclOmitComments extends Canonicalizer20010315Excl {
+ /**
+ * Constructor Canonicalizer20010315ExclOmitComments
+ */
+ public Canonicalizer20010315ExclOmitComments() {
+ super(false);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public final String engineGetURI() {
+ return Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public final boolean engineGetIncludeComments() {
+ return false;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclWithComments.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclWithComments.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclWithComments.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315ExclWithComments.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.impl;
+
+import org.apache.axiom.c14n.Canonicalizer;
+
+public class Canonicalizer20010315ExclWithComments extends Canonicalizer20010315Excl {
+//public class Canonicalizer20010315ExclWithComments extends Canonicalizer20010315Excl {
+ /**
+ * Constructor Canonicalizer20010315ExclWithComments
+ */
+ public Canonicalizer20010315ExclWithComments() {
+ super(true);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public final String engineGetURI() {
+ return Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public final boolean engineGetIncludeComments() {
+ return true;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315OmitComments.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315OmitComments.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315OmitComments.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315OmitComments.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.impl;
+
+import org.apache.axiom.c14n.Canonicalizer;
+
+/**
+ * @author Christian Geuer-Pollmann <ge...@apache.org>
+ *
+ * modified to work with Axiom wrapper by Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class Canonicalizer20010315OmitComments extends Canonicalizer20010315 {
+ /**
+ * Constructor Canonicalizer20010315OmitComments
+ */
+ public Canonicalizer20010315OmitComments() {
+ super(false);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public final String engineGetURI() {
+ return Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public final boolean engineGetIncludeComments() {
+ return false;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315WithComments.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315WithComments.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315WithComments.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/Canonicalizer20010315WithComments.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.c14n.impl;
+
+import org.apache.axiom.c14n.Canonicalizer;
+
+/**
+ * @author Christian Geuer-Pollmann <ge...@apache.org>
+ *
+ * modified to work with Axiom wrapper by Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class Canonicalizer20010315WithComments extends Canonicalizer20010315 {
+
+ /**
+ * Constructor Canonicalizer20010315WithComments
+ */
+ public Canonicalizer20010315WithComments() {
+ super(true);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public final String engineGetURI() {
+ return Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public final boolean engineGetIncludeComments() {
+ return true;
+ }
+}