You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by gi...@apache.org on 2012/07/31 09:20:30 UTC

svn commit: r1367437 [1/3] - in /santuario/xml-security-java/trunk/src: main/java/org/apache/xml/security/stax/config/ main/java/org/apache/xml/security/stax/ext/ main/java/org/apache/xml/security/stax/impl/ main/java/org/apache/xml/security/stax/impl/...

Author: giger
Date: Tue Jul 31 07:20:29 2012
New Revision: 1367437

URL: http://svn.apache.org/viewvc?rev=1367437&view=rev
Log:
- fix for SANTUARIO-322 and SANTUARIO-319
- transformer chaining improvements

Added:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java   (with props)
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformBase64DecodeTest.java   (with props)
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformCanonicalizerTest.java   (with props)
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformEnvelopedSignatureTest.java   (with props)
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformIdentityTest.java   (with props)
    santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml   (with props)
Modified:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/DocumentContext.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/InboundXMLSec.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/ResourceResolverLookup.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/Transformer.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/DocumentContextImpl.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureInputHandler.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureReferenceVerifyInputProcessor.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverFilesystem.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverHttp.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverSameDocument.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverXPointer.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/encryption/DecryptionTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/BaltimoreTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/IAIKTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationReferenceURIResolverTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/HttpRequestRedirectorProxy.java
    santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java Tue Jul 31 07:20:29 2012
@@ -48,12 +48,12 @@ public class ResourceResolverMapper {
         }
     }
 
-    public static ResourceResolver getResourceResolver(String uri) throws XMLSecurityException {
+    public static ResourceResolver getResourceResolver(String uri, String baseURI) throws XMLSecurityException {
         for (int i = 0; i < resourceResolvers.size(); i++) {
             ResourceResolverLookup resourceResolver = resourceResolvers.get(i);
-            ResourceResolverLookup rr = resourceResolver.canResolve(uri);
+            ResourceResolverLookup rr = resourceResolver.canResolve(uri, baseURI);
             if (rr != null) {
-                return rr.newInstance(uri);
+                return rr.newInstance(uri, baseURI);
             }
         }
         throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, "resolver.noClass", uri);

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/DocumentContext.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/DocumentContext.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/DocumentContext.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/DocumentContext.java Tue Jul 31 07:20:29 2012
@@ -30,11 +30,16 @@ import java.util.Map;
 public interface DocumentContext {
 
     /**
-     * @return The Encoding of the Document
+     * @return The Encoding of the document
      */
     String getEncoding();
 
     /**
+     * @return The base URI of the document if known
+     */
+    String getBaseURI();
+
+    /**
      * Indicates if we currently stay in an encrypted content
      */
     void setIsInEncryptedContent(int index, Object object);

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/InboundXMLSec.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/InboundXMLSec.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/InboundXMLSec.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/InboundXMLSec.java Tue Jul 31 07:20:29 2012
@@ -126,6 +126,7 @@ public class InboundXMLSec {
 
         DocumentContextImpl documentContext = new DocumentContextImpl();
         documentContext.setEncoding(xmlStreamReader.getEncoding() != null ? xmlStreamReader.getEncoding() : "UTF-8");
+        documentContext.setBaseURI(xmlStreamReader.getLocation().getSystemId());
         
         InputProcessorChainImpl inputProcessorChain = new InputProcessorChainImpl(securityContextImpl, documentContext);
         inputProcessorChain.addProcessor(new XMLEventReaderInputProcessor(securityProperties, xmlStreamReader));

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/ResourceResolverLookup.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/ResourceResolverLookup.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/ResourceResolverLookup.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/ResourceResolverLookup.java Tue Jul 31 07:20:29 2012
@@ -24,7 +24,7 @@ package org.apache.xml.security.stax.ext
  */
 public interface ResourceResolverLookup {
 
-    ResourceResolverLookup canResolve(String uri);
+    ResourceResolverLookup canResolve(String uri, String baseURI);
 
-    ResourceResolver newInstance(String uri);
+    ResourceResolver newInstance(String uri, String baseURI);
 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/Transformer.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/Transformer.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/Transformer.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/Transformer.java Tue Jul 31 07:20:29 2012
@@ -21,6 +21,7 @@ package org.apache.xml.security.stax.ext
 import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
 
 import javax.xml.stream.XMLStreamException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.List;
 
@@ -32,11 +33,15 @@ public interface Transformer {
 
     void setOutputStream(OutputStream outputStream) throws XMLSecurityException;
 
+    void setTransformer(Transformer transformer) throws XMLSecurityException;
+
     void setList(List list) throws XMLSecurityException;
 
-    void setTransformer(Transformer transformer) throws XMLSecurityException;
+    XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput);
 
     void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException;
 
+    void transform(InputStream inputStream) throws XMLStreamException;
+
     void doFinal() throws XMLStreamException;
 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java Tue Jul 31 07:20:29 2012
@@ -384,4 +384,9 @@ public class XMLSecurityConstants {
         SIGNATURE,
         ENCRYPTION
     }
+
+    public enum TransformMethod {
+        XMLSecEvent,
+        InputStream,
+    }
 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/DocumentContextImpl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/DocumentContextImpl.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/DocumentContextImpl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/DocumentContextImpl.java Tue Jul 31 07:20:29 2012
@@ -32,6 +32,7 @@ import java.util.*;
 public class DocumentContextImpl implements DocumentContext, Cloneable {
 
     private String encoding;
+    private String baseURI;
     private final Map<Integer, XMLSecurityConstants.ContentType> contentTypeMap = new TreeMap<Integer, XMLSecurityConstants.ContentType>();
     private final Map<Object, Integer> processorToIndexMap = new HashMap<Object, Integer>();
 
@@ -43,6 +44,14 @@ public class DocumentContextImpl impleme
         this.encoding = encoding;
     }
 
+    public String getBaseURI() {
+        return baseURI;
+    }
+
+    public void setBaseURI(String baseURI) {
+        this.baseURI = baseURI;
+    }
+
     public synchronized void setIsInEncryptedContent(int index, Object key) {
         contentTypeMap.put(index, XMLSecurityConstants.ContentType.ENCRYPTION);
         processorToIndexMap.put(key, index);
@@ -88,6 +97,7 @@ public class DocumentContextImpl impleme
     protected DocumentContextImpl clone() throws CloneNotSupportedException {
         DocumentContextImpl documentContext = new DocumentContextImpl();
         documentContext.setEncoding(this.encoding);
+        documentContext.setBaseURI(this.baseURI);
         documentContext.setContentTypeMap(getContentTypeMap());
         return documentContext;
     }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java Tue Jul 31 07:20:29 2012
@@ -38,10 +38,8 @@ import org.apache.xml.security.stax.secu
 import org.xmlsecurity.ns.configuration.AlgorithmType;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
 import java.io.*;
 import java.lang.reflect.InvocationTargetException;
 import java.security.MessageDigest;
@@ -64,6 +62,7 @@ public abstract class AbstractSignatureR
     private final List<ReferenceType> processedReferences;
 
     public AbstractSignatureReferenceVerifyInputProcessor(
+            InputProcessorChain inputProcessorChain,
             SignatureType signatureType, SecurityToken securityToken,
             XMLSecurityProperties securityProperties) throws XMLSecurityException {
         super(securityProperties);
@@ -81,7 +80,10 @@ public abstract class AbstractSignatureR
             if (referenceType.getURI() == null) {
                 throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK);
             }
-            ResourceResolver resourceResolver = ResourceResolverMapper.getResourceResolver(referenceType.getURI());
+            ResourceResolver resourceResolver =
+                    ResourceResolverMapper.getResourceResolver(
+                            referenceType.getURI(), inputProcessorChain.getDocumentContext().getBaseURI());
+
             if (resourceResolver.isSameDocumentReference()) {
                 sameDocumentReferences.put(resourceResolver, referenceType);
             } else {
@@ -218,18 +220,7 @@ public abstract class AbstractSignatureR
 
             if (referenceType.getTransforms() != null) {
                 transformer = buildTransformerChain(referenceType, bufferedDigestOutputStream, inputProcessorChain, null);
-
-                XMLStreamReader xmlStreamReader =
-                        inputProcessorChain.getSecurityContext().<XMLInputFactory>get(
-                                XMLSecurityConstants.XMLINPUTFACTORY).createXMLStreamReader(inputStream);
-                XMLEventReaderInputProcessor xmlEventReaderInputProcessor = new XMLEventReaderInputProcessor(null, xmlStreamReader);
-
-                XMLSecEvent xmlSecEvent;
-                do {
-                    xmlSecEvent = xmlEventReaderInputProcessor.processNextEvent(null);
-                    transformer.transform(xmlSecEvent);
-                } while (xmlSecEvent.getEventType() != XMLStreamConstants.END_DOCUMENT);
-
+                transformer.transform(inputStream);
                 bufferedDigestOutputStream.close();
             } else {
                 IOUtils.copy(inputStream, bufferedDigestOutputStream);

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureInputHandler.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureInputHandler.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureInputHandler.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureInputHandler.java Tue Jul 31 07:20:29 2012
@@ -104,7 +104,7 @@ public class XMLSignatureInputHandler ex
                                                               XMLSecurityProperties securityProperties,
                                                               SignatureType signatureType, SecurityToken securityToken) throws XMLSecurityException {
         //add processors to verify references
-        inputProcessorChain.addProcessor(new XMLSignatureReferenceVerifyInputProcessor(signatureType, securityToken, securityProperties));
+        inputProcessorChain.addProcessor(new XMLSignatureReferenceVerifyInputProcessor(inputProcessorChain, signatureType, securityToken, securityProperties));
     }
     
     public class XMLSignatureVerifier extends SignatureVerifier {

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureReferenceVerifyInputProcessor.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureReferenceVerifyInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureReferenceVerifyInputProcessor.java Tue Jul 31 07:20:29 2012
@@ -36,8 +36,8 @@ import org.apache.xml.security.stax.secu
  */
 public class XMLSignatureReferenceVerifyInputProcessor extends AbstractSignatureReferenceVerifyInputProcessor {
 
-    public XMLSignatureReferenceVerifyInputProcessor(SignatureType signatureType, SecurityToken securityToken, XMLSecurityProperties securityProperties) throws XMLSecurityException {
-        super(signatureType, securityToken, securityProperties);
+    public XMLSignatureReferenceVerifyInputProcessor(InputProcessorChain inputProcessorChain, SignatureType signatureType, SecurityToken securityToken, XMLSecurityProperties securityProperties) throws XMLSecurityException {
+        super(inputProcessorChain, signatureType, securityToken, securityProperties);
         this.addAfterProcessor(XMLSignatureReferenceVerifyInputProcessor.class.getName());
     }
     

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java Tue Jul 31 07:20:29 2012
@@ -79,7 +79,7 @@ public abstract class AbstractSignatureO
             final SecurePart securePart = securePartEntry.getValue();
             final String externalReference = securePart.getExternalReference();
             if (externalReference != null) {
-                ResourceResolver resourceResolver = ResourceResolverMapper.getResourceResolver(externalReference);
+                ResourceResolver resourceResolver = ResourceResolverMapper.getResourceResolver(externalReference, outputProcessorChain.getDocumentContext().getBaseURI());
 
                 DigestOutputStream digestOutputStream = null;
                 try {
@@ -92,13 +92,27 @@ public abstract class AbstractSignatureO
 
                 InputStream inputStream = resourceResolver.getInputStreamFromExternalReference();
 
-                //todo transformers
-
                 try {
-                    IOUtils.copy(inputStream, digestOutputStream);
+                    if (securePart.getTransforms() != null) {
+                        Transformer transformer = buildTransformerChain(digestOutputStream, securePart.getTransforms());
+                        transformer.transform(inputStream);
+                        transformer.doFinal();
+                    } else {
+                        IOUtils.copy(inputStream, digestOutputStream);
+                    }
+                    digestOutputStream.close();
+                } catch (NoSuchMethodException e) {
+                    throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
+                } catch (InstantiationException e) {
+                    throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
+                } catch (IllegalAccessException e) {
+                    throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
+                } catch (InvocationTargetException e) {
+                    throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
                 } catch (IOException e) {
                     throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
                 }
+
                 String calculatedDigest = new String(Base64.encodeBase64(digestOutputStream.getDigestValue()));
                 if (logger.isDebugEnabled()) {
                     logger.debug("Calculated Digest: " + calculatedDigest);
@@ -144,6 +158,31 @@ public abstract class AbstractSignatureO
         return new DigestOutputStream(messageDigest);
     }
 
+    protected Transformer buildTransformerChain(OutputStream outputStream, String[] transforms)
+            throws XMLSecurityException, NoSuchMethodException, InstantiationException,
+            IllegalAccessException, InvocationTargetException {
+
+        if (transforms == null || transforms.length == 0) {
+            Transformer transformer = new TransformIdentity();
+            transformer.setOutputStream(outputStream);
+            return transformer;
+        }
+
+        Transformer parentTransformer = null;
+        for (int i = transforms.length - 1; i >= 0; i--) {
+            String transform = transforms[i];
+
+            if (parentTransformer != null) {
+                parentTransformer = XMLSecurityUtils.getTransformer(
+                        parentTransformer, null, transform, XMLSecurityConstants.DIRECTION.OUT);
+            } else {
+                parentTransformer = XMLSecurityUtils.getTransformer(
+                        null, outputStream, transform, XMLSecurityConstants.DIRECTION.OUT);
+            }
+        }
+        return parentTransformer;
+    }
+
     public class InternalSignatureOutputProcessor extends AbstractOutputProcessor {
 
         private SignaturePartDef signaturePartDef;
@@ -181,35 +220,9 @@ public abstract class AbstractSignatureO
             } catch (NoSuchProviderException e) {
                 throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
             }
-
             super.init(outputProcessorChain);
         }
 
-        protected Transformer buildTransformerChain(OutputStream outputStream, String[] transforms)
-                throws XMLSecurityException, NoSuchMethodException, InstantiationException,
-                IllegalAccessException, InvocationTargetException {
-
-            if (transforms == null || transforms.length == 0) {
-                Transformer transformer = new TransformIdentity();
-                transformer.setOutputStream(outputStream);
-                return transformer;
-            }
-
-            Transformer parentTransformer = null;
-            for (int i = transforms.length - 1; i >= 0; i--) {
-                String transform = transforms[i];
-
-                if (parentTransformer != null) {
-                    parentTransformer = XMLSecurityUtils.getTransformer(
-                            parentTransformer, null, transform, XMLSecurityConstants.DIRECTION.OUT);
-                } else {
-                    parentTransformer = XMLSecurityUtils.getTransformer(
-                            null, outputStream, transform, XMLSecurityConstants.DIRECTION.OUT);
-                }
-            }
-            return parentTransformer;
-        }
-
         @Override
         public void processEvent(XMLSecEvent xmlSecEvent, OutputProcessorChain outputProcessorChain)
                 throws XMLStreamException, XMLSecurityException {

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverFilesystem.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverFilesystem.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverFilesystem.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverFilesystem.java Tue Jul 31 07:20:29 2012
@@ -36,25 +36,30 @@ import java.net.URI;
 public class ResolverFilesystem implements ResourceResolver, ResourceResolverLookup {
 
     private String uri;
+    private String baseURI;
 
     public ResolverFilesystem() {
     }
 
-    public ResolverFilesystem(String uri) {
+    public ResolverFilesystem(String uri, String baseURI) {
         this.uri = uri;
+        this.baseURI = baseURI;
     }
 
     @Override
-    public ResourceResolverLookup canResolve(String uri) {
-        if (uri != null && uri.startsWith("file:")) {
+    public ResourceResolverLookup canResolve(String uri, String baseURI) {
+        if (uri == null) {
+            return null;
+        }
+        if (uri.startsWith("file:") || (baseURI != null && baseURI.startsWith("file:"))) {
             return this;
         }
         return null;
     }
 
     @Override
-    public ResourceResolver newInstance(String uri) {
-        return new ResolverFilesystem(uri);
+    public ResourceResolver newInstance(String uri, String baseURI) {
+        return new ResolverFilesystem(uri, baseURI);
     }
 
     @Override
@@ -70,7 +75,13 @@ public class ResolverFilesystem implemen
     @Override
     public InputStream getInputStreamFromExternalReference() throws XMLSecurityException {
         try {
-            URI tmp = new URI(uri);
+            URI tmp;
+            if (baseURI == null || "".equals(baseURI)) {
+                tmp = new URI(uri);
+            } else {
+                tmp = new URI(baseURI).resolve(uri);
+            }
+
             if (tmp.getFragment() != null) {
                 tmp = new URI(tmp.getScheme(), tmp.getSchemeSpecificPart(), null);
             }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverHttp.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverHttp.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverHttp.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverHttp.java Tue Jul 31 07:20:29 2012
@@ -39,13 +39,15 @@ public class ResolverHttp implements Res
     private static Proxy proxy;
 
     private String uri;
+    private String baseURI;
     private Pattern pattern = Pattern.compile("^http[s]?://.*");
 
     public ResolverHttp() {
     }
 
-    public ResolverHttp(String uri) {
+    public ResolverHttp(String uri, String baseURI) {
         this.uri = uri;
+        this.baseURI = baseURI;
     }
 
     public static void setProxy(Proxy proxy) {
@@ -53,16 +55,19 @@ public class ResolverHttp implements Res
     }
 
     @Override
-    public ResourceResolverLookup canResolve(String uri) {
-        if (uri != null && pattern.matcher(uri).matches()) {
+    public ResourceResolverLookup canResolve(String uri, String baseURI) {
+        if (uri == null) {
+            return null;
+        }
+        if (pattern.matcher(uri).matches() || (baseURI != null && pattern.matcher(baseURI).matches())) {
             return this;
         }
         return null;
     }
 
     @Override
-    public ResourceResolver newInstance(String uri) {
-        return new ResolverHttp(uri);
+    public ResourceResolver newInstance(String uri, String baseURI) {
+        return new ResolverHttp(uri, baseURI);
     }
 
     @Override
@@ -78,7 +83,13 @@ public class ResolverHttp implements Res
     @Override
     public InputStream getInputStreamFromExternalReference() throws XMLSecurityException {
         try {
-            URI tmp = new URI(uri);
+            URI tmp;
+            if (baseURI == null || "".equals(baseURI)) {
+                tmp = new URI(uri);
+            } else {
+                tmp = new URI(baseURI).resolve(uri);
+            }
+
             if (tmp.getFragment() != null) {
                 tmp = new URI(tmp.getScheme(), tmp.getSchemeSpecificPart(), null);
             }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverSameDocument.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverSameDocument.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverSameDocument.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverSameDocument.java Tue Jul 31 07:20:29 2012
@@ -47,7 +47,7 @@ public class ResolverSameDocument implem
     }
 
     @Override
-    public ResourceResolverLookup canResolve(String uri) {
+    public ResourceResolverLookup canResolve(String uri, String baseURI) {
         if (uri != null && (uri.isEmpty() || uri.charAt(0) == '#')) {
             if (uri.startsWith("#xpointer")) {
                 return null;
@@ -58,7 +58,7 @@ public class ResolverSameDocument implem
     }
 
     @Override
-    public ResourceResolver newInstance(String uri) {
+    public ResourceResolver newInstance(String uri, String baseURI) {
         return new ResolverSameDocument(uri);
     }
 

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverXPointer.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverXPointer.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverXPointer.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/resourceResolvers/ResolverXPointer.java Tue Jul 31 07:20:29 2012
@@ -74,7 +74,7 @@ public class ResolverXPointer implements
     }
 
     @Override
-    public ResourceResolverLookup canResolve(String uri) {
+    public ResourceResolverLookup canResolve(String uri, String baseURI) {
         if (uri != null && pattern.matcher(uri).find()) {
             return this;
         }
@@ -82,7 +82,7 @@ public class ResolverXPointer implements
     }
 
     @Override
-    public ResourceResolver newInstance(String uri) {
+    public ResourceResolver newInstance(String uri, String baseURI) {
         return new ResolverXPointer(uri);
     }
 

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java Tue Jul 31 07:20:29 2012
@@ -18,29 +18,28 @@
  */
 package org.apache.xml.security.stax.impl.transformer;
 
+import org.apache.commons.codec.binary.Base64InputStream;
 import org.apache.commons.codec.binary.Base64OutputStream;
-import org.apache.xml.security.stax.ext.Transformer;
+import org.apache.xml.security.stax.ext.XMLSecurityConstants;
 import org.apache.xml.security.stax.ext.XMLSecurityException;
 import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
+import org.apache.xml.security.stax.impl.processor.input.XMLEventReaderInputProcessor;
 
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
+import java.io.*;
 
 /**
  * @author $Author$
  * @version $Revision$ $Date$
  */
-public class TransformBase64Decode implements Transformer {
+public class TransformBase64Decode extends TransformIdentity {
 
-    private OutputStream outputStream;
+    private ChildOutputMethod childOutputMethod;
 
     @Override
     public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
-        this.outputStream = new Base64OutputStream(
+        super.setOutputStream(new Base64OutputStream(
                 new FilterOutputStream(outputStream) {
                     @Override
                     public void close() throws IOException {
@@ -48,16 +47,20 @@ public class TransformBase64Decode imple
                         super.flush();
                     }
                 },
-                false);
+                false)
+        );
     }
 
     @Override
-    public void setList(List list) throws XMLSecurityException {
-    }
-
-    @Override
-    public void setTransformer(Transformer transformer) throws XMLSecurityException {
-        throw new UnsupportedOperationException("Transformer not supported");
+    public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+        switch (forInput) {
+            case XMLSecEvent:
+                return XMLSecurityConstants.TransformMethod.InputStream;
+            case InputStream:
+                return XMLSecurityConstants.TransformMethod.InputStream;
+            default:
+                throw new IllegalArgumentException("Unsupported class " + forInput.name());
+        }
     }
 
     @Override
@@ -65,24 +68,130 @@ public class TransformBase64Decode imple
         int eventType = xmlSecEvent.getEventType();
         switch (eventType) {
             case XMLStreamConstants.CHARACTERS:
-                try {
+                if (getOutputStream() != null) {
+                    //we have an output stream
                     //encoding shouldn't matter here, because the data is Base64 encoded and is therefore in the ASCII range.
-                    outputStream.write(xmlSecEvent.asCharacters().getData().getBytes());
-                } catch (IOException e) {
-                    throw new XMLStreamException(e);
+                    try {
+                        getOutputStream().write(xmlSecEvent.asCharacters().getData().getBytes());
+                    } catch (IOException e) {
+                        throw new XMLStreamException(e);
+                    }
+                } else {
+                    //we have a child transformer
+                    if (childOutputMethod == null) {
+
+                        final XMLSecurityConstants.TransformMethod preferredChildTransformMethod =
+                                getTransformer().getPreferredTransformMethod(XMLSecurityConstants.TransformMethod.XMLSecEvent);
+
+                        switch (preferredChildTransformMethod) {
+                            case XMLSecEvent: {
+                                childOutputMethod = new ChildOutputMethod() {
+
+                                    private ByteArrayOutputStream byteArrayOutputStream;
+                                    private Base64OutputStream base64OutputStream;
+
+                                    @Override
+                                    public void transform(Object object) throws XMLStreamException {
+                                        if (base64OutputStream == null) {
+                                            byteArrayOutputStream = new ByteArrayOutputStream();
+                                            base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
+                                        }
+                                        try {
+                                            base64OutputStream.write(((byte[]) object));
+                                        } catch (IOException e) {
+                                            throw new XMLStreamException(e);
+                                        }
+                                    }
+
+                                    @Override
+                                    public void doFinal() throws XMLStreamException {
+                                        try {
+                                            base64OutputStream.close();
+                                        } catch (IOException e) {
+                                            throw new XMLStreamException(e);
+                                        }
+                                        XMLEventReaderInputProcessor xmlEventReaderInputProcessor
+                                                = new XMLEventReaderInputProcessor(
+                                                null,
+                                                getXmlInputFactory().createXMLStreamReader(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()))
+                                        );
+
+                                        try {
+                                            XMLSecEvent xmlSecEvent;
+                                            do {
+                                                xmlSecEvent = xmlEventReaderInputProcessor.processNextEvent(null);
+                                                getTransformer().transform(xmlSecEvent);
+                                            } while (xmlSecEvent.getEventType() != XMLStreamConstants.END_DOCUMENT);
+                                        } catch (XMLSecurityException e) {
+                                            throw new XMLStreamException(e);
+                                        }
+                                        getTransformer().doFinal();
+                                    }
+                                };
+                                break;
+                            }
+                            case InputStream: {
+                                childOutputMethod = new ChildOutputMethod() {
+
+                                    private ByteArrayOutputStream byteArrayOutputStream;
+                                    private Base64OutputStream base64OutputStream;
+
+                                    @Override
+                                    public void transform(Object object) throws XMLStreamException {
+                                        if (base64OutputStream == null) {
+                                            byteArrayOutputStream = new ByteArrayOutputStream();
+                                            base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
+                                        }
+                                        try {
+                                            base64OutputStream.write(((byte[]) object));
+                                        } catch (IOException e) {
+                                            throw new XMLStreamException(e);
+                                        }
+                                    }
+
+                                    @Override
+                                    public void doFinal() throws XMLStreamException {
+                                        try {
+                                            base64OutputStream.close();
+                                        } catch (IOException e) {
+                                            throw new XMLStreamException(e);
+                                        }
+                                        getTransformer().transform(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
+                                        getTransformer().doFinal();
+                                    }
+                                };
+                                break;
+                            }
+                        }
+                    }
+                    childOutputMethod.transform(xmlSecEvent.asCharacters().getData().getBytes());
                 }
                 break;
-            default:
-                return;
+        }
+    }
+
+    @Override
+    public void transform(InputStream inputStream) throws XMLStreamException {
+        if (getOutputStream() != null) {
+            super.transform(inputStream);
+        } else {
+            super.transform(new Base64InputStream(inputStream, false));
         }
     }
 
     @Override
     public void doFinal() throws XMLStreamException {
-        try {
-            outputStream.close();
-        } catch (IOException e) {
-            throw new XMLStreamException(e);
+        if (getOutputStream() != null) {
+            try {
+                getOutputStream().close();
+            } catch (IOException e) {
+                throw new XMLStreamException(e);
+            }
+        }
+        if (childOutputMethod != null) {
+            childOutputMethod.doFinal();
+        } else if (getTransformer() != null) {
+            getTransformer().doFinal();
         }
     }
 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java Tue Jul 31 07:20:29 2012
@@ -18,51 +18,37 @@
  */
 package org.apache.xml.security.stax.impl.transformer;
 
-import org.apache.xml.security.stax.ext.Transformer;
 import org.apache.xml.security.stax.ext.XMLSecurityConstants;
-import org.apache.xml.security.stax.ext.XMLSecurityException;
 import org.apache.xml.security.stax.ext.stax.XMLSecEndElement;
 import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
 import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
 
-import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
-import java.io.OutputStream;
-import java.util.List;
+import java.io.InputStream;
 
 /**
  * @author $Author$
  * @version $Revision$ $Date$
  */
-public class TransformEnvelopedSignature implements Transformer {
+public class TransformEnvelopedSignature extends TransformIdentity {
 
-    private static final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
-    private XMLEventWriter xmlEventWriter;
-    private Transformer transformer;
     private int curLevel = 0;
     private int sigElementLevel = -1;
 
     @Override
-    public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
-        try {
-            xmlEventWriter = xmlOutputFactory.createXMLEventWriter(outputStream);
-        } catch (XMLStreamException e) {
-            throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
+    public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+        switch (forInput) {
+            case XMLSecEvent:
+                return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+            case InputStream:
+                return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+            default:
+                throw new IllegalArgumentException("Unsupported class " + forInput.name());
         }
     }
 
     @Override
-    public void setList(List list) throws XMLSecurityException {
-    }
-
-    @Override
-    public void setTransformer(Transformer transformer) throws XMLSecurityException {
-        this.transformer = transformer;
-    }
-
-    @Override
     public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
         switch (xmlSecEvent.getEventType()) {
             case XMLStreamConstants.START_ELEMENT:
@@ -82,21 +68,13 @@ public class TransformEnvelopedSignature
                 curLevel--;
         }
         if (sigElementLevel == -1) {
-            if (xmlEventWriter != null) {
-                xmlEventWriter.add(xmlSecEvent);
-            } else if (transformer != null) {
-                transformer.transform(xmlSecEvent);
-            }
+            super.transform(xmlSecEvent);
         }
     }
 
     @Override
-    public void doFinal() throws XMLStreamException {
-        if (xmlEventWriter != null) {
-            xmlEventWriter.close();
-        }
-        if (transformer != null) {
-            transformer.doFinal();
-        }
+    public void transform(InputStream inputStream) throws XMLStreamException {
+        //there is no use case at the moment but can be implemented if needed
+        throw new UnsupportedOperationException("transform(InputStream) not supported");
     }
 }

Added: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java?rev=1367437&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java (added)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java Tue Jul 31 07:20:29 2012
@@ -0,0 +1,262 @@
+/**
+ * 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.xml.security.stax.impl.transformer;
+
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.xml.security.stax.ext.Transformer;
+import org.apache.xml.security.stax.ext.XMLSecurityConstants;
+import org.apache.xml.security.stax.ext.XMLSecurityException;
+import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
+import org.apache.xml.security.stax.impl.processor.input.XMLEventReaderInputProcessor;
+
+import javax.xml.stream.*;
+import java.io.*;
+import java.util.List;
+
+/**
+ * @author $Author: $
+ * @version $Revision: $ $Date: $
+ */
+public class TransformIdentity implements Transformer {
+
+    private static XMLOutputFactory xmlOutputFactory;
+    private static XMLInputFactory xmlInputFactory;
+    private OutputStream outputStream;
+    private XMLEventWriter xmlEventWriterForOutputStream;
+    private Transformer transformer;
+    private ChildOutputMethod childOutputMethod;
+    private List list;
+
+    protected static XMLOutputFactory getXmlOutputFactory() {
+        if (xmlOutputFactory == null) {
+            xmlOutputFactory = XMLOutputFactory.newInstance();
+        }
+        return xmlOutputFactory;
+    }
+
+    public static XMLInputFactory getXmlInputFactory() {
+        if (xmlInputFactory == null) {
+            xmlInputFactory = XMLInputFactory.newInstance();
+        }
+        return xmlInputFactory;
+    }
+
+    @Override
+    public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+        this.outputStream = outputStream;
+    }
+
+    protected OutputStream getOutputStream() {
+        return this.outputStream;
+    }
+
+    protected XMLEventWriter getXmlEventWriterForOutputStream() throws XMLStreamException {
+        if (this.xmlEventWriterForOutputStream != null) {
+            return this.xmlEventWriterForOutputStream;
+        }
+        if (this.outputStream != null) {
+            return this.xmlEventWriterForOutputStream = getXmlOutputFactory().createXMLEventWriter(new FilterOutputStream(outputStream) {
+                @Override
+                public void close() throws IOException {
+                    //do not close the parent output stream!
+                    super.flush();
+                }
+            });
+        }
+        return null;
+    }
+
+    @Override
+    public void setTransformer(Transformer transformer) throws XMLSecurityException {
+        this.transformer = transformer;
+    }
+
+    protected Transformer getTransformer() {
+        return transformer;
+    }
+
+    @Override
+    public void setList(List list) throws XMLSecurityException {
+        this.list = list;
+    }
+
+    protected List getList() {
+        return list;
+    }
+
+    @Override
+    public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+        switch (forInput) {
+            case XMLSecEvent:
+                return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+            case InputStream:
+                return XMLSecurityConstants.TransformMethod.InputStream;
+            default:
+                throw new IllegalArgumentException("Unsupported class " + forInput.name());
+        }
+    }
+
+    @Override
+    public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+        if (getXmlEventWriterForOutputStream() != null) {
+            //we have an output stream
+            getXmlEventWriterForOutputStream().add(xmlSecEvent);
+        } else {
+            //we have a child transformer
+            if (childOutputMethod == null) {
+
+                final XMLSecurityConstants.TransformMethod preferredChildTransformMethod =
+                        getTransformer().getPreferredTransformMethod(XMLSecurityConstants.TransformMethod.XMLSecEvent);
+
+                switch (preferredChildTransformMethod) {
+                    case XMLSecEvent: {
+                        childOutputMethod = new ChildOutputMethod() {
+
+                            @Override
+                            public void transform(Object object) throws XMLStreamException {
+                                getTransformer().transform((XMLSecEvent) object);
+                            }
+
+                            @Override
+                            public void doFinal() throws XMLStreamException {
+                                getTransformer().doFinal();
+                            }
+                        };
+                        break;
+                    }
+                    case InputStream: {
+                        childOutputMethod = new ChildOutputMethod() {
+
+                            private ByteArrayOutputStream baos;
+                            private XMLEventWriter xmlEventWriter;
+
+                            @Override
+                            public void transform(Object object) throws XMLStreamException {
+                                if (xmlEventWriter == null) {
+                                    baos = new ByteArrayOutputStream();
+                                    xmlEventWriter = getXmlOutputFactory().createXMLEventWriter(baos);
+                                }
+
+                                xmlEventWriter.add((XMLSecEvent) object);
+                            }
+
+                            @Override
+                            public void doFinal() throws XMLStreamException {
+                                xmlEventWriter.close();
+                                getTransformer().transform(new ByteArrayInputStream(baos.toByteArray()));
+                                getTransformer().doFinal();
+                            }
+                        };
+                        break;
+                    }
+                }
+            }
+            childOutputMethod.transform(xmlSecEvent);
+        }
+    }
+
+    @Override
+    public void transform(final InputStream inputStream) throws XMLStreamException {
+        if (getOutputStream() != null) {
+            //we have an output stream
+            try {
+                IOUtils.copy(inputStream, getOutputStream());
+            } catch (IOException e) {
+                throw new XMLStreamException(e);
+            }
+        } else {
+            //we have a child transformer
+            if (childOutputMethod == null) {
+
+                final XMLSecurityConstants.TransformMethod preferredChildTransformMethod =
+                        getTransformer().getPreferredTransformMethod(XMLSecurityConstants.TransformMethod.InputStream);
+
+                switch (preferredChildTransformMethod) {
+                    case XMLSecEvent: {
+                        childOutputMethod = new ChildOutputMethod() {
+
+                            private XMLEventReaderInputProcessor xmlEventReaderInputProcessor;
+
+                            @Override
+                            public void transform(Object object) throws XMLStreamException {
+                                if (xmlEventReaderInputProcessor == null) {
+                                    xmlEventReaderInputProcessor = new XMLEventReaderInputProcessor(
+                                            null,
+                                            getXmlInputFactory().createXMLStreamReader(inputStream)
+                                    );
+                                }
+                                try {
+                                    XMLSecEvent xmlSecEvent;
+                                    do {
+                                        xmlSecEvent = xmlEventReaderInputProcessor.processNextEvent(null);
+                                        getTransformer().transform(xmlSecEvent);
+                                    } while (xmlSecEvent.getEventType() != XMLStreamConstants.END_DOCUMENT);
+                                } catch (XMLSecurityException e) {
+                                    throw new XMLStreamException(e);
+                                }
+                            }
+
+                            @Override
+                            public void doFinal() throws XMLStreamException {
+                                getTransformer().doFinal();
+                            }
+                        };
+                        break;
+                    }
+                    case InputStream: {
+                        childOutputMethod = new ChildOutputMethod() {
+
+                            @Override
+                            public void transform(Object object) throws XMLStreamException {
+                                getTransformer().transform(inputStream);
+                            }
+
+                            @Override
+                            public void doFinal() throws XMLStreamException {
+                                getTransformer().doFinal();
+                            }
+
+                        };
+                        break;
+                    }
+                }
+            }
+            childOutputMethod.transform(inputStream);
+        }
+    }
+
+    @Override
+    public void doFinal() throws XMLStreamException {
+        if (xmlEventWriterForOutputStream != null) {
+            xmlEventWriterForOutputStream.close();
+        }
+        if (childOutputMethod != null) {
+            childOutputMethod.doFinal();
+        } else if (transformer != null) {
+            transformer.doFinal();
+        }
+    }
+
+    interface ChildOutputMethod {
+
+        void transform(Object object) throws XMLStreamException;
+
+        void doFinal() throws XMLStreamException;
+    }
+}

Propchange: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java Tue Jul 31 07:20:29 2012
@@ -20,23 +20,23 @@ package org.apache.xml.security.stax.imp
 
 import org.apache.xml.security.c14n.implementations.UtfHelpper;
 import org.apache.xml.security.stax.ext.Transformer;
+import org.apache.xml.security.stax.ext.XMLSecurityConstants;
 import org.apache.xml.security.stax.ext.XMLSecurityException;
 import org.apache.xml.security.stax.ext.XMLSecurityUtils;
 import org.apache.xml.security.stax.ext.stax.*;
+import org.apache.xml.security.stax.impl.processor.input.XMLEventReaderInputProcessor;
+import org.apache.xml.security.stax.impl.transformer.TransformIdentity;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Serializable;
+import javax.xml.stream.*;
+import java.io.*;
 import java.util.*;
 
 /**
  * @author $Author$
  * @version $Revision$ $Date$
  */
-public abstract class CanonicalizerBase implements Transformer {
+public abstract class CanonicalizerBase extends TransformIdentity {
 
     protected static final byte[] _END_PI = {'?', '>'};
     protected static final byte[] _BEGIN_PI = {'<', '?'};
@@ -64,8 +64,6 @@ public abstract class CanonicalizerBase 
         NODE_AFTER_DOCUMENT_ELEMENT
     }
 
-    private OutputStream outputStream;
-
     private static final Map<String, byte[]> cache = new WeakHashMap<String, byte[]>();
     private final C14NStack outputStack = new C14NStack();
     private boolean includeComments = false;
@@ -78,11 +76,6 @@ public abstract class CanonicalizerBase 
     }
 
     @Override
-    public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
-        this.outputStream = outputStream;
-    }
-
-    @Override
     @SuppressWarnings("unchecked")
     public void setList(List list) throws XMLSecurityException {
         this.inclusiveNamespaces = prefixList2Set(list);
@@ -90,7 +83,9 @@ public abstract class CanonicalizerBase 
 
     @Override
     public void setTransformer(Transformer transformer) throws XMLSecurityException {
-        throw new UnsupportedOperationException("Transformer not supported");
+        //we support only transformers which takes an InputStream otherwise we will break the C14N
+        setOutputStream(new ByteArrayOutputStream());
+        super.setTransformer(transformer);
     }
 
     public static SortedSet<String> prefixList2Set(List<String> inclusiveNamespaces) {
@@ -248,8 +243,23 @@ public abstract class CanonicalizerBase 
         return utilizedAttributes;
     }
 
+    @Override
+    public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+        switch (forInput) {
+            case XMLSecEvent:
+                return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+            case InputStream:
+                return XMLSecurityConstants.TransformMethod.InputStream;
+            default:
+                throw new IllegalArgumentException("Unsupported class " + forInput.name());
+        }
+    }
+
+    @Override
     public void transform(final XMLSecEvent xmlSecEvent) throws XMLStreamException {
         try {
+            OutputStream outputStream = getOutputStream();
+
             switch (xmlSecEvent.getEventType()) {
                 case XMLStreamConstants.START_ELEMENT:
 
@@ -356,21 +366,21 @@ public abstract class CanonicalizerBase 
 
                     break;
                 case XMLStreamConstants.PROCESSING_INSTRUCTION:
-                    outputPItoWriter(((XMLSecProcessingInstruction) xmlSecEvent), this.outputStream, currentDocumentLevel);
+                    outputPItoWriter(((XMLSecProcessingInstruction) xmlSecEvent), outputStream, currentDocumentLevel);
                     break;
                 case XMLStreamConstants.CHARACTERS:
                     if (currentDocumentLevel == DocumentLevel.NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT) {
-                        outputTextToWriter(xmlSecEvent.asCharacters().getData(), this.outputStream);
+                        outputTextToWriter(xmlSecEvent.asCharacters().getData(), outputStream);
                     }
                     break;
                 case XMLStreamConstants.COMMENT:
                     if (includeComments) {
-                        outputCommentToWriter(((XMLSecComment) xmlSecEvent), this.outputStream, currentDocumentLevel);
+                        outputCommentToWriter(((XMLSecComment) xmlSecEvent), outputStream, currentDocumentLevel);
                     }
                     break;
                 case XMLStreamConstants.SPACE:
                     if (currentDocumentLevel == DocumentLevel.NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT) {
-                        outputTextToWriter(xmlSecEvent.asCharacters().getData(), this.outputStream);
+                        outputTextToWriter(xmlSecEvent.asCharacters().getData(), outputStream);
                     }
                     break;
                 case XMLStreamConstants.START_DOCUMENT:
@@ -385,7 +395,7 @@ public abstract class CanonicalizerBase 
                 case XMLStreamConstants.DTD:
                     break;
                 case XMLStreamConstants.CDATA:
-                    outputTextToWriter(xmlSecEvent.asCharacters().getData(), this.outputStream);
+                    outputTextToWriter(xmlSecEvent.asCharacters().getData(), outputStream);
                     break;
                 case XMLStreamConstants.NAMESPACE:
                     throw new XMLStreamException("illegal event :" + XMLSecurityUtils.getXMLEventAsString(xmlSecEvent));
@@ -400,8 +410,28 @@ public abstract class CanonicalizerBase 
     }
 
     @Override
+    public void transform(InputStream inputStream) throws XMLStreamException {
+        XMLEventReaderInputProcessor xmlEventReaderInputProcessor =
+                new XMLEventReaderInputProcessor(null, getXmlInputFactory().createXMLStreamReader(inputStream));
+
+        try {
+            XMLSecEvent xmlSecEvent;
+            do {
+                xmlSecEvent = xmlEventReaderInputProcessor.processNextEvent(null);
+                this.transform(xmlSecEvent);
+            } while (xmlSecEvent.getEventType() != XMLStreamConstants.END_DOCUMENT);
+        } catch (XMLSecurityException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    @Override
     public void doFinal() throws XMLStreamException {
-        //nothing to do here
+        if (getTransformer() != null) {
+            ByteArrayOutputStream baos = (ByteArrayOutputStream)getOutputStream();
+            getTransformer().transform(new ByteArrayInputStream(baos.toByteArray()));
+            getTransformer().doFinal();
+        }
     }
 
     protected static void outputAttrToWriter(final String name, final String value, final OutputStream writer,

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/encryption/DecryptionTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/encryption/DecryptionTest.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/encryption/DecryptionTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/encryption/DecryptionTest.java Tue Jul 31 07:20:29 2012
@@ -352,7 +352,7 @@ public class DecryptionTest extends org.
         NodeList nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         Assert.assertEquals(nodeList.getLength(), 0);
         
-        XMLUtils.outputDOM(document, System.out);
+        //XMLUtils.outputDOM(document, System.out);
         
         // Convert Document to a Stream Reader
         javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();