[utilities COMMIT] in /java-support/trunk: doc/RELEASE-NOTES.txt src/main/java/net/shibboleth/utilities/java/support/...

noreply at shibboleth.net noreply at shibboleth.net
Fri Apr 5 16:43:25 EDT 2013


Author: putmanb
Date: Fri Apr  5 16:43:25 2013
New Revision: 365

URL: http://svn.shibboleth.net/view/utilities?rev=365&view=rev
Log:
JSPT-23: SerializeSupport prettyPrintXML has reverted impl to diverge from writeNode and nodeToString 

Modified:
    java-support/trunk/doc/RELEASE-NOTES.txt
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SerializeSupport.java

Modified: java-support/trunk/doc/RELEASE-NOTES.txt
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/doc/RELEASE-NOTES.txt?rev=365&r1=364&r2=365&view=diff
==============================================================================
--- java-support/trunk/doc/RELEASE-NOTES.txt (original)
+++ java-support/trunk/doc/RELEASE-NOTES.txt Fri Apr  5 16:43:25 2013
@@ -1,4 +1,5 @@
 Changes in Release 1.1.0
 ===============================
 [JSPT-3] - Providers helpers for dealing with idle connections in HttpClient
-[JSPT-16] - Add a ServletListener that configures logback with a specified configuration file
+[JSPT-16] - Add a ServletListener that configures logback with a specified configuration file
+[JSPT-23] - SerializeSupport prettyPrintXML has reverted impl to diverge from writeNode and nodeToString 

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SerializeSupport.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SerializeSupport.java?rev=365&r1=364&r2=365&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SerializeSupport.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SerializeSupport.java Fri Apr  5 16:43:25 2013
@@ -19,19 +19,13 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.OutputStream;
-import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.util.Map;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 
+import net.shibboleth.utilities.java.support.collection.LazyMap;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 
 import org.w3c.dom.DOMConfiguration;
@@ -45,6 +39,9 @@
 
 /** Set of helper functions for serializing/writing DOM nodes. */
 public final class SerializeSupport {
+    
+    /** DOM configuration parameters used by LSSerializer in pretty print format output. */
+    private static Map<String, Object> prettyPrintParams;
 
     /** Constructor. */
     private SerializeSupport() {
@@ -72,7 +69,8 @@
     }
 
     /**
-     * Pretty prints the XML node.
+     * Converts a Node into a String, using the DOM, level 3, Load/Save serializer. A serializer
+     * option of 'format-pretty-print=true' is used to produce the pretty-print formatting.
      * 
      * @param node xml node to print
      * 
@@ -80,19 +78,13 @@
      */
     @Nonnull public static String prettyPrintXML(@Nonnull final Node node) {
         Constraint.isNotNull(node, "Node may not be null");
-
-        final TransformerFactory tfactory = TransformerFactory.newInstance();
+        
+        final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+        writeNode(node, baout, prettyPrintParams);
         try {
-            final Transformer serializer = tfactory.newTransformer();
-            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
-            serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
-
-            final StringWriter output = new StringWriter();
-            serializer.transform(new DOMSource(node), new StreamResult(output));
-            return output.toString();
-        } catch (TransformerException e) {
-            // this is fatal, just dump the stack and throw a runtime exception
-            e.printStackTrace();
+            return new String(baout.toByteArray(), "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            // all VMs are required to support UTF-8, if it's not something is really wrong
             throw new RuntimeException(e);
         }
     }
@@ -105,21 +97,25 @@
      * @param output the output stream to write the XML to
      */
     public static void writeNode(@Nonnull final Node node, @Nonnull final OutputStream output) {
+        writeNode(node, output, null);
+    }
+    
+    /**
+     * Writes a Node out to a Writer using the DOM, level 3, Load/Save serializer. The written content is encoded using
+     * the encoding specified in the writer configuration.
+     * 
+     * @param node the node to write out
+     * @param output the output stream to write the XML to
+     * @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer instance, obtained

[... 35 lines stripped ...]


More information about the commits mailing list