Package org.htmlcleaner
Class Serializer
- java.lang.Object
-
- org.htmlcleaner.Serializer
-
- Direct Known Subclasses:
HtmlSerializer
,XmlSerializer
public abstract class Serializer extends java.lang.Object
Basic abstract serializer - contains common logic for descendants (methods
writeXXX()
.
-
-
Field Summary
Fields Modifier and Type Field Description protected CleanerProperties
props
-
Constructor Summary
Constructors Modifier Constructor Description protected
Serializer(CleanerProperties props)
-
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).
-
-
-
Field Detail
-
props
protected CleanerProperties props
-
-
Constructor Detail
-
Serializer
protected Serializer(CleanerProperties props)
-
-
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 writtenout
- Output streamcharset
- Charset of the outputomitEnvelope
- 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 writtenout
- Output streamcharset
- 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 writtenout
- Output streamomitEnvelope
- 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 writtenout
- 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 writtenfileName
- Output file namecharset
- Charset of the outputomitEnvelope
- 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 writtenfileName
- Output file namecharset
- 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 writtenfileName
- Output file nameomitEnvelope
- 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 writtenfileName
- 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 stringcharset
- Charset of the output - stands in xml declaration partomitEnvelope
- 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 stringcharset
- 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 stringomitEnvelope
- 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 instancecharset
- 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 instancecharset
- Charset of the outputomitEnvelope
- 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
-
-