You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2020/01/27 11:54:20 UTC

svn commit: r1873204 - in /santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption: AbstractSerializer.java Serializer.java

Author: coheigea
Date: Mon Jan 27 11:54:20 2020
New Revision: 1873204

URL: http://svn.apache.org/viewvc?rev=1873204&view=rev
Log:
SANTUARIO-522 - Remove unused methods from Serializer

Modified:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/Serializer.java

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java?rev=1873204&r1=1873203&r2=1873204&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java Mon Jan 27 11:54:20 2020
@@ -46,21 +46,6 @@ public abstract class AbstractSerializer
     }
 
     /**
-     * Returns a <code>String</code> representation of the specified
-     * <code>Element</code>.
-     * <p></p>
-     * Refer also to comments about setup of format.
-     *
-     * @param element the <code>Element</code> to serialize.
-     * @return the <code>String</code> representation of the serilaized
-     *   <code>Element</code>.
-     * @throws Exception
-     */
-    public String serialize(Element element) throws Exception {
-        return canonSerialize(element);
-    }
-
-    /**
      * Returns a <code>byte[]</code> representation of the specified
      * <code>Element</code>.
      *
@@ -70,39 +55,9 @@ public abstract class AbstractSerializer
      * @throws Exception
      */
     public byte[] serializeToByteArray(Element element) throws Exception {
-        return canonSerializeToByteArray(element);
-    }
-
-    /**
-     * Returns a <code>String</code> representation of the specified
-     * <code>NodeList</code>.
-     * <p></p>
-     * This is a special case because the NodeList may represent a
-     * <code>DocumentFragment</code>. A document fragment may be a
-     * non-valid XML document (refer to appropriate description of
-     * W3C) because it my start with a non-element node, e.g. a text
-     * node.
-     * <p></p>
-     * The methods first converts the node list into a document fragment.
-     * Special care is taken to not destroy the current document, thus
-     * the method clones the nodes (deep cloning) before it appends
-     * them to the document fragment.
-     * <p></p>
-     * Refer also to comments about setup of format.
-     *
-     * @param content the <code>NodeList</code> to serialize.
-     * @return the <code>String</code> representation of the serialized
-     *   <code>NodeList</code>.
-     * @throws Exception
-     */
-    public String serialize(NodeList content) throws Exception {
         try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
-            for (int i = 0; i < content.getLength(); i++) {
-                canon.canonicalizeSubtree(content.item(i), baos);
-            }
-            String ret = baos.toString(StandardCharsets.UTF_8.name());
-            baos.reset();
-            return ret;
+            canon.canonicalizeSubtree(element, baos);
+            return baos.toByteArray();
         }
     }
 
@@ -124,34 +79,6 @@ public abstract class AbstractSerializer
         }
     }
 
-    /**
-     * Use the Canonicalizer to serialize the node
-     * @param node
-     * @return the canonicalization of the node
-     * @throws Exception
-     */
-    public String canonSerialize(Node node) throws Exception {
-        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
-            canon.canonicalizeSubtree(node, baos);
-            String ret = baos.toString(StandardCharsets.UTF_8.name());
-            baos.reset();
-            return ret;
-        }
-    }
-
-    /**
-     * Use the Canonicalizer to serialize the node
-     * @param node
-     * @return the (byte[]) canonicalization of the node
-     * @throws Exception
-     */
-    public byte[] canonSerializeToByteArray(Node node) throws Exception {
-        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
-            canon.canonicalizeSubtree(node, baos);
-            return baos.toByteArray();
-        }
-    }
-
     protected static byte[] createContext(byte[] source, Node ctx) throws XMLEncryptionException {
         // Create the context to parse the document against
         try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
@@ -195,36 +122,4 @@ public abstract class AbstractSerializer
         }
     }
 
-    protected static String createContext(String source, Node ctx) {
-        // Create the context to parse the document against
-        StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?><dummy");
-
-        // Run through each node up to the document node and find any xmlns: nodes
-        Map<String, String> storedNamespaces = new HashMap<>();
-        Node wk = ctx;
-        while (wk != null) {
-            NamedNodeMap atts = wk.getAttributes();
-            if (atts != null) {
-                for (int i = 0; i < atts.getLength(); ++i) {
-                    Node att = atts.item(i);
-                    String nodeName = att.getNodeName();
-                    if (("xmlns".equals(nodeName) || nodeName.startsWith("xmlns:"))
-                        && !storedNamespaces.containsKey(att.getNodeName())) {
-                        sb.append(' ');
-                        sb.append(nodeName);
-                        sb.append("=\"");
-                        sb.append(att.getNodeValue());
-                        sb.append('\"');
-                        storedNamespaces.put(nodeName, att.getNodeValue());
-                    }
-                }
-            }
-            wk = wk.getParentNode();
-        }
-        sb.append('>');
-        sb.append(source);
-        sb.append("</dummy>");
-        return sb.toString();
-    }
-
 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/Serializer.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/Serializer.java?rev=1873204&r1=1873203&r2=1873204&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/Serializer.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/Serializer.java Mon Jan 27 11:54:20 2020
@@ -40,7 +40,7 @@ public interface Serializer {
      * <code>Element</code>.
      *
      * @param element the <code>Element</code> to serialize.
-     * @return the <code>byte[]</code> representation of the serilaized
+     * @return the <code>byte[]</code> representation of the serialized
      *   <code>Element</code>.
      * @throws Exception
      */
@@ -58,14 +58,6 @@ public interface Serializer {
     byte[] serializeToByteArray(NodeList content) throws Exception;
 
     /**
-     * Use the Canonicalizer to serialize the node
-     * @param node
-     * @return the (byte[]) canonicalization of the node
-     * @throws Exception
-     */
-    byte[] canonSerializeToByteArray(Node node) throws Exception;
-
-    /**
      * @param source
      * @param ctx
      * @param secureValidation