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/02/04 12:25:15 UTC
svn commit: r1067153 - in /santuario/xml-security-java/trunk:
samples/org/apache/xml/security/samples/signature/
src/main/java/org/apache/xml/security/
src/main/java/org/apache/xml/security/transforms/
src/test/java/org/apache/xml/security/test/transfo...
Author: coheigea
Date: Fri Feb 4 11:25:15 2011
New Revision: 1067153
URL: http://svn.apache.org/viewvc?rev=1067153&view=rev
Log:
[SANTUARIO-259] - Transform cleanup
- Changed how Transforms are loaded. Previously the Class was loaded and inserted into a static HashMap, and then another static HashMap kept track of instances which were loaded when required. To simplify things, there is now a single ConcurrentHashMap that loads implementations when registered.
Removed:
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/transforms/RegisterTest.java
Modified:
santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleSixteen.java
santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleTwentyThree.java
santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateNullURIReference.java
santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateSignature.java
santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/HereSigner.java
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/transforms/InvalidTransformException.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transform.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformParam.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformSpi.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformationException.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transforms.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/transforms/SampleTransform.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/utils/OldApiTest.java
Modified: santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleSixteen.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleSixteen.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleSixteen.java (original)
+++ santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleSixteen.java Fri Feb 4 11:25:15 2011
@@ -40,6 +40,7 @@ import org.apache.xml.security.signature
import org.apache.xml.security.transforms.Transforms;
import org.apache.xml.security.transforms.params.XPathContainer;
import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.ElementProxy;
import org.apache.xml.security.utils.IdResolver;
import org.apache.xml.security.utils.JavaUtils;
import org.apache.xml.security.utils.XMLUtils;
@@ -68,7 +69,7 @@ public class CreateMerlinsExampleSixteen
* @throws Exception
*/
public static void main(String unused[]) throws Exception {
- Constants.setSignatureSpecNSprefix("ds");
+ ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "ds");
String keystoreType = "JKS";
String keystoreFile = "samples/data/keystore.jks";
String keystorePass = "xmlsecurity";
Modified: santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleTwentyThree.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleTwentyThree.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleTwentyThree.java (original)
+++ santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateMerlinsExampleTwentyThree.java Fri Feb 4 11:25:15 2011
@@ -40,6 +40,7 @@ import org.apache.xml.security.signature
import org.apache.xml.security.transforms.Transforms;
import org.apache.xml.security.transforms.params.XPathContainer;
import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.ElementProxy;
import org.apache.xml.security.utils.IdResolver;
import org.apache.xml.security.utils.JavaUtils;
import org.apache.xml.security.utils.XMLUtils;
@@ -68,7 +69,7 @@ public class CreateMerlinsExampleTwentyT
* @throws Exception
*/
public static void main(String unused[]) throws Exception {
- Constants.setSignatureSpecNSprefix("ds");
+ ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "ds");
String keystoreType = "JKS";
String keystoreFile = "samples/data/keystore.jks";
Modified: santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateNullURIReference.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateNullURIReference.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateNullURIReference.java (original)
+++ santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateNullURIReference.java Fri Feb 4 11:25:15 2011
@@ -25,6 +25,7 @@ import java.security.cert.X509Certificat
import org.apache.xml.security.signature.XMLSignature;
import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.ElementProxy;
import org.apache.xml.security.utils.XMLUtils;
@@ -71,9 +72,9 @@ public class CreateNullURIReference {
javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = db.newDocument();
- String BaseURI = signatureFile.toURL().toString();
+ String BaseURI = signatureFile.toURI().toURL().toString();
- Constants.setSignatureSpecNSprefix(null);
+ ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, null);
XMLSignature sig =
new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_SIGNATURE_DSA);
Modified: santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateSignature.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateSignature.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateSignature.java (original)
+++ santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/CreateSignature.java Fri Feb 4 11:25:15 2011
@@ -26,6 +26,7 @@ import java.security.cert.X509Certificat
import org.apache.xml.security.signature.XMLSignature;
import org.apache.xml.security.transforms.Transforms;
import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.ElementProxy;
import org.apache.xml.security.utils.XMLUtils;
import org.w3c.dom.Element;
@@ -50,7 +51,7 @@ public class CreateSignature {
* @throws Exception
*/
public static void main(String unused[]) throws Exception {
- Constants.setSignatureSpecNSprefix("ds");
+ ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "ds");
//All the parameters for the keystore
String keystoreType = "JKS";
Modified: santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/HereSigner.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/HereSigner.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/HereSigner.java (original)
+++ santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/signature/HereSigner.java Fri Feb 4 11:25:15 2011
@@ -29,6 +29,7 @@ import org.apache.xml.security.signature
import org.apache.xml.security.transforms.Transforms;
import org.apache.xml.security.transforms.params.XPathContainer;
import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.ElementProxy;
import org.apache.xml.security.utils.HelperNodeList;
import org.apache.xml.security.utils.XMLUtils;
import org.w3c.dom.Element;
@@ -77,7 +78,7 @@ public class HereSigner {
org.w3c.dom.Document doc = db.newDocument();
String BaseURI = signatureFile.toURI().toURL().toString();
- Constants.setSignatureSpecNSprefix("prof");
+ ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "prof");
XMLSignature sig =
new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_SIGNATURE_DSA);
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=1067153&r1=1067152&r2=1067153&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 Feb 4 11:25:15 2011
@@ -204,7 +204,6 @@ public class Init {
if (tag.equals("TransformAlgorithms")){
XX_configure_reg_transforms_start = System.currentTimeMillis();
- Transform.init();
Element[] tranElem = XMLUtils.selectNodes(el.getFirstChild(),CONF_NS,"TransformAlgorithm");
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/InvalidTransformException.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/InvalidTransformException.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/InvalidTransformException.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/InvalidTransformException.java Fri Feb 4 11:25:15 2011
@@ -17,68 +17,64 @@
*/
package org.apache.xml.security.transforms;
-
-
import org.apache.xml.security.exceptions.XMLSecurityException;
-
/**
*
* @author Christian Geuer-Pollmann
*/
public class InvalidTransformException extends XMLSecurityException {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor InvalidTransformException
- *
- */
- public InvalidTransformException() {
- super();
- }
-
- /**
- * Constructor InvalidTransformException
- *
- * @param _msgId
- */
- public InvalidTransformException(String _msgId) {
- super(_msgId);
- }
-
- /**
- * Constructor InvalidTransformException
- *
- * @param _msgId
- * @param exArgs
- */
- public InvalidTransformException(String _msgId, Object exArgs[]) {
- super(_msgId, exArgs);
- }
-
- /**
- * Constructor InvalidTransformException
- *
- * @param _msgId
- * @param _originalException
- */
- public InvalidTransformException(String _msgId, Exception _originalException) {
- super(_msgId, _originalException);
- }
-
- /**
- * Constructor InvalidTransformException
- *
- * @param _msgId
- * @param exArgs
- * @param _originalException
- */
- public InvalidTransformException(String _msgId, Object exArgs[],
- Exception _originalException) {
- super(_msgId, exArgs, _originalException);
- }
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor InvalidTransformException
+ *
+ */
+ public InvalidTransformException() {
+ super();
+ }
+
+ /**
+ * Constructor InvalidTransformException
+ *
+ * @param msgId
+ */
+ public InvalidTransformException(String msgId) {
+ super(msgId);
+ }
+
+ /**
+ * Constructor InvalidTransformException
+ *
+ * @param msgId
+ * @param exArgs
+ */
+ public InvalidTransformException(String msgId, Object exArgs[]) {
+ super(msgId, exArgs);
+ }
+
+ /**
+ * Constructor InvalidTransformException
+ *
+ * @param msgId
+ * @param originalException
+ */
+ public InvalidTransformException(String msgId, Exception originalException) {
+ super(msgId, originalException);
+ }
+
+ /**
+ * Constructor InvalidTransformException
+ *
+ * @param msgId
+ * @param exArgs
+ * @param originalException
+ */
+ public InvalidTransformException(String msgId, Object exArgs[], Exception originalException) {
+ super(msgId, exArgs, originalException);
+ }
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transform.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transform.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transform.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transform.java Fri Feb 4 11:25:15 2011
@@ -18,7 +18,8 @@ package org.apache.xml.security.transfor
import java.io.IOException;
import java.io.OutputStream;
-import java.util.HashMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xml.security.c14n.CanonicalizationException;
@@ -55,15 +56,11 @@ public final class Transform extends Sig
private static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(Transform.class.getName());
- /** Field _alreadyInitialized */
- private static boolean alreadyInitialized = false;
-
/** All available Transform classes are registered here */
- private static HashMap transformClassHash = null;
-
- private static HashMap transformSpiHash = new HashMap();
-
- private TransformSpi transformSpi = null;
+ private static Map<String, TransformSpi> transformSpiHash =
+ new ConcurrentHashMap<String, TransformSpi>();
+
+ private TransformSpi transformSpi;
/**
* Constructs {@link Transform}
@@ -78,17 +75,14 @@ public final class Transform extends Sig
*/
public Transform(Document doc, String algorithmURI, NodeList contextNodes)
throws InvalidTransformException {
-
super(doc);
- this.constructionElement.setAttributeNS
- (null, Constants._ATT_ALGORITHM, algorithmURI);
+ this.constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM, algorithmURI);
- transformSpi = getTransformSpi(algorithmURI);
+ transformSpi = transformSpiHash.get(algorithmURI);
if (transformSpi == null) {
Object exArgs[] = { algorithmURI };
- throw new InvalidTransformException(
- "signature.Transform.UnknownTransform", exArgs);
+ throw new InvalidTransformException("signature.Transform.UnknownTransform", exArgs);
}
if (log.isDebugEnabled()) {
@@ -100,16 +94,12 @@ public final class Transform extends Sig
// give it to the current document
if (contextNodes != null) {
for (int i = 0; i < contextNodes.getLength(); i++) {
- this.constructionElement.appendChild
- (contextNodes.item(i).cloneNode(true));
+ this.constructionElement.appendChild(contextNodes.item(i).cloneNode(true));
}
}
}
/**
- * This constructor can only be called from the {@link Transforms} object,
- * so it's protected.
- *
* @param element <code>ds:Transform</code> element
* @param BaseURI the URI of the resource where the XML instance was stored
* @throws InvalidTransformException
@@ -117,22 +107,19 @@ public final class Transform extends Sig
* @throws XMLSecurityException
*/
public Transform(Element element, String BaseURI)
- throws InvalidTransformException, TransformationException,
- XMLSecurityException {
-
+ throws InvalidTransformException, TransformationException, XMLSecurityException {
super(element, BaseURI);
// retrieve Algorithm Attribute from ds:Transform
String algorithmURI = element.getAttributeNS(null, Constants._ATT_ALGORITHM);
if (algorithmURI == null || algorithmURI.length() == 0) {
- Object exArgs[] = { Constants._ATT_ALGORITHM,
- Constants._TAG_TRANSFORM };
+ Object exArgs[] = { Constants._ATT_ALGORITHM, Constants._TAG_TRANSFORM };
throw new TransformationException("xml.WrongContent", exArgs);
}
- transformSpi = getTransformSpi(algorithmURI);
+ transformSpi = transformSpiHash.get(algorithmURI);
if (transformSpi == null) {
Object exArgs[] = { algorithmURI };
throw new InvalidTransformException(
@@ -152,7 +139,8 @@ public final class Transform extends Sig
* @throws InvalidTransformException
*/
public static Transform getInstance(
- Document doc, String algorithmURI) throws InvalidTransformException {
+ Document doc, String algorithmURI
+ ) throws InvalidTransformException {
return getInstance(doc, algorithmURI, (NodeList) null);
}
@@ -169,8 +157,8 @@ public final class Transform extends Sig
* @throws InvalidTransformException
*/
public static Transform getInstance(
- Document doc, String algorithmURI, Element contextChild)
- throws InvalidTransformException {
+ Document doc, String algorithmURI, Element contextChild
+ ) throws InvalidTransformException {
HelperNodeList contextNodes = null;
@@ -198,22 +186,12 @@ public final class Transform extends Sig
* @throws InvalidTransformException
*/
public static Transform getInstance(
- Document doc, String algorithmURI, NodeList contextNodes)
- throws InvalidTransformException {
+ Document doc, String algorithmURI, NodeList contextNodes
+ ) throws InvalidTransformException {
return new Transform(doc, algorithmURI, contextNodes);
}
/**
- * Initalizes for this {@link Transform}.
- */
- public static void init() {
- if (!alreadyInitialized) {
- transformClassHash = new HashMap(10);
- alreadyInitialized = true;
- }
- }
-
- /**
* Registers implementing class of the Transform algorithm with algorithmURI
*
* @param algorithmURI algorithmURI URI representation of
@@ -224,23 +202,36 @@ public final class Transform extends Sig
* @throws AlgorithmAlreadyRegisteredException if specified algorithmURI
* is already registered
*/
+ @SuppressWarnings("unchecked")
public static void register(String algorithmURI, String implementingClass)
- throws AlgorithmAlreadyRegisteredException {
-
+ throws AlgorithmAlreadyRegisteredException, InvalidTransformException {
// are we already registered?
- Class registeredClass = getImplementingClass(algorithmURI);
- if ((registeredClass != null) ) {
- Object exArgs[] = { algorithmURI, registeredClass };
+ TransformSpi transformSpi = transformSpiHash.get(algorithmURI);
+ if ((transformSpi != null) ) {
+ Object exArgs[] = { algorithmURI, transformSpi.getClass() };
throw new AlgorithmAlreadyRegisteredException(
"algorithm.alreadyRegistered", exArgs);
}
-
try {
- transformClassHash.put
- (algorithmURI, ClassLoaderUtils.loadClass(implementingClass, Transform.class));
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
+ Class<TransformSpi> transformSpiClass =
+ (Class<TransformSpi>)ClassLoaderUtils.loadClass(implementingClass, Transform.class);
+ transformSpiHash.put(algorithmURI, transformSpiClass.newInstance());
+ } catch (InstantiationException ex) {
+ Object exArgs[] = { algorithmURI };
+ throw new InvalidTransformException(
+ "signature.Transform.UnknownTransform", exArgs, ex
+ );
+ } catch (IllegalAccessException ex) {
+ Object exArgs[] = { algorithmURI };
+ throw new InvalidTransformException(
+ "signature.Transform.UnknownTransform", exArgs, ex
+ );
+ } catch (ClassNotFoundException ex) {
+ Object exArgs[] = { algorithmURI };
+ throw new InvalidTransformException(
+ "signature.Transform.UnknownTransform", exArgs, ex
+ );
+ }
}
/**
@@ -249,8 +240,7 @@ public final class Transform extends Sig
* @return the URI representation of Transformation algorithm
*/
public String getURI() {
- return this.constructionElement.getAttributeNS
- (null, Constants._ATT_ALGORITHM);
+ return this.constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
}
/**
@@ -300,9 +290,9 @@ public final class Transform extends Sig
* @throws TransformationException
*/
public XMLSignatureInput performTransform(XMLSignatureInput input,
- OutputStream os) throws IOException, CanonicalizationException,
+ OutputStream os
+ ) throws IOException, CanonicalizationException,
InvalidCanonicalizerException, TransformationException {
-
XMLSignatureInput result = null;
try {
@@ -320,41 +310,6 @@ public final class Transform extends Sig
return result;
}
- /**
- * Method getImplementingClass
- *
- * @param URI
- * @return The name of the class implementing the URI.
- */
- private static Class getImplementingClass(String URI) {
- return (Class) transformClassHash.get(URI);
- }
-
- private static TransformSpi getTransformSpi(String URI)
- throws InvalidTransformException {
- try {
- Object value = transformSpiHash.get(URI);
- if (value != null) {
- return (TransformSpi) value;
- }
- Class cl = (Class) transformClassHash.get(URI);
- if (cl != null) {
- TransformSpi tr = (TransformSpi) cl.newInstance();
- transformSpiHash.put(URI, tr);
- return tr;
- }
- } catch (InstantiationException ex) {
- Object exArgs[] = { URI };
- throw new InvalidTransformException(
- "signature.Transform.UnknownTransform", exArgs, ex);
- } catch (IllegalAccessException ex) {
- Object exArgs[] = { URI };
- throw new InvalidTransformException(
- "signature.Transform.UnknownTransform", exArgs, ex);
- }
- return null;
- }
-
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_TRANSFORM;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformParam.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformParam.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformParam.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformParam.java Fri Feb 4 11:25:15 2011
@@ -21,6 +21,5 @@ package org.apache.xml.security.transfor
*
* @author $Author$
*/
-
public interface TransformParam {
}
\ No newline at end of file
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformSpi.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformSpi.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformSpi.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformSpi.java Fri Feb 4 11:25:15 2011
@@ -33,20 +33,23 @@ import org.xml.sax.SAXException;
* @author Christian Geuer-Pollmann
*/
public abstract class TransformSpi {
+
/**
* For API compatibility not thread safe.
* @deprecated
*/
- protected Transform _transformObject = null;
+ protected Transform transformObject = null;
+
/**
* Set the transform object.
- * Depeprecated For API compatibility.
+ * Deprecated For API compatibility.
* @param transform the Transform
* @deprecated
*/
protected void setTransform(Transform transform) {
- this._transformObject = transform;
+ this.transformObject = transform;
}
+
/**
* The mega method which MUST be implemented by the Transformation Algorithm.
*
@@ -62,13 +65,12 @@ public abstract class TransformSpi {
* @throws TransformationException
*/
protected XMLSignatureInput enginePerformTransform(
- XMLSignatureInput input, OutputStream os, Transform _transformObject)
- throws IOException,
- CanonicalizationException, InvalidCanonicalizerException,
- TransformationException, ParserConfigurationException,
- SAXException {
- return enginePerformTransform(input, _transformObject);
+ XMLSignatureInput input, OutputStream os, Transform transformObject
+ ) throws IOException, CanonicalizationException, InvalidCanonicalizerException,
+ TransformationException, ParserConfigurationException, SAXException {
+ return enginePerformTransform(input, transformObject);
}
+
/**
* The mega method which MUST be implemented by the Transformation Algorithm.
* In order to be compatible with preexisting Transform implementations,
@@ -77,7 +79,7 @@ public abstract class TransformSpi {
* implementation.
*
* @param input {@link XMLSignatureInput} as the input of transformation
- * @param _transformObject the Transform
+ * @param transformObject the Transform
* @return {@link XMLSignatureInput} as the result of transformation
* @throws CanonicalizationException
* @throws IOException
@@ -87,15 +89,12 @@ public abstract class TransformSpi {
* @throws TransformationException
*/
protected XMLSignatureInput enginePerformTransform(
- XMLSignatureInput input, Transform _transformObject)
- throws IOException,
- CanonicalizationException, InvalidCanonicalizerException,
- TransformationException, ParserConfigurationException,
- SAXException {
- //Default implementation overide with a much better
+ XMLSignatureInput input, Transform transformObject
+ ) throws IOException, CanonicalizationException, InvalidCanonicalizerException,
+ TransformationException, ParserConfigurationException, SAXException {
try {
- TransformSpi tmp = (TransformSpi) getClass().newInstance();
- tmp.setTransform(_transformObject);
+ TransformSpi tmp = (TransformSpi) getClass().newInstance();
+ tmp.setTransform(transformObject);
return tmp.enginePerformTransform(input);
} catch (InstantiationException e) {
throw new TransformationException("",e);
@@ -117,13 +116,12 @@ public abstract class TransformSpi {
* @throws TransformationException
*/
protected XMLSignatureInput enginePerformTransform(
- XMLSignatureInput input)
- throws IOException,
- CanonicalizationException, InvalidCanonicalizerException,
- TransformationException, ParserConfigurationException,
- SAXException {
+ XMLSignatureInput input
+ ) throws IOException, CanonicalizationException, InvalidCanonicalizerException,
+ TransformationException, ParserConfigurationException, SAXException {
throw new UnsupportedOperationException();
}
+
/**
* Returns the URI representation of <code>Transformation algorithm</code>
*
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformationException.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformationException.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformationException.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/TransformationException.java Fri Feb 4 11:25:15 2011
@@ -17,68 +17,63 @@
*/
package org.apache.xml.security.transforms;
-
-
import org.apache.xml.security.exceptions.XMLSecurityException;
-
/**
*
* @author Christian Geuer-Pollmann
*/
public class TransformationException extends XMLSecurityException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor TransformationException
- *
- */
- public TransformationException() {
- super();
- }
-
- /**
- * Constructor TransformationException
- *
- * @param _msgID
- */
- public TransformationException(String _msgID) {
- super(_msgID);
- }
-
- /**
- * Constructor TransformationException
- *
- * @param _msgID
- * @param exArgs
- */
- public TransformationException(String _msgID, Object exArgs[]) {
- super(_msgID, exArgs);
- }
-
- /**
- * Constructor TransformationException
- *
- * @param _msgID
- * @param _originalException
- */
- public TransformationException(String _msgID, Exception _originalException) {
- super(_msgID, _originalException);
- }
-
- /**
- * Constructor TransformationException
- *
- * @param _msgID
- * @param exArgs
- * @param _originalException
- */
- public TransformationException(String _msgID, Object exArgs[],
- Exception _originalException) {
- super(_msgID, exArgs, _originalException);
- }
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor TransformationException
+ *
+ */
+ public TransformationException() {
+ super();
+ }
+
+ /**
+ * Constructor TransformationException
+ *
+ * @param msgID
+ */
+ public TransformationException(String msgID) {
+ super(msgID);
+ }
+
+ /**
+ * Constructor TransformationException
+ *
+ * @param msgID
+ * @param exArgs
+ */
+ public TransformationException(String msgID, Object exArgs[]) {
+ super(msgID, exArgs);
+ }
+
+ /**
+ * Constructor TransformationException
+ *
+ * @param msgID
+ * @param originalException
+ */
+ public TransformationException(String msgID, Exception originalException) {
+ super(msgID, originalException);
+ }
+
+ /**
+ * Constructor TransformationException
+ *
+ * @param msgID
+ * @param exArgs
+ * @param originalException
+ */
+ public TransformationException(String msgID, Object exArgs[], Exception originalException) {
+ super(msgID, exArgs, originalException);
+ }
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transforms.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transforms.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transforms.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/Transforms.java Fri Feb 4 11:25:15 2011
@@ -47,53 +47,67 @@ import org.w3c.dom.NodeList;
*/
public class Transforms extends SignatureElementProxy {
- /** {@link org.apache.commons.logging} logging facility */
- static org.apache.commons.logging.Log log =
- org.apache.commons.logging.LogFactory.getLog(Transforms.class.getName());
/** Canonicalization - Required Canonical XML (omits comments) */
public static final String TRANSFORM_C14N_OMIT_COMMENTS
= Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
+
/** Canonicalization - Recommended Canonical XML with Comments */
public static final String TRANSFORM_C14N_WITH_COMMENTS
= Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
+
/** Canonicalization - Required Canonical XML 1.1 (omits comments) */
public static final String TRANSFORM_C14N11_OMIT_COMMENTS
= Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS;
+
/** Canonicalization - Recommended Canonical XML 1.1 with Comments */
public static final String TRANSFORM_C14N11_WITH_COMMENTS
= Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS;
+
/** Canonicalization - Required Exclusive Canonicalization (omits comments) */
public static final String TRANSFORM_C14N_EXCL_OMIT_COMMENTS
= Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
+
/** Canonicalization - Recommended Exclusive Canonicalization with Comments */
public static final String TRANSFORM_C14N_EXCL_WITH_COMMENTS
= Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS;
+
/** Transform - Optional XSLT */
public static final String TRANSFORM_XSLT
= "http://www.w3.org/TR/1999/REC-xslt-19991116";
+
/** Transform - Required base64 decoding */
public static final String TRANSFORM_BASE64_DECODE
= Constants.SignatureSpecNS + "base64";
+
/** Transform - Recommended XPath */
public static final String TRANSFORM_XPATH
= "http://www.w3.org/TR/1999/REC-xpath-19991116";
+
/** Transform - Required Enveloped Signature */
public static final String TRANSFORM_ENVELOPED_SIGNATURE
= Constants.SignatureSpecNS + "enveloped-signature";
+
/** Transform - XPointer */
public static final String TRANSFORM_XPOINTER
= "http://www.w3.org/TR/2001/WD-xptr-20010108";
+
/** Transform - XPath Filter v2.0 */
public static final String TRANSFORM_XPATH2FILTER04
= "http://www.w3.org/2002/04/xmldsig-filter2";
+
/** Transform - XPath Filter */
public static final String TRANSFORM_XPATH2FILTER
= "http://www.w3.org/2002/06/xmldsig-filter2";
+
/** Transform - XPath Filter CHGP private */
public static final String TRANSFORM_XPATHFILTERCHGP
= "http://www.nue.et-inf.uni-siegen.de/~geuer-pollmann/#xpathFilter";
+
+ /** {@link org.apache.commons.logging} logging facility */
+ private static org.apache.commons.logging.Log log =
+ org.apache.commons.logging.LogFactory.getLog(Transforms.class.getName());
- Element []transforms;
+ private Element[] transforms;
protected Transforms() { };
@@ -121,19 +135,15 @@ public class Transforms extends Signatur
* @throws XMLSignatureException
*/
public Transforms(Element element, String BaseURI)
- throws DOMException, XMLSignatureException,
- InvalidTransformException, TransformationException,
- XMLSecurityException {
-
+ throws DOMException, XMLSignatureException, InvalidTransformException,
+ TransformationException, XMLSecurityException {
super(element, BaseURI);
int numberOfTransformElems = this.getLength();
if (numberOfTransformElems == 0) {
-
// At least one Transform element must be present. Bad.
- Object exArgs[] = { Constants._TAG_TRANSFORM,
- Constants._TAG_TRANSFORMS };
+ Object exArgs[] = { Constants._TAG_TRANSFORM, Constants._TAG_TRANSFORMS };
throw new TransformationException("xml.WrongContent", exArgs);
}
@@ -147,15 +157,13 @@ public class Transforms extends Signatur
* transformation is applied to data
* @throws TransformationException
*/
- public void addTransform(String transformURI)
- throws TransformationException {
-
+ public void addTransform(String transformURI) throws TransformationException {
try {
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
log.debug("Transforms.addTransform(" + transformURI + ")");
+ }
- Transform transform =
- Transform.getInstance(this.doc, transformURI);
+ Transform transform = Transform.getInstance(this.doc, transformURI);
this.addTransform(transform);
} catch (InvalidTransformException ex) {
@@ -174,11 +182,11 @@ public class Transforms extends Signatur
* @see Transform#getInstance(Document doc, String algorithmURI, Element childElement)
*/
public void addTransform(String transformURI, Element contextElement)
- throws TransformationException {
-
+ throws TransformationException {
try {
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
log.debug("Transforms.addTransform(" + transformURI + ")");
+ }
Transform transform =
Transform.getInstance(this.doc, transformURI, contextElement);
@@ -200,7 +208,7 @@ public class Transforms extends Signatur
* @see Transform#getInstance(Document doc, String algorithmURI, NodeList contextNodes)
*/
public void addTransform(String transformURI, NodeList contextNodes)
- throws TransformationException {
+ throws TransformationException {
try {
Transform transform =
@@ -217,8 +225,9 @@ public class Transforms extends Signatur
* @param transform {@link Transform} object
*/
private void addTransform(Transform transform) {
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
log.debug("Transforms.addTransform(" + transform.getURI() + ")");
+ }
Element transformElement = transform.getElement();
@@ -235,7 +244,8 @@ public class Transforms extends Signatur
* @throws TransformationException
*/
public XMLSignatureInput performTransforms(
- XMLSignatureInput xmlSignatureInput) throws TransformationException {
+ XMLSignatureInput xmlSignatureInput
+ ) throws TransformationException {
return performTransforms(xmlSignatureInput, null);
}
@@ -249,20 +259,18 @@ public class Transforms extends Signatur
* @throws TransformationException
*/
public XMLSignatureInput performTransforms(
- XMLSignatureInput xmlSignatureInput, OutputStream os)
- throws TransformationException {
-
+ XMLSignatureInput xmlSignatureInput, OutputStream os
+ ) throws TransformationException {
try {
- int last=this.getLength()-1;
+ int last = this.getLength() - 1;
for (int i = 0; i < last; i++) {
Transform t = this.item(i);
if (log.isDebugEnabled()) {
- log.debug("Perform the (" + i + ")th " + t.getURI()
- + " transform");
+ log.debug("Perform the (" + i + ")th " + t.getURI() + " transform");
}
xmlSignatureInput = t.performTransform(xmlSignatureInput);
}
- if (last>=0) {
+ if (last >= 0) {
Transform t = this.item(last);
xmlSignatureInput = t.performTransform(xmlSignatureInput, os);
}
@@ -282,11 +290,10 @@ public class Transforms extends Signatur
*
* @return the number of transformations
*/
- public int getLength()
- {
+ public int getLength() {
if (transforms == null) {
- transforms = XMLUtils.selectDsNodes
- (this.constructionElement.getFirstChild(), "Transform");
+ transforms =
+ XMLUtils.selectDsNodes(this.constructionElement.getFirstChild(), "Transform");
}
return transforms.length;
}
@@ -300,11 +307,10 @@ public class Transforms extends Signatur
* @throws TransformationException
*/
public Transform item(int i) throws TransformationException {
-
try {
if (transforms == null) {
- transforms = XMLUtils.selectDsNodes
- (this.constructionElement.getFirstChild(), "Transform");
+ transforms =
+ XMLUtils.selectDsNodes(this.constructionElement.getFirstChild(), "Transform");
}
return new Transform(transforms[i], this.baseURI);
} catch (XMLSecurityException ex) {
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/transforms/SampleTransform.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/transforms/SampleTransform.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/transforms/SampleTransform.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/transforms/SampleTransform.java Fri Feb 4 11:25:15 2011
@@ -29,9 +29,8 @@ public class SampleTransform extends Tra
public static final String uri =
"http://org.apache.xml.security.test.transforms.SampleTransform";
- public SampleTransform() {
+ public SampleTransform() throws InvalidTransformException {
try {
- Transform.init();
Transform.register
(uri, "org.apache.xml.security.test.transforms.SampleTransform");
} catch (AlgorithmAlreadyRegisteredException e) { }
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/utils/OldApiTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/utils/OldApiTest.java?rev=1067153&r1=1067152&r2=1067153&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/utils/OldApiTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/utils/OldApiTest.java Fri Feb 4 11:25:15 2011
@@ -54,7 +54,7 @@ public class OldApiTest extends org.juni
XMLSignatureInput input
) throws IOException, CanonicalizationException, InvalidCanonicalizerException,
TransformationException, ParserConfigurationException, SAXException {
- assertEquals(compare, _transformObject);
+ assertEquals(compare, transformObject);
return null ;
}