Class Serializer

  • Direct Known Subclasses:
    HtmlSerializer, XmlSerializer

    public abstract class Serializer
    extends java.lang.Object

    Basic abstract serializer - contains common logic for descendants (methods writeXXX().

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  Serializer.HeadlessTagNode
      Used to implement serialization with missing envelope - omiting open and close tags, just serialize children.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getAsString​(java.lang.String htmlContent)  
      java.lang.String getAsString​(TagNode tagNode)  
      java.lang.String getAsString​(TagNode tagNode, boolean omitEnvelope)  
      java.lang.String getAsString​(TagNode tagNode, java.lang.String charset)  
      java.lang.String getAsString​(TagNode tagNode, java.lang.String charset, boolean omitEnvelope)  
      protected boolean isScriptOrStyle​(TagNode tagNode)  
      protected abstract void serialize​(TagNode tagNode, java.io.Writer writer)  
      void write​(TagNode tagNode, java.io.Writer writer, java.lang.String charset)
      Writes specified node using specified writer.
      void write​(TagNode tagNode, java.io.Writer writer, java.lang.String charset, boolean omitEnvelope)
      Writes specified node using specified writer.
      void writeToFile​(TagNode tagNode, java.lang.String fileName)
      Writes specified TagNode to the file, using system default charset.
      void writeToFile​(TagNode tagNode, java.lang.String fileName, boolean omitEnvelope)
      Writes specified TagNode to the file, using specified charset and optionally omits node envelope (skips open and close tags of the node).
      void writeToFile​(TagNode tagNode, java.lang.String fileName, java.lang.String charset)
      Writes specified TagNode to the file, using specified charset.
      void writeToFile​(TagNode tagNode, java.lang.String fileName, java.lang.String charset, boolean omitEnvelope)
      Writes specified TagNode to the file, using specified charset and optionally omits node envelope (skips open and close tags of the node).
      void writeToStream​(TagNode tagNode, java.io.OutputStream out)
      Writes specified TagNode to the output stream, using system default charset.
      void writeToStream​(TagNode tagNode, java.io.OutputStream out, boolean omitEnvelope)
      Writes specified TagNode to the output stream, using system default charset and optionally omits node envelope (skips open and close tags of the node).
      void writeToStream​(TagNode tagNode, java.io.OutputStream out, java.lang.String charset)
      Writes specified TagNode to the output stream, using specified charset.
      void writeToStream​(TagNode tagNode, java.io.OutputStream out, java.lang.String charset, boolean omitEnvelope)
      Writes specified TagNode to the output stream, using specified charset and optionally omits node envelope (skips open and close tags of the node).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • writeToStream

        public void writeToStream​(TagNode tagNode,
                                  java.io.OutputStream out,
                                  java.lang.String charset,
                                  boolean omitEnvelope)
                           throws java.io.IOException
        Writes specified TagNode to the output stream, using specified charset and optionally omits node envelope (skips open and close tags of the node).
        Parameters:
        tagNode - Node to be written
        out - Output stream
        charset - Charset of the output
        omitEnvelope - Tells whether to skip open and close tag of the node.
        Throws:
        java.io.IOException
      • writeToStream

        public void writeToStream​(TagNode tagNode,
                                  java.io.OutputStream out,
                                  java.lang.String charset)
                           throws java.io.IOException
        Writes specified TagNode to the output stream, using specified charset.
        Parameters:
        tagNode - Node to be written
        out - Output stream
        charset - Charset of the output
        Throws:
        java.io.IOException
      • writeToStream

        public void writeToStream​(TagNode tagNode,
                                  java.io.OutputStream out,
                                  boolean omitEnvelope)
                           throws java.io.IOException
        Writes specified TagNode to the output stream, using system default charset and optionally omits node envelope (skips open and close tags of the node).
        Parameters:
        tagNode - Node to be written
        out - Output stream
        omitEnvelope - Tells whether to skip open and close tag of the node.
        Throws:
        java.io.IOException
      • writeToStream

        public void writeToStream​(TagNode tagNode,
                                  java.io.OutputStream out)
                           throws java.io.IOException
        Writes specified TagNode to the output stream, using system default charset.
        Parameters:
        tagNode - Node to be written
        out - Output stream
        Throws:
        java.io.IOException
      • writeToFile

        public void writeToFile​(TagNode tagNode,
                                java.lang.String fileName,
                                java.lang.String charset,
                                boolean omitEnvelope)
                         throws java.io.IOException
        Writes specified TagNode to the file, using specified charset and optionally omits node envelope (skips open and close tags of the node).
        Parameters:
        tagNode - Node to be written
        fileName - Output file name
        charset - Charset of the output
        omitEnvelope - Tells whether to skip open and close tag of the node.
        Throws:
        java.io.IOException
      • writeToFile

        public void writeToFile​(TagNode tagNode,
                                java.lang.String fileName,
                                java.lang.String charset)
                         throws java.io.IOException
        Writes specified TagNode to the file, using specified charset.
        Parameters:
        tagNode - Node to be written
        fileName - Output file name
        charset - Charset of the output
        Throws:
        java.io.IOException
      • writeToFile

        public void writeToFile​(TagNode tagNode,
                                java.lang.String fileName,
                                boolean omitEnvelope)
                         throws java.io.IOException
        Writes specified TagNode to the file, using specified charset and optionally omits node envelope (skips open and close tags of the node).
        Parameters:
        tagNode - Node to be written
        fileName - Output file name
        omitEnvelope - Tells whether to skip open and close tag of the node.
        Throws:
        java.io.IOException
      • writeToFile

        public void writeToFile​(TagNode tagNode,
                                java.lang.String fileName)
                         throws java.io.IOException
        Writes specified TagNode to the file, using system default charset.
        Parameters:
        tagNode - Node to be written
        fileName - Output file name
        Throws:
        java.io.IOException
      • getAsString

        public java.lang.String getAsString​(TagNode tagNode,
                                            java.lang.String charset,
                                            boolean omitEnvelope)
        Parameters:
        tagNode - Node to serialize to string
        charset - Charset of the output - stands in xml declaration part
        omitEnvelope - Tells whether to skip open and close tag of the node.
        Returns:
        Output as string
      • getAsString

        public java.lang.String getAsString​(TagNode tagNode,
                                            java.lang.String charset)
        Parameters:
        tagNode - Node to serialize to string
        charset - Charset of the output - stands in xml declaration part
        Returns:
        Output as string
      • getAsString

        public java.lang.String getAsString​(TagNode tagNode,
                                            boolean omitEnvelope)
        Parameters:
        tagNode - Node to serialize to string
        omitEnvelope - Tells whether to skip open and close tag of the node.
        Returns:
        Output as string
        Throws:
        java.io.IOException
      • getAsString

        public java.lang.String getAsString​(TagNode tagNode)
        Parameters:
        tagNode - Node to serialize to string
        Returns:
        Output as string
        Throws:
        java.io.IOException
      • getAsString

        public java.lang.String getAsString​(java.lang.String htmlContent)
      • write

        public void write​(TagNode tagNode,
                          java.io.Writer writer,
                          java.lang.String charset)
                   throws java.io.IOException
        Writes specified node using specified writer.
        Parameters:
        tagNode - Node to serialize.
        writer - Writer instance
        charset - Charset of the output
        Throws:
        java.io.IOException
      • write

        public void write​(TagNode tagNode,
                          java.io.Writer writer,
                          java.lang.String charset,
                          boolean omitEnvelope)
                   throws java.io.IOException
        Writes specified node using specified writer.
        Parameters:
        tagNode - Node to serialize.
        writer - Writer instance
        charset - Charset of the output
        omitEnvelope - Tells whether to skip open and close tag of the node.
        Throws:
        java.io.IOException
      • isScriptOrStyle

        protected boolean isScriptOrStyle​(TagNode tagNode)
      • serialize

        protected abstract void serialize​(TagNode tagNode,
                                          java.io.Writer writer)
                                   throws java.io.IOException
        Throws:
        java.io.IOException