Class Serializer

java.lang.Object
org.htmlcleaner.Serializer
Direct Known Subclasses:
HtmlSerializer, XmlSerializer

public abstract class Serializer extends Object

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

  • Field Details

  • Constructor Details

  • Method Details

    • writeToStream

      public void writeToStream(TagNode tagNode, OutputStream out, String charset, boolean omitEnvelope) throws 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:
      IOException
    • writeToStream

      public void writeToStream(TagNode tagNode, OutputStream out, String charset) throws 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:
      IOException
    • writeToStream

      public void writeToStream(TagNode tagNode, OutputStream out, boolean omitEnvelope) throws 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:
      IOException
    • writeToStream

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

      public void writeToFile(TagNode tagNode, String fileName, String charset, boolean omitEnvelope) throws 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:
      IOException
    • writeToFile

      public void writeToFile(TagNode tagNode, String fileName, String charset) throws 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:
      IOException
    • writeToFile

      public void writeToFile(TagNode tagNode, String fileName, boolean omitEnvelope) throws 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:
      IOException
    • writeToFile

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

      public String getAsString(TagNode tagNode, 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 String getAsString(TagNode tagNode, 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 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:
      IOException
    • getAsString

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

      public String getAsString(String htmlContent)
    • write

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

      public void write(TagNode tagNode, Writer writer, String charset, boolean omitEnvelope) throws 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:
      IOException
    • isScriptOrStyle

      protected boolean isScriptOrStyle(TagNode tagNode)
    • serialize

      protected abstract void serialize(TagNode tagNode, Writer writer) throws IOException
      Throws:
      IOException