Class SerializeSupport


  • public final class SerializeSupport
    extends Object
    Set of helper functions for serializing/writing DOM nodes.
    • Field Detail

      • prettyPrintParams

        private static Map<String,​Object> prettyPrintParams
        DOM configuration parameters used by LSSerializer in pretty print format output.
    • Constructor Detail

      • SerializeSupport

        private SerializeSupport()
        Constructor.
    • Method Detail

      • nodeToString

        @Nonnull
        public static String nodeToString​(@Nonnull
                                          Node node)
        Converts a Node into a String using the DOM, level 3, Load/Save serializer.
        Parameters:
        node - the node to be written to a string
        Returns:
        the string representation of the node
      • nodeToString

        @Nonnull
        public static String nodeToString​(@Nonnull
                                          Node node,
                                          @Nullable
                                          Map<String,​Object> serializerParams)
        Converts a Node into a String using the DOM, level 3, Load/Save serializer.
        Parameters:
        node - the node to be written to a string
        serializerParams - parameters to pass to the DOMConfiguration of the serializer instance, obtained via LSSerializer.getDomConfig(). May be null.
        Returns:
        the string representation of the node
      • prettyPrintXML

        @Nonnull
        public static String prettyPrintXML​(@Nonnull
                                            Node 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.
        Parameters:
        node - xml node to print
        Returns:
        pretty-printed xml
      • writeNode

        public static void writeNode​(@Nonnull
                                     Node node,
                                     @Nonnull
                                     OutputStream output)
        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.
        Parameters:
        node - the node to write out
        output - the output stream to write the XML to
      • writeNode

        public static void writeNode​(@Nonnull
                                     Node node,
                                     @Nonnull
                                     OutputStream output,
                                     @Nullable
                                     Map<String,​Object> serializerParams)
        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.
        Parameters:
        node - the node to write out
        output - the output stream to write the XML to
        serializerParams - parameters to pass to the DOMConfiguration of the serializer instance, obtained via LSSerializer.getDomConfig(). May be null.
      • getLSSerializer

        @Nonnull
        public static LSSerializer getLSSerializer​(@Nonnull
                                                   DOMImplementationLS domImplLS,
                                                   @Nullable
                                                   Map<String,​Object> serializerParams)
        Obtain a the DOM, level 3, Load/Save serializer LSSerializer instance from the given DOMImplementationLS instance.

        The serializer instance will be configured with the parameters passed as the serializerParams argument. It will also be configured with an LSSerializerFilter that shows all nodes to the filter, and accepts all nodes shown.

        Parameters:
        domImplLS - the DOM Level 3 Load/Save implementation to use
        serializerParams - parameters to pass to the DOMConfiguration of the serializer instance, obtained via LSSerializer.getDomConfig(). May be null.
        Returns:
        a new LSSerializer instance
      • getDOMImplementationLS

        @Nonnull
        public static DOMImplementationLS getDOMImplementationLS​(@Nonnull
                                                                 Node node)
        Gets the DOM, level 3, Load/Store implementation associated with the given node.
        Parameters:
        node - the node, never null
        Returns:
        the Load/Store implementation, never null