Package org.htmlcleaner
Class DomSerializer
- java.lang.Object
-
- org.htmlcleaner.DomSerializer
-
public class DomSerializer extends java.lang.Object
DOM serializer - creates xml DOM.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CSS_COMMENT_END
private static java.lang.String
CSS_COMMENT_START
protected boolean
deserializeCdataEntities
protected boolean
escapeXml
Whether XML entities should be escaped or not.private static java.lang.String
NEW_LINE
protected CleanerProperties
props
The HTML Cleaner properties set by the user to control the HTML cleaning.protected boolean
strictErrorChecking
private static java.lang.String
XML_10
private static java.lang.String
XML_11
protected java.lang.String
xmlVersion
-
Constructor Summary
Constructors Constructor Description DomSerializer(CleanerProperties props)
DomSerializer(CleanerProperties props, boolean escapeXml)
DomSerializer(CleanerProperties props, boolean escapeXml, boolean deserializeCdataEntities)
DomSerializer(CleanerProperties props, boolean escapeXml, boolean deserializeCdataEntities, boolean strictErrorChecking)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.w3c.dom.Document
createDocument(TagNode rootNode)
org.w3c.dom.Document
createDOM(TagNode rootNode)
protected void
createSubnodes(org.w3c.dom.Document document, org.w3c.dom.Element element, java.util.List<? extends BaseToken> tagChildren)
Serialize a given HTML Cleaner node.protected java.lang.String
deserializeCdataEntities(java.lang.String input)
protected boolean
dontEscape(org.w3c.dom.Element element)
encapsulate content with <[CDATA[ ]]> for things like script and style elementsjava.lang.String
getXmlVersion()
protected boolean
isScriptOrStyle(org.w3c.dom.Element element)
protected java.lang.String
outputCData(CData cdata)
void
setXmlVersion(java.lang.String xmlVersion)
-
-
-
Field Detail
-
CSS_COMMENT_START
private static final java.lang.String CSS_COMMENT_START
- See Also:
- Constant Field Values
-
CSS_COMMENT_END
private static final java.lang.String CSS_COMMENT_END
- See Also:
- Constant Field Values
-
NEW_LINE
private static final java.lang.String NEW_LINE
- See Also:
- Constant Field Values
-
XML_10
private static final java.lang.String XML_10
- See Also:
- Constant Field Values
-
XML_11
private static final java.lang.String XML_11
- See Also:
- Constant Field Values
-
props
protected CleanerProperties props
The HTML Cleaner properties set by the user to control the HTML cleaning.
-
escapeXml
protected boolean escapeXml
Whether XML entities should be escaped or not.
-
deserializeCdataEntities
protected boolean deserializeCdataEntities
-
strictErrorChecking
protected boolean strictErrorChecking
-
xmlVersion
protected java.lang.String xmlVersion
-
-
Constructor Detail
-
DomSerializer
public DomSerializer(CleanerProperties props, boolean escapeXml, boolean deserializeCdataEntities, boolean strictErrorChecking)
- Parameters:
props
- the HTML Cleaner properties set by the user to control the HTML cleaning.escapeXml
- if true then escape XML entitiesdeserializeCdataEntities
- if true then deserialize entities in CData sectionsstrictErrorChecking
- if false then Document strict error checking is turned off
-
DomSerializer
public DomSerializer(CleanerProperties props, boolean escapeXml, boolean deserializeCdataEntities)
- Parameters:
props
- the HTML Cleaner properties set by the user to control the HTML cleaning.escapeXml
- if true then escape XML entitiesdeserializeCdataEntities
- if true then deserialize entities in CData sections
-
DomSerializer
public DomSerializer(CleanerProperties props, boolean escapeXml)
- Parameters:
props
- the HTML Cleaner properties set by the user to control the HTML cleaning.escapeXml
- if true then escape XML entities
-
DomSerializer
public DomSerializer(CleanerProperties props)
- Parameters:
props
- the HTML Cleaner properties set by the user to control the HTML cleaning.
-
-
Method Detail
-
getXmlVersion
public java.lang.String getXmlVersion()
-
setXmlVersion
public void setXmlVersion(java.lang.String xmlVersion) throws java.lang.Exception
- Throws:
java.lang.Exception
-
createDocument
protected org.w3c.dom.Document createDocument(TagNode rootNode) throws javax.xml.parsers.ParserConfigurationException
- Throws:
javax.xml.parsers.ParserConfigurationException
-
createDOM
public org.w3c.dom.Document createDOM(TagNode rootNode) throws javax.xml.parsers.ParserConfigurationException
- Parameters:
rootNode
- the HTML Cleaner root node to serialize- Returns:
- the W3C Document object
- Throws:
javax.xml.parsers.ParserConfigurationException
- if there's an error during serialization
-
isScriptOrStyle
protected boolean isScriptOrStyle(org.w3c.dom.Element element)
- Parameters:
element
- the element to check- Returns:
- true if the passed element is a script or style element
-
dontEscape
protected boolean dontEscape(org.w3c.dom.Element element)
encapsulate content with <[CDATA[ ]]> for things like script and style elements- Parameters:
element
-- Returns:
- true if <[CDATA[ ]]> should be used.
-
outputCData
protected java.lang.String outputCData(CData cdata)
-
deserializeCdataEntities
protected java.lang.String deserializeCdataEntities(java.lang.String input)
-
createSubnodes
protected void createSubnodes(org.w3c.dom.Document document, org.w3c.dom.Element element, java.util.List<? extends BaseToken> tagChildren)
Serialize a given HTML Cleaner node.- Parameters:
document
- the W3C Document to use for creating new DOM elementselement
- the W3C element to which we'll add the subnodes totagChildren
- the HTML Cleaner nodes to serialize for that node
-
-