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/10/16 16:01:41 UTC

svn commit: r1398806 - in /santuario/xml-security-java/trunk/src: main/java/org/apache/xml/security/c14n/implementations/ main/java/org/apache/xml/security/stax/ext/ main/java/org/apache/xml/security/stax/ext/stax/ main/java/org/apache/xml/security/sta...

Author: giger
Date: Tue Oct 16 14:01:40 2012
New Revision: 1398806

URL: http://svn.apache.org/viewvc?rev=1398806&view=rev
Log:
SANTUARIO-346 - further performance update.

Modified:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/UtfHelpper.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecCharacters.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecEventFactory.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityEventWriter.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamReader.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamWriter.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecCharactersImpl.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer11.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer20010315_Excl.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/XMLSecurityEventWriterTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XmlReaderToWriter.java

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/UtfHelpper.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/UtfHelpper.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/UtfHelpper.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/c14n/implementations/UtfHelpper.java Tue Oct 16 14:01:40 2012
@@ -176,15 +176,4 @@ public final class UtfHelpper {
         }
         return result;
     }
-
-    public static void writeUTF8String(final String str, final OutputStream out, Map<String, byte[]> cache)
-            throws IOException {
-
-        byte[] result = cache.get(str);
-        if (result == null) {
-            result = str.getBytes("UTF-8");
-            cache.put(str, result);
-        }
-        out.write(result);
-    }
 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java Tue Oct 16 14:01:40 2012
@@ -205,10 +205,19 @@ public abstract class AbstractOutputProc
         outputAsEvent(outputProcessorChain, createCharacters(characters));
     }
 
+    public void createCharactersAndOutputAsEvent(OutputProcessorChain outputProcessorChain, char[] text)
+            throws XMLStreamException, XMLSecurityException {
+        outputAsEvent(outputProcessorChain, createCharacters(text));
+    }
+
     public XMLSecCharacters createCharacters(String characters) {
         return XMLSecEventFactory.createXmlSecCharacters(characters);
     }
 
+    public XMLSecCharacters createCharacters(char[] text) {
+        return XMLSecEventFactory.createXmlSecCharacters(text);
+    }
+
     public XMLSecAttribute createAttribute(QName attribute, String attributeValue) {
         return XMLSecEventFactory.createXMLSecAttribute(attribute, attributeValue);
     }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecCharacters.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecCharacters.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecCharacters.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecCharacters.java Tue Oct 16 14:01:40 2012
@@ -28,4 +28,6 @@ public interface XMLSecCharacters extend
 
     @Override
     XMLSecCharacters asCharacters();
+
+    char[] getText();
 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecEventFactory.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecEventFactory.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecEventFactory.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/stax/XMLSecEventFactory.java Tue Oct 16 14:01:40 2012
@@ -26,6 +26,7 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.events.EntityDeclaration;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
@@ -65,7 +66,9 @@ public class XMLSecEventFactory {
             case XMLStreamConstants.PROCESSING_INSTRUCTION:
                 return new XMLSecProcessingInstructionImpl(xmlStreamReader.getPITarget(), xmlStreamReader.getPIData(), parentXMLSecStartElement);
             case XMLStreamConstants.CHARACTERS:
-                return new XMLSecCharactersImpl(xmlStreamReader.getText(), false, false, xmlStreamReader.isWhiteSpace(), parentXMLSecStartElement);
+                char[] text = new char[xmlStreamReader.getTextLength()];
+                xmlStreamReader.getTextCharacters(0, text, 0, xmlStreamReader.getTextLength());
+                return new XMLSecCharactersImpl(text, false, false, xmlStreamReader.isWhiteSpace(), parentXMLSecStartElement);
             case XMLStreamConstants.COMMENT:
                 return new XMLSecCommentImpl(xmlStreamReader.getText(), parentXMLSecStartElement);
             case XMLStreamConstants.SPACE:
@@ -117,6 +120,14 @@ public class XMLSecEventFactory {
         return new XMLSecCharactersImpl(data, false, false, false, null);
     }
 
+    public static XMLSecCharacters createXmlSecCharacters(char[] text) {
+        return new XMLSecCharactersImpl(text, false, false, false, null);
+    }
+
+    public static XMLSecCharacters createXmlSecCharacters(char[] text, int off, int len) {
+        return new XMLSecCharactersImpl(Arrays.copyOfRange(text, off, off + len), false, false, false, null);
+    }
+
     public static XMLSecComment createXMLSecComment(String data) {
         return new XMLSecCommentImpl(data, null);
     }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityEventWriter.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityEventWriter.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityEventWriter.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityEventWriter.java Tue Oct 16 14:01:40 2012
@@ -18,11 +18,13 @@
  */
 package org.apache.xml.security.stax.impl;
 
+import org.apache.xml.security.stax.ext.stax.*;
+
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.*;
 import javax.xml.stream.events.*;
-import java.util.Iterator;
+import java.util.List;
 
 /**
  * @author $Author$
@@ -37,22 +39,27 @@ public class XMLSecurityEventWriter impl
     }
 
     public void add(XMLEvent event) throws XMLStreamException {
-        switch (event.getEventType()) {
+        if (!(event instanceof XMLSecEvent)) {
+            throw new IllegalArgumentException("XMLEvent must be an instance of XMLSecEvent");
+        }
+
+        XMLSecEvent xmlSecEvent = (XMLSecEvent)event;
+        switch (xmlSecEvent.getEventType()) {
             case XMLStreamConstants.START_ELEMENT:
-                StartElement startElement = event.asStartElement();
-                QName n = startElement.getName();
+                XMLSecStartElement xmlSecStartElement = xmlSecEvent.asStartElement();
+                QName n = xmlSecStartElement.getName();
                 this.xmlStreamWriter.writeStartElement(n.getPrefix(), n.getLocalPart(), n.getNamespaceURI());
 
-                @SuppressWarnings("unchecked")
-                Iterator<Namespace> namespaceIterator = startElement.getNamespaces();
-                while (namespaceIterator.hasNext()) {
-                    add(namespaceIterator.next());
+                List<XMLSecNamespace> xmlSecNamespaces = xmlSecStartElement.getOnElementDeclaredNamespaces();
+                for (int i = 0; i < xmlSecNamespaces.size(); i++) {
+                    Namespace namespace = xmlSecNamespaces.get(i);
+                    add(namespace);
                 }
 
-                @SuppressWarnings("unchecked")
-                Iterator<Attribute> attributeIterator = startElement.getAttributes();
-                while (attributeIterator.hasNext()) {
-                    add(attributeIterator.next());
+                List<XMLSecAttribute> xmlSecAttributes = xmlSecStartElement.getOnElementDeclaredAttributes();
+                for (int i = 0; i < xmlSecAttributes.size(); i++) {
+                    XMLSecAttribute xmlSecAttribute = xmlSecAttributes.get(i);
+                    add(xmlSecAttribute);
                 }
                 break;
 
@@ -61,25 +68,26 @@ public class XMLSecurityEventWriter impl
                 break;
 
             case XMLStreamConstants.PROCESSING_INSTRUCTION:
-                ProcessingInstruction pi = (ProcessingInstruction) event;
+                ProcessingInstruction pi = (ProcessingInstruction) xmlSecEvent;
                 this.xmlStreamWriter.writeProcessingInstruction(pi.getTarget(), pi.getData());
                 break;
 
             case XMLStreamConstants.CHARACTERS:
-                Characters characters = event.asCharacters();
-                if (characters.isCData()) {
-                    this.xmlStreamWriter.writeCData(characters.getData());
+                XMLSecCharacters characters = xmlSecEvent.asCharacters();
+                if (!characters.isCData()) {
+                    final char[] text = characters.getText();
+                    this.xmlStreamWriter.writeCharacters(text, 0, text.length);
                 } else {
-                    this.xmlStreamWriter.writeCharacters(characters.getData());
+                    this.xmlStreamWriter.writeCData(characters.getData());
                 }
                 break;
 
             case XMLStreamConstants.COMMENT:
-                this.xmlStreamWriter.writeComment(((Comment) event).getText());
+                this.xmlStreamWriter.writeComment(((Comment) xmlSecEvent).getText());
                 break;
 
             case XMLStreamConstants.START_DOCUMENT:
-                StartDocument startDocument = (StartDocument) event;
+                StartDocument startDocument = (StartDocument) xmlSecEvent;
                 if (!startDocument.encodingSet()) {
                     this.xmlStreamWriter.writeStartDocument(startDocument.getVersion());
                 } else {
@@ -92,25 +100,25 @@ public class XMLSecurityEventWriter impl
                 break;
 
             case XMLStreamConstants.ENTITY_REFERENCE:
-                this.xmlStreamWriter.writeEntityRef(((EntityReference) event).getName());
+                this.xmlStreamWriter.writeEntityRef(((EntityReference) xmlSecEvent).getName());
                 break;
 
             case XMLStreamConstants.ATTRIBUTE:
-                Attribute attribute = (Attribute) event;
+                Attribute attribute = (Attribute) xmlSecEvent;
                 QName name = attribute.getName();
                 this.xmlStreamWriter.writeAttribute(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), attribute.getValue());
                 break;
 
             case XMLStreamConstants.DTD:
-                this.xmlStreamWriter.writeDTD(((DTD) event).getDocumentTypeDeclaration());
+                this.xmlStreamWriter.writeDTD(((DTD) xmlSecEvent).getDocumentTypeDeclaration());
                 break;
 
             case XMLStreamConstants.CDATA:
-                this.xmlStreamWriter.writeCData(event.asCharacters().getData());
+                this.xmlStreamWriter.writeCData(xmlSecEvent.asCharacters().getData());
                 break;
 
             case XMLStreamConstants.NAMESPACE:
-                Namespace ns = (Namespace) event;
+                Namespace ns = (Namespace) xmlSecEvent;
                 this.xmlStreamWriter.writeNamespace(ns.getPrefix(), ns.getNamespaceURI());
                 break;
 

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamReader.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamReader.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamReader.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamReader.java Tue Oct 16 14:01:40 2012
@@ -394,7 +394,7 @@ public class XMLSecurityStreamReader imp
             case CDATA:
             case SPACE:
             case CHARACTERS:
-                return xmlSecEvent.asCharacters().getData().toCharArray();
+                return xmlSecEvent.asCharacters().getText();
             default:
                 throw new IllegalStateException("Current state not TEXT");
         }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamWriter.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamWriter.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamWriter.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/XMLSecurityStreamWriter.java Tue Oct 16 14:01:40 2012
@@ -420,7 +420,7 @@ public class XMLSecurityStreamWriter imp
 
     public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
         outputOpenStartElement();
-        chainProcessEvent(XMLSecEventFactory.createXmlSecCharacters(new String(text, start, len)));
+        chainProcessEvent(XMLSecEventFactory.createXmlSecCharacters(text, start, len));
     }
 
     public String getPrefix(String uri) throws XMLStreamException {

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java Tue Oct 16 14:01:40 2012
@@ -230,6 +230,7 @@ public abstract class AbstractDecryptInp
                         decryptedEventReaderInputProcessor);
 
                 Thread thread = new Thread(decryptionThread);
+                thread.setPriority(Thread.NORM_PRIORITY + 1);
                 thread.setName("decrypting thread");
                 //when an exception in the decryption thread occurs, we want to forward them:
                 thread.setUncaughtExceptionHandler(decryptedEventReaderInputProcessor);
@@ -748,8 +749,8 @@ public abstract class AbstractDecryptInp
                             //this must be the CipherValue EndElement.                            
                             break exitLoop;
                         case XMLStreamConstants.CHARACTERS:
-                            final String data = xmlSecEvent.asCharacters().getData();
-                            outputStreamWriter.write(data, 0, data.length());
+                            final char[] data = xmlSecEvent.asCharacters().getText();
+                            outputStreamWriter.write(data);
                             break;
                         default:
                             throw new XMLSecurityException(

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java Tue Oct 16 14:01:40 2012
@@ -27,6 +27,7 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.stax.ext.XMLSecurityConstants;
 import org.apache.xml.security.stax.ext.stax.*;
 import org.apache.xml.security.stax.impl.EncryptionPartDef;
+import org.apache.xml.security.stax.impl.XMLSecurityEventWriter;
 import org.apache.xml.security.stax.impl.util.TrimmerOutputStream;
 
 import javax.crypto.Cipher;
@@ -133,7 +134,7 @@ public abstract class AbstractEncryptOut
                 //Should internally generate an IV
                 byte[] iv = symmetricCipher.getIV();
 
-                characterEventGeneratorOutputStream = new CharacterEventGeneratorOutputStream(getEncoding());
+                characterEventGeneratorOutputStream = new CharacterEventGeneratorOutputStream();
                 Base64OutputStream base64EncoderStream =
                         new Base64OutputStream(characterEventGeneratorOutputStream, true, 0, null);
                 base64EncoderStream.write(iv);
@@ -153,7 +154,7 @@ public abstract class AbstractEncryptOut
 
                 //we create a new StAX writer for optimized namespace writing.
                 //spec says (4.2): "The cleartext octet sequence obtained in step 3 is interpreted as UTF-8 encoded character data."
-                xmlEventWriter = XMLSecurityConstants.xmlOutputFactory.createXMLEventWriter(cipherOutputStream, "UTF-8");
+                xmlEventWriter = new XMLSecurityEventWriter(XMLSecurityConstants.xmlOutputFactory.createXMLStreamWriter(cipherOutputStream, "UTF-8"));
                 //we have to output a fake element to workaround text-only encryption:
                 xmlEventWriter.add(wrapperStartElement);
             } catch (NoSuchPaddingException e) {
@@ -359,11 +360,6 @@ public abstract class AbstractEncryptOut
     public class CharacterEventGeneratorOutputStream extends OutputStream {
 
         private final Deque<XMLSecCharacters> charactersBuffer = new ArrayDeque<XMLSecCharacters>();
-        private final String encoding;
-
-        public CharacterEventGeneratorOutputStream(String encoding) {
-            this.encoding = encoding;
-        }
 
         public Deque<XMLSecCharacters> getCharactersBuffer() {
             return charactersBuffer;
@@ -371,17 +367,25 @@ public abstract class AbstractEncryptOut
 
         @Override
         public void write(int b) throws IOException {
-            charactersBuffer.offer(createCharacters(new String(new byte[]{((byte) b)}, encoding)));
+            charactersBuffer.offer(createCharacters(new char[]{(char)b}));
         }
 
         @Override
         public void write(byte[] b) throws IOException {
-            charactersBuffer.offer(createCharacters(new String(b, encoding)));
+            charactersBuffer.offer(createCharacters(byteToCharArray(b, 0, b.length)));
         }
 
         @Override
         public void write(byte[] b, int off, int len) throws IOException {
-            charactersBuffer.offer(createCharacters(new String(b, off, len, encoding)));
+            charactersBuffer.offer(createCharacters(byteToCharArray(b, off, len)));
+        }
+    }
+
+    private char[] byteToCharArray(byte[]  bytes, int off, int len) {
+        char[] chars = new char[len];
+        for (int i = off; i < len; i++) {
+            chars[i] = (char)bytes[i];
         }
+        return chars;
     }
 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java Tue Oct 16 14:01:40 2012
@@ -45,7 +45,7 @@ public class FinalOutputProcessor extend
         super();
         setPhase(XMLSecurityConstants.Phase.POSTPROCESSING);
         try {
-            xmlEventWriter = XMLSecurityConstants.xmlOutputFactory.createXMLEventWriter(outputStream, encoding);
+            xmlEventWriter = new XMLSecurityEventWriter(XMLSecurityConstants.xmlOutputFactory.createXMLStreamWriter(outputStream, encoding));
         } catch (XMLStreamException e) {
             throw new XMLSecurityException(e);
         }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecCharactersImpl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecCharactersImpl.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecCharactersImpl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecCharactersImpl.java Tue Oct 16 14:01:40 2012
@@ -29,7 +29,8 @@ import javax.xml.stream.XMLStreamConstan
  */
 public class XMLSecCharactersImpl extends XMLSecEventBaseImpl implements XMLSecCharacters {
 
-    private final String data;
+    private String data;
+    private char[] text;
     private final boolean isCData;
     private final boolean isIgnorableWhiteSpace;
     private final boolean isWhiteSpace;
@@ -42,11 +43,29 @@ public class XMLSecCharactersImpl extend
         setParentXMLSecStartElement(parentXmlSecStartElement);
     }
 
+    public XMLSecCharactersImpl(char[] text, boolean isCData, boolean isIgnorableWhiteSpace, boolean isWhiteSpace, XMLSecStartElement parentXmlSecStartElement) {
+        this.text = text;
+        this.isCData = isCData;
+        this.isIgnorableWhiteSpace = isIgnorableWhiteSpace;
+        this.isWhiteSpace = isWhiteSpace;
+        setParentXMLSecStartElement(parentXmlSecStartElement);
+    }
+
     @Override
     public String getData() {
+        if (data == null) {
+            data = new String(text);
+        }
         return data;
     }
 
+    public char[] getText() {
+        if (text == null) {
+            text = data.toCharArray();
+        }
+        return text;
+    }
+
     @Override
     public boolean isWhiteSpace() {
         return isWhiteSpace;

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer11.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer11.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer11.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer11.java Tue Oct 16 14:01:40 2012
@@ -22,10 +22,7 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
 
 import javax.xml.namespace.QName;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.util.*;
 
 /**
  * @author $Author$
@@ -37,10 +34,10 @@ public class Canonicalizer11 extends Can
     }
 
     @Override
-    protected SortedSet<XMLSecAttribute> getInitialUtilizedAttributes(final XMLSecStartElement xmlSecStartElement,
+    protected List<XMLSecAttribute> getInitialUtilizedAttributes(final XMLSecStartElement xmlSecStartElement,
                                                                       final C14NStack outputStack) {
 
-        SortedSet<XMLSecAttribute> utilizedAttributes = emptySortedSet();
+        List<XMLSecAttribute> utilizedAttributes = Collections.emptyList();
 
         List<XMLSecAttribute> visibleAttributes = new ArrayList<XMLSecAttribute>();
         xmlSecStartElement.getAttributesFromCurrentScope(visibleAttributes);
@@ -58,8 +55,8 @@ public class Canonicalizer11 extends Can
             if (outputStack.containsOnStack(comparableAttribute) != null) {
                 continue;
             }
-            if (utilizedAttributes == (Object) emptySortedSet()) {
-                utilizedAttributes = new TreeSet<XMLSecAttribute>();
+            if (utilizedAttributes == (Object)Collections.emptyList()) {
+                utilizedAttributes = new ArrayList<XMLSecAttribute>(2);
             }
             utilizedAttributes.add(comparableAttribute);
             outputStack.peek().add(comparableAttribute);
@@ -74,8 +71,8 @@ public class Canonicalizer11 extends Can
             if (XML.equals(attributeName.getPrefix())) {
                 continue;
             }
-            if (utilizedAttributes == (Object) emptySortedSet()) {
-                utilizedAttributes = new TreeSet<XMLSecAttribute>();
+            if (utilizedAttributes == (Object)Collections.emptyList()) {
+                utilizedAttributes = new ArrayList<XMLSecAttribute>(2);
             }
             utilizedAttributes.add(comparableAttribute);
         }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer20010315_Excl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer20010315_Excl.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer20010315_Excl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/Canonicalizer20010315_Excl.java Tue Oct 16 14:01:40 2012
@@ -22,9 +22,7 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.stax.ext.stax.XMLSecNamespace;
 import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
 
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.util.*;
 
 /**
  * @author $Author$
@@ -37,15 +35,15 @@ public abstract class Canonicalizer20010
     }
 
     @Override
-    protected SortedSet<XMLSecNamespace> getCurrentUtilizedNamespaces(final XMLSecStartElement xmlSecStartElement,
+    protected List<XMLSecNamespace> getCurrentUtilizedNamespaces(final XMLSecStartElement xmlSecStartElement,
                                                                       final C14NStack outputStack) {
-        SortedSet<XMLSecNamespace> utilizedNamespaces = emptySortedSet();
+        List<XMLSecNamespace> utilizedNamespaces = Collections.emptyList();
 
         XMLSecNamespace elementNamespace = xmlSecStartElement.getElementNamespace();
         final XMLSecNamespace found = (XMLSecNamespace) outputStack.containsOnStack(elementNamespace);
         //found means the prefix matched. so check the ns further
         if (found == null || found.getNamespaceURI() == null || !found.getNamespaceURI().equals(elementNamespace.getNamespaceURI())) {
-            utilizedNamespaces = new TreeSet<XMLSecNamespace>();
+            utilizedNamespaces = new ArrayList<XMLSecNamespace>(2);
             utilizedNamespaces.add(elementNamespace);
             outputStack.peek().add(elementNamespace);
         }
@@ -65,8 +63,8 @@ public abstract class Canonicalizer20010
             if (resultNamespace == null || resultNamespace.getNamespaceURI() == null
                     || !resultNamespace.getNamespaceURI().equals(attributeNamespace.getNamespaceURI())) {
 
-                if (utilizedNamespaces == (Object) emptySortedSet()) {
-                    utilizedNamespaces = new TreeSet<XMLSecNamespace>();
+                if (utilizedNamespaces == (Object)Collections.emptyList()) {
+                    utilizedNamespaces = new ArrayList<XMLSecNamespace>(2);
                 }
                 utilizedNamespaces.add(attributeNamespace);
                 outputStack.peek().add(attributeNamespace);
@@ -77,21 +75,21 @@ public abstract class Canonicalizer20010
     }
 
     @Override
-    protected SortedSet<XMLSecNamespace> getInitialUtilizedNamespaces(final XMLSecStartElement xmlSecStartElement,
+    protected List<XMLSecNamespace> getInitialUtilizedNamespaces(final XMLSecStartElement xmlSecStartElement,
                                                                       final C14NStack outputStack) {
         return getCurrentUtilizedNamespaces(xmlSecStartElement, outputStack);
     }
 
     @Override
-    protected SortedSet<XMLSecAttribute> getInitialUtilizedAttributes(final XMLSecStartElement xmlSecStartElement,
+    protected List<XMLSecAttribute> getInitialUtilizedAttributes(final XMLSecStartElement xmlSecStartElement,
                                                                       final C14NStack outputStack) {
-        SortedSet<XMLSecAttribute> utilizedAttributes = emptySortedSet();
+        List<XMLSecAttribute> utilizedAttributes = Collections.emptyList();
         @SuppressWarnings("unchecked")
         List<XMLSecAttribute> comparableAttributes = xmlSecStartElement.getOnElementDeclaredAttributes();
         for (int i = 0; i < comparableAttributes.size(); i++) {
             XMLSecAttribute comparableAttribute = comparableAttributes.get(i);
-            if (utilizedAttributes == (Object) emptySortedSet()) {
-                utilizedAttributes = new TreeSet<XMLSecAttribute>();
+            if (utilizedAttributes == (Object)Collections.emptyList()) {
+                utilizedAttributes = new ArrayList<XMLSecAttribute>(2);
             }
             utilizedAttributes.add(comparableAttribute);
         }

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=1398806&r1=1398805&r2=1398806&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 Oct 16 14:01:40 2012
@@ -58,7 +58,6 @@ public abstract class CanonicalizerBase 
     protected static final String XML = "xml";
     protected static final String XMLNS = "xmlns";
     protected static final char DOUBLEPOINT = ':';
-    protected static final String XMLNS_DOUBLEPOINT = XMLNS + DOUBLEPOINT;
 
     private enum DocumentLevel {
         NODE_BEFORE_DOCUMENT_ELEMENT,
@@ -109,10 +108,10 @@ public abstract class CanonicalizerBase 
         return prefixes;
     }
 
-    protected SortedSet<XMLSecNamespace> getCurrentUtilizedNamespaces(final XMLSecStartElement xmlSecStartElement,
+    protected List<XMLSecNamespace> getCurrentUtilizedNamespaces(final XMLSecStartElement xmlSecStartElement,
                                                                       final C14NStack outputStack) {
 
-        SortedSet<XMLSecNamespace> utilizedNamespaces = emptySortedSet();
+        List<XMLSecNamespace> utilizedNamespaces = Collections.emptyList();
 
         XMLSecNamespace elementNamespace = xmlSecStartElement.getElementNamespace();
         final XMLSecNamespace found = (XMLSecNamespace) outputStack.containsOnStack(elementNamespace);
@@ -120,7 +119,7 @@ public abstract class CanonicalizerBase 
         if (found == null || found.getNamespaceURI() == null
                 || !found.getNamespaceURI().equals(elementNamespace.getNamespaceURI())) {
 
-            utilizedNamespaces = new TreeSet<XMLSecNamespace>();
+            utilizedNamespaces = new ArrayList<XMLSecNamespace>(2);
             utilizedNamespaces.add(elementNamespace);
             outputStack.peek().add(elementNamespace);
         }
@@ -135,8 +134,8 @@ public abstract class CanonicalizerBase 
                 continue;
             }
 
-            if (utilizedNamespaces == (Object) emptySortedSet()) {
-                utilizedNamespaces = new TreeSet<XMLSecNamespace>();
+            if (utilizedNamespaces == (Object)Collections.emptyList()) {
+                utilizedNamespaces = new ArrayList<XMLSecNamespace>(2);
             }
             utilizedNamespaces.add(comparableNamespace);
             outputStack.peek().add(comparableNamespace);
@@ -157,8 +156,8 @@ public abstract class CanonicalizerBase 
             if (resultNamespace == null || resultNamespace.getNamespaceURI() == null
                     || !resultNamespace.getNamespaceURI().equals(attributeNamespace.getNamespaceURI())) {
 
-                if (utilizedNamespaces == (Object) emptySortedSet()) {
-                    utilizedNamespaces = new TreeSet<XMLSecNamespace>();
+                if (utilizedNamespaces == (Object)Collections.emptyList()) {
+                    utilizedNamespaces = new ArrayList<XMLSecNamespace>(2);
                 }
                 utilizedNamespaces.add(attributeNamespace);
                 outputStack.peek().add(attributeNamespace);
@@ -168,20 +167,20 @@ public abstract class CanonicalizerBase 
         return utilizedNamespaces;
     }
 
-    protected SortedSet<XMLSecAttribute> getCurrentUtilizedAttributes(final XMLSecStartElement xmlSecStartElement,
+    protected List<XMLSecAttribute> getCurrentUtilizedAttributes(final XMLSecStartElement xmlSecStartElement,
                                                                       final C14NStack outputStack) {
         List<XMLSecAttribute> comparableAttributes = xmlSecStartElement.getOnElementDeclaredAttributes();
         if (comparableAttributes.isEmpty()) {
-            return emptySortedSet();
+            return Collections.emptyList();
         }
 
-        return new TreeSet<XMLSecAttribute>(comparableAttributes);
+        return new ArrayList<XMLSecAttribute>(comparableAttributes);
     }
 
-    protected SortedSet<XMLSecNamespace> getInitialUtilizedNamespaces(final XMLSecStartElement xmlSecStartElement,
+    protected List<XMLSecNamespace> getInitialUtilizedNamespaces(final XMLSecStartElement xmlSecStartElement,
                                                                       final C14NStack outputStack) {
 
-        final SortedSet<XMLSecNamespace> utilizedNamespaces = new TreeSet<XMLSecNamespace>();
+        final List<XMLSecNamespace> utilizedNamespaces = new ArrayList<XMLSecNamespace>();
         List<XMLSecNamespace> visibleNamespaces = new ArrayList<XMLSecNamespace>();
         xmlSecStartElement.getNamespacesFromCurrentScope(visibleNamespaces);
         for (int i = 0; i < visibleNamespaces.size(); i++) {
@@ -206,10 +205,10 @@ public abstract class CanonicalizerBase 
         return utilizedNamespaces;
     }
 
-    protected SortedSet<XMLSecAttribute> getInitialUtilizedAttributes(final XMLSecStartElement xmlSecStartElement,
+    protected List<XMLSecAttribute> getInitialUtilizedAttributes(final XMLSecStartElement xmlSecStartElement,
                                                                       final C14NStack outputStack) {
 
-        SortedSet<XMLSecAttribute> utilizedAttributes = emptySortedSet();
+        List<XMLSecAttribute> utilizedAttributes = Collections.emptyList();
 
         List<XMLSecAttribute> comparableAttributes = new ArrayList<XMLSecAttribute>();
         xmlSecStartElement.getAttributesFromCurrentScope(comparableAttributes);
@@ -221,8 +220,8 @@ public abstract class CanonicalizerBase 
             if (outputStack.containsOnStack(comparableAttribute) != null) {
                 continue;
             }
-            if (utilizedAttributes == (Object) emptySortedSet()) {
-                utilizedAttributes = new TreeSet<XMLSecAttribute>();
+            if (utilizedAttributes == (Object)Collections.emptyList()) {
+                utilizedAttributes = new ArrayList<XMLSecAttribute>(2);
             }
             utilizedAttributes.add(comparableAttribute);
             outputStack.peek().add(comparableAttribute);
@@ -237,8 +236,8 @@ public abstract class CanonicalizerBase 
             if (XML.equals(attributeName.getPrefix())) {
                 continue;
             }
-            if (utilizedAttributes == (Object) emptySortedSet()) {
-                utilizedAttributes = new TreeSet<XMLSecAttribute>();
+            if (utilizedAttributes == (Object)Collections.emptyList()) {
+                utilizedAttributes = new ArrayList<XMLSecAttribute>(2);
             }
             utilizedAttributes.add(comparableAttribute);
         }
@@ -270,12 +269,12 @@ public abstract class CanonicalizerBase 
                     currentDocumentLevel = DocumentLevel.NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
                     outputStack.push(Collections.<Comparable>emptyList());
 
-                    final SortedSet<XMLSecNamespace> utilizedNamespaces;
-                    final SortedSet<XMLSecAttribute> utilizedAttributes;
+                    final List<XMLSecNamespace> utilizedNamespaces;
+                    final List<XMLSecAttribute> utilizedAttributes;
 
                     if (firstCall) {
-                        utilizedNamespaces = new TreeSet<XMLSecNamespace>();
-                        utilizedAttributes = new TreeSet<XMLSecAttribute>();
+                        utilizedNamespaces = new ArrayList<XMLSecNamespace>();
+                        utilizedAttributes = new ArrayList<XMLSecAttribute>();
                         outputStack.peek().add(XMLSecEventFactory.createXMLSecNamespace(null, ""));
                         outputStack.push(Collections.<Comparable>emptyList());
                         firstCall = false;
@@ -308,41 +307,39 @@ public abstract class CanonicalizerBase 
                     outputStream.write('<');
                     final String prefix = xmlSecStartElement.getName().getPrefix();
                     if (prefix != null && !prefix.isEmpty()) {
-                        UtfHelpper.writeUTF8String(prefix, outputStream, cache);
+                        UtfHelpper.writeByte(prefix, outputStream, cache);
                         outputStream.write(DOUBLEPOINT);
                     }
                     final String name = xmlSecStartElement.getName().getLocalPart();
-                    UtfHelpper.writeUTF8String(name, outputStream, cache);
+                    UtfHelpper.writeByte(name, outputStream, cache);
 
                     if (!utilizedNamespaces.isEmpty()) {
-                        final Iterator<XMLSecNamespace> namespaceIterator = utilizedNamespaces.iterator();
-                        while (namespaceIterator.hasNext()) {
-                            final XMLSecNamespace namespace = namespaceIterator.next();
-
-                            if (!namespaceIsAbsolute(namespace.getNamespaceURI())) {
-                                throw new XMLStreamException("namespace is relative encountered: " + namespace.getNamespaceURI());
+                        Collections.sort(utilizedNamespaces);
+                        for (int i = 0; i < utilizedNamespaces.size(); i++) {
+                            final XMLSecNamespace xmlSecNamespace = utilizedNamespaces.get(i);
+                            if (!namespaceIsAbsolute(xmlSecNamespace.getNamespaceURI())) {
+                                throw new XMLStreamException("namespace is relative encountered: " + xmlSecNamespace.getNamespaceURI());
                             }
 
-                            if (namespace.isDefaultNamespaceDeclaration()) {
-                                outputAttrToWriter(XMLNS, namespace.getNamespaceURI(), outputStream, cache);
+                            if (xmlSecNamespace.isDefaultNamespaceDeclaration()) {
+                                outputAttrToWriter(null, XMLNS, xmlSecNamespace.getNamespaceURI(), outputStream, cache);
                             } else {
-                                outputAttrToWriter(XMLNS_DOUBLEPOINT + namespace.getPrefix(), namespace.getNamespaceURI(), outputStream, cache);
+                                outputAttrToWriter(XMLNS, xmlSecNamespace.getPrefix(), xmlSecNamespace.getNamespaceURI(), outputStream, cache);
                             }
                         }
                     }
 
                     if (!utilizedAttributes.isEmpty()) {
-                        final Iterator<XMLSecAttribute> attributeIterator = utilizedAttributes.iterator();
-                        while (attributeIterator.hasNext()) {
-                            final XMLSecAttribute attribute = attributeIterator.next();
+                        Collections.sort(utilizedAttributes);
+                        for (int i = 0; i < utilizedAttributes.size(); i++) {
+                            final XMLSecAttribute xmlSecAttribute = utilizedAttributes.get(i);
 
-                            final QName attributeName = attribute.getName();
+                            final QName attributeName = xmlSecAttribute.getName();
                             final String attributeNamePrefix = attributeName.getPrefix();
                             if (attributeNamePrefix != null && !attributeNamePrefix.isEmpty()) {
-                                final String localPart = attributeNamePrefix + DOUBLEPOINT + attributeName.getLocalPart();
-                                outputAttrToWriter(localPart, attribute.getValue(), outputStream, cache);
+                                outputAttrToWriter(attributeNamePrefix, attributeName.getLocalPart(), xmlSecAttribute.getValue(), outputStream, cache);
                             } else {
-                                outputAttrToWriter(attributeName.getLocalPart(), attribute.getValue(), outputStream, cache);
+                                outputAttrToWriter(null, attributeName.getLocalPart(), xmlSecAttribute.getValue(), outputStream, cache);
                             }
                         }
                     }
@@ -354,10 +351,10 @@ public abstract class CanonicalizerBase 
                     final String localPrefix = xmlSecEndElement.getName().getPrefix();
                     outputStream.write(_END_TAG);
                     if (localPrefix != null && !localPrefix.isEmpty()) {
-                        UtfHelpper.writeUTF8String(localPrefix, outputStream, cache);
+                        UtfHelpper.writeByte(localPrefix, outputStream, cache);
                         outputStream.write(DOUBLEPOINT);
                     }
-                    UtfHelpper.writeUTF8String(xmlSecEndElement.getName().getLocalPart(), outputStream, cache);
+                    UtfHelpper.writeByte(xmlSecEndElement.getName().getLocalPart(), outputStream, cache);
                     outputStream.write('>');
 
                     //We finished with this level, pop to the previous definitions.
@@ -372,7 +369,7 @@ public abstract class CanonicalizerBase 
                     break;
                 case XMLStreamConstants.CHARACTERS:
                     if (currentDocumentLevel == DocumentLevel.NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT) {
-                        outputTextToWriter(xmlSecEvent.asCharacters().getData(), outputStream);
+                        outputTextToWriter(xmlSecEvent.asCharacters().getText(), outputStream);
                     }
                     break;
                 case XMLStreamConstants.COMMENT:
@@ -382,7 +379,7 @@ public abstract class CanonicalizerBase 
                     break;
                 case XMLStreamConstants.SPACE:
                     if (currentDocumentLevel == DocumentLevel.NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT) {
-                        outputTextToWriter(xmlSecEvent.asCharacters().getData(), outputStream);
+                        outputTextToWriter(xmlSecEvent.asCharacters().getText(), outputStream);
                     }
                     break;
                 case XMLStreamConstants.START_DOCUMENT:
@@ -436,10 +433,14 @@ public abstract class CanonicalizerBase 
         }
     }
 
-    protected static void outputAttrToWriter(final String name, final String value, final OutputStream writer,
+    protected static void outputAttrToWriter(final String prefix, final String name, final String value, final OutputStream writer,
                                              final Map<String, byte[]> cache) throws IOException {
         writer.write(' ');
-        UtfHelpper.writeUTF8String(name, writer, cache);
+        if (prefix != null) {
+            UtfHelpper.writeByte(prefix, writer, cache);
+            UtfHelpper.writeCharToUtf8(DOUBLEPOINT, writer);
+        }
+        UtfHelpper.writeByte(name, writer, cache);
         writer.write(EQUAL_STRING);
         byte[] toWrite;
         final int length = value.length();
@@ -530,6 +531,42 @@ public abstract class CanonicalizerBase 
         }
     }
 
+    protected static void outputTextToWriter(final char[] text, final OutputStream writer) throws IOException {
+        final int length = text.length;
+        byte[] toWrite;
+        for (int i = 0; i < length; i++) {
+            final char c = text[i];
+
+            switch (c) {
+
+                case '&':
+                    toWrite = _AMP_;
+                    break;
+
+                case '<':
+                    toWrite = _LT_;
+                    break;
+
+                case '>':
+                    toWrite = _GT_;
+                    break;
+
+                case 0xD:
+                    toWrite = __XD_;
+                    break;
+
+                default:
+                    if (c < 0x80) {
+                        writer.write(c);
+                    } else {
+                        UtfHelpper.writeCharToUtf8(c, writer);
+                    }
+                    continue;
+            }
+            writer.write(toWrite);
+        }
+    }
+
     /**
      * Outputs a PI to the internal Writer.
      *
@@ -660,100 +697,4 @@ public abstract class CanonicalizerBase 
             throw new UnsupportedOperationException("Use peek()");
         }
     }
-
-    @SuppressWarnings("unchecked")
-    protected static <T> SortedSet<T> emptySortedSet() {
-        return (SortedSet<T>) EMPTY_SORTEDSET;
-    }
-
-    private static final SortedSet EMPTY_SORTEDSET = new EmptySortedSet();
-
-    private static class EmptySortedSet extends AbstractSet<Object> implements SortedSet<Object>, Serializable {
-
-        @Override
-        public Iterator<Object> iterator() {
-            return new Iterator<Object>() {
-                @Override
-                public boolean hasNext() {
-                    return false;
-                }
-
-                @Override
-                public Object next() {
-                    throw new NoSuchElementException();
-                }
-
-                @Override
-                public void remove() {
-                    throw new UnsupportedOperationException();
-                }
-            };
-        }
-
-        @Override
-        public int size() {
-            return 0;
-        }
-
-        @Override
-        public boolean contains(Object obj) {
-            return false;
-        }
-
-        @Override
-        public Comparator<? super Object> comparator() {
-            return null;
-        }
-
-        @Override
-        public SortedSet<Object> subSet(Object fromElement, Object toElement) {
-            return this;
-        }
-
-        @Override
-        public SortedSet<Object> headSet(Object toElement) {
-            return this;
-        }
-
-        @Override
-        public SortedSet<Object> tailSet(Object fromElement) {
-            return this;
-        }
-
-        @Override
-        public Object first() {
-            throw new NoSuchElementException();
-        }
-
-        @Override
-        public Object last() {
-            throw new NoSuchElementException();
-        }
-
-        @Override
-        @SuppressWarnings("unchecked")
-        public <T> T[] toArray(T[] a) {
-            return (T[]) new Object[0];
-        }
-
-        @Override
-        public boolean containsAll(Collection<?> c) {
-            return false;
-        }
-
-        @Override
-        public boolean addAll(Collection c) {
-            return false;
-        }
-
-        @Override
-        public boolean retainAll(Collection<?> c) {
-            return false;
-        }
-
-        @Override
-        public boolean removeAll(Collection<?> c) {
-            return false;
-        }
-    }
 }

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/XMLSecurityEventWriterTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/XMLSecurityEventWriterTest.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/XMLSecurityEventWriterTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/XMLSecurityEventWriterTest.java Tue Oct 16 14:01:40 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.xml.security.test.stax;
 
+import org.apache.xml.security.stax.ext.stax.XMLSecEventFactory;
 import org.junit.Test;
 
 import org.custommonkey.xmlunit.XMLAssert;
@@ -44,14 +45,15 @@ public class XMLSecurityEventWriterTest 
         XMLEventWriter stdXmlEventWriter = xmlOutputFactory.createXMLEventWriter(stdStringWriter);
 
         XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
-        XMLEventReader xmlEventReader = 
-            xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream(
-                "org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
+        XMLStreamReader xmlStreamReader =
+            xmlInputFactory.createXMLStreamReader(this.getClass().getClassLoader().getResourceAsStream(
+                    "org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
 
-        while (xmlEventReader.hasNext()) {
-            XMLEvent xmlEvent = xmlEventReader.nextEvent();
+        while (xmlStreamReader.hasNext()) {
+            XMLEvent xmlEvent = XMLSecEventFactory.allocate(xmlStreamReader, null);
             xmlSecurityEventWriter.add(xmlEvent);
             stdXmlEventWriter.add(xmlEvent);
+            xmlStreamReader.next();
         }
 
         xmlSecurityEventWriter.close();

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java Tue Oct 16 14:01:40 2012
@@ -24,6 +24,7 @@ import org.apache.xml.security.signature
 import org.apache.xml.security.stax.ext.*;
 import org.apache.xml.security.test.stax.utils.XmlReaderToWriter;
 import org.apache.xml.security.transforms.Transforms;
+import org.apache.xml.security.utils.XMLUtils;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.w3c.dom.Document;
@@ -37,9 +38,6 @@ import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.io.*;
 import java.security.Key;
 import java.security.KeyStore;
@@ -54,7 +52,6 @@ public abstract class AbstractPerformanc
     private static Key encryptionSymKey;
     protected XMLInputFactory xmlInputFactory;
     protected DocumentBuilderFactory documentBuilderFactory;
-    protected TransformerFactory transformerFactory;
     protected Key key;
     protected X509Certificate cert;
     private OutboundXMLSec outboundSignatureXMLSec;
@@ -78,8 +75,6 @@ public abstract class AbstractPerformanc
         documentBuilderFactory = DocumentBuilderFactory.newInstance();
         documentBuilderFactory.setNamespaceAware(true);
 
-        transformerFactory = TransformerFactory.newInstance();
-
         org.apache.xml.security.Init.init();
 
         KeyStore keyStore = KeyStore.getInstance("jks");
@@ -248,8 +243,7 @@ public abstract class AbstractPerformanc
         sig.sign(key);
         sig.addKeyInfo(cert);
 
-        javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
-        transformer.transform(new DOMSource(document), new StreamResult(new File(getTmpFilePath(), "signature-dom-" + tagCount + ".xml")));
+        XMLUtils.outputDOM(document, new BufferedOutputStream(new FileOutputStream(new File(getTmpFilePath(), "signature-dom-" + tagCount + ".xml"))));
     }
 
     protected void doDOMSignatureInbound(File file, int tagCount) throws Exception {
@@ -303,8 +297,7 @@ public abstract class AbstractPerformanc
         cipher.init(XMLCipher.ENCRYPT_MODE, encryptionSymKey);
         document = cipher.doFinal(document, document.getDocumentElement());
 
-        javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
-        transformer.transform(new DOMSource(document), new StreamResult(new File(getTmpFilePath(), "encryption-dom-" + tagCount + ".xml")));
+        XMLUtils.outputDOM(document, new BufferedOutputStream(new FileOutputStream(new File(getTmpFilePath(), "encryption-dom-" + tagCount + ".xml"))));
     }
 
     protected void doDOMDecryptionInbound(File file, int tagCount) throws Exception {

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java Tue Oct 16 14:01:40 2012
@@ -60,14 +60,12 @@ public class PerformanceTimingTest exten
             File signedFile = doStreamingSignatureOutbound(file, startTagCount);
             outSignatureSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
             signedFiles.put(startTagCount, signedFile);
-            System.gc();
-            System.gc();
+            doGC();
 
             start = System.currentTimeMillis();
             doDOMSignatureOutbound(file, startTagCount);
             outSignatureSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
-            System.gc();
-            System.gc();
+            doGC();
 
             outSignatureSamplesWriter.write("\n");
         }
@@ -92,14 +90,12 @@ public class PerformanceTimingTest exten
             long start = System.currentTimeMillis();
             doStreamingSignatureInbound(file, startTagCount);
             inSignatureSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
-            System.gc();
-            System.gc();
+            doGC();
 
             start = System.currentTimeMillis();
             doDOMSignatureInbound(file, startTagCount);
             inSignatureSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
-            System.gc();
-            System.gc();
+            doGC();
 
             inSignatureSamplesWriter.write("\n");
         }
@@ -122,14 +118,12 @@ public class PerformanceTimingTest exten
             File encryptedFile = doStreamingEncryptionOutbound(file, startTagCount);
             outEncryptionSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
             encryptedFiles.put(startTagCount, encryptedFile);
-            System.gc();
-            System.gc();
+            doGC();
 
             start = System.currentTimeMillis();
             doDOMEncryptionOutbound(file, startTagCount);
             outEncryptionSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
-            System.gc();
-            System.gc();
+            doGC();
 
             outEncryptionSamplesWriter.write("\n");
         }
@@ -154,17 +148,21 @@ public class PerformanceTimingTest exten
             long start = System.currentTimeMillis();
             doStreamingDecryptionInbound(file, startTagCount);
             inEncryptionSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
-            System.gc();
-            System.gc();
+            doGC();
 
             start = System.currentTimeMillis();
             doDOMDecryptionInbound(file, startTagCount);
             inEncryptionSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
-            System.gc();
-            System.gc();
+            doGC();
 
             inEncryptionSamplesWriter.write("\n");
         }
         inEncryptionSamplesWriter.close();
     }
+
+    private void doGC() {
+        Runtime.getRuntime().runFinalization();
+        System.gc();
+        System.gc();
+    }
 }

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XmlReaderToWriter.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XmlReaderToWriter.java?rev=1398806&r1=1398805&r2=1398806&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XmlReaderToWriter.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XmlReaderToWriter.java Tue Oct 16 14:01:40 2012
@@ -83,7 +83,9 @@ public final class XmlReaderToWriter {
                 break;
             case XMLEvent.SPACE:
             case XMLEvent.CHARACTERS:
-                writer.writeCharacters(xmlr.getText());
+                char[] text = new char[xmlr.getTextLength()];
+                xmlr.getTextCharacters(0, text, 0, xmlr.getTextLength());
+                writer.writeCharacters(text, 0, text.length);
                 break;
             case XMLEvent.PROCESSING_INSTRUCTION:
                 writer.writeProcessingInstruction(xmlr.getPITarget(), xmlr.getPIData());