Package org.htmlcleaner
Class XmlSerializer
- java.lang.Object
-
- org.htmlcleaner.Serializer
-
- org.htmlcleaner.XmlSerializer
-
- Direct Known Subclasses:
BrowserCompactXmlSerializer,CompactXmlSerializer,PrettyXmlSerializer,SimpleXmlSerializer
public abstract class XmlSerializer extends Serializer
Abstract XML serializer - contains common logic for descendants.
-
-
Field Summary
Fields Modifier and Type Field Description private booleancreatingHtmlDomstatic java.lang.StringXMLNS_NAMESPACE-
Fields inherited from class org.htmlcleaner.Serializer
props
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedXmlSerializer(CleanerProperties props)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected booleandontEscape(TagNode tagNode)protected java.lang.StringescapeXml(java.lang.String xmlContent)java.lang.StringgetXmlAsString(TagNode tagNode)Deprecated.Use getAsString() instead.java.lang.StringgetXmlAsString(TagNode tagNode, java.lang.String charset)Deprecated.Use getAsString() instead.booleanisCreatingHtmlDom()protected booleanisForbiddenAttribute(TagNode tagNode, java.lang.String attName, java.lang.String value)Override to add additional conditions.protected booleanisForbiddenTag(TagNode tagNode)protected booleanisHeadOrBody(java.lang.String tagName)protected booleanisMinimizedTagSyntax(TagNode tagNode)protected voidserializeAttribute(TagNode tagNode, java.io.Writer writer, java.lang.String attName, java.lang.String attValue)This allows overriding to eliminate forbidden attributes (for example javascript attributes onclick, onblur, etc.protected voidserializeCData(CData item, TagNode tagNode, java.io.Writer writer)Serialize a CDATA section.protected voidserializeContentToken(ContentNode item, TagNode tagNode, java.io.Writer writer)Serialize a content token, escaping where necessary.protected voidserializeEndTag(TagNode tagNode, java.io.Writer writer)protected voidserializeEndTag(TagNode tagNode, java.io.Writer writer, boolean newLine)protected voidserializeOpenTag(TagNode tagNode, java.io.Writer writer)protected voidserializeOpenTag(TagNode tagNode, java.io.Writer writer, boolean newLine)voidsetCreatingHtmlDom(boolean creatingHtmlDom)voidwriteXml(TagNode tagNode, java.io.Writer writer, java.lang.String charset)Deprecated.Use write() instead.voidwriteXmlToFile(TagNode tagNode, java.lang.String fileName)Deprecated.Use writeToFile() instead.voidwriteXmlToFile(TagNode tagNode, java.lang.String fileName, java.lang.String charset)Deprecated.Use writeToFile() instead.voidwriteXmlToStream(TagNode tagNode, java.io.OutputStream out)Deprecated.Use writeToStream() instead.voidwriteXmlToStream(TagNode tagNode, java.io.OutputStream out, java.lang.String charset)Deprecated.Use writeToStream() instead.-
Methods inherited from class org.htmlcleaner.Serializer
getAsString, getAsString, getAsString, getAsString, getAsString, isScriptOrStyle, serialize, write, write, writeToFile, writeToFile, writeToFile, writeToFile, writeToStream, writeToStream, writeToStream, writeToStream
-
-
-
-
Field Detail
-
XMLNS_NAMESPACE
public static final java.lang.String XMLNS_NAMESPACE
- See Also:
- Constant Field Values
-
creatingHtmlDom
private boolean creatingHtmlDom
-
-
Constructor Detail
-
XmlSerializer
protected XmlSerializer(CleanerProperties props)
-
-
Method Detail
-
setCreatingHtmlDom
public void setCreatingHtmlDom(boolean creatingHtmlDom)
- Parameters:
creatingHtmlDom- the creatingHtmlDom to set
-
isCreatingHtmlDom
public boolean isCreatingHtmlDom()
- Returns:
- the creatingHtmlDom
-
writeXmlToStream
@Deprecated public void writeXmlToStream(TagNode tagNode, java.io.OutputStream out, java.lang.String charset) throws java.io.IOException
Deprecated.Use writeToStream() instead.- Throws:
java.io.IOException
-
writeXmlToStream
@Deprecated public void writeXmlToStream(TagNode tagNode, java.io.OutputStream out) throws java.io.IOException
Deprecated.Use writeToStream() instead.- Throws:
java.io.IOException
-
writeXmlToFile
@Deprecated public void writeXmlToFile(TagNode tagNode, java.lang.String fileName, java.lang.String charset) throws java.io.IOException
Deprecated.Use writeToFile() instead.- Throws:
java.io.IOException
-
writeXmlToFile
@Deprecated public void writeXmlToFile(TagNode tagNode, java.lang.String fileName) throws java.io.IOException
Deprecated.Use writeToFile() instead.- Throws:
java.io.IOException
-
getXmlAsString
@Deprecated public java.lang.String getXmlAsString(TagNode tagNode, java.lang.String charset)
Deprecated.Use getAsString() instead.
-
getXmlAsString
@Deprecated public java.lang.String getXmlAsString(TagNode tagNode)
Deprecated.Use getAsString() instead.
-
writeXml
@Deprecated public void writeXml(TagNode tagNode, java.io.Writer writer, java.lang.String charset) throws java.io.IOException
Deprecated.Use write() instead.- Throws:
java.io.IOException
-
escapeXml
protected java.lang.String escapeXml(java.lang.String xmlContent)
-
dontEscape
protected boolean dontEscape(TagNode tagNode)
-
isMinimizedTagSyntax
protected boolean isMinimizedTagSyntax(TagNode tagNode)
-
serializeOpenTag
protected void serializeOpenTag(TagNode tagNode, java.io.Writer writer) throws java.io.IOException
- Throws:
java.io.IOException
-
serializeCData
protected void serializeCData(CData item, TagNode tagNode, java.io.Writer writer) throws java.io.IOException
Serialize a CDATA section. If the context is a script or style tag, and using CDATA for script and style is set to true, then we just write the actual content, as the whole section is wrapped in CDATA tokens. Otherwise we escape the content as if it were regular text.- Parameters:
item- the CDATA instancetagNode- the TagNode within which the CDATA appearswriter- the writer to output to- Throws:
java.io.IOException
-
serializeContentToken
protected void serializeContentToken(ContentNode item, TagNode tagNode, java.io.Writer writer) throws java.io.IOException
Serialize a content token, escaping where necessary.- Parameters:
item- the content token to serializetagNode- the TagNode within which the content token appearswriter- the writer to output to- Throws:
java.io.IOException
-
serializeOpenTag
protected void serializeOpenTag(TagNode tagNode, java.io.Writer writer, boolean newLine) throws java.io.IOException
- Throws:
java.io.IOException
-
isForbiddenTag
protected boolean isForbiddenTag(TagNode tagNode)
- Parameters:
tagNode-- Returns:
- true if the tag is forbidden
-
isHeadOrBody
protected boolean isHeadOrBody(java.lang.String tagName)
-
serializeAttribute
protected void serializeAttribute(TagNode tagNode, java.io.Writer writer, java.lang.String attName, java.lang.String attValue) throws java.io.IOException
This allows overriding to eliminate forbidden attributes (for example javascript attributes onclick, onblur, etc. )- Parameters:
writer-attName-attValue-- Throws:
java.io.IOException
-
isForbiddenAttribute
protected boolean isForbiddenAttribute(TagNode tagNode, java.lang.String attName, java.lang.String value)
Override to add additional conditions.- Parameters:
tagNode-attName-value-- Returns:
- true if the attribute should not be outputed.
-
serializeEndTag
protected void serializeEndTag(TagNode tagNode, java.io.Writer writer) throws java.io.IOException
- Throws:
java.io.IOException
-
serializeEndTag
protected void serializeEndTag(TagNode tagNode, java.io.Writer writer, boolean newLine) throws java.io.IOException
- Throws:
java.io.IOException
-
-