Class HtmlBuilder
By default, when using the constructor without arguments, the
this parser coerces XML 1.0-incompatible infosets into XML 1.0-compatible
infosets. This corresponds to ALTER_INFOSET as the general
XML violation policy. It is possible to treat XML 1.0 infoset violations
as fatal by setting the general XML violation policy to FATAL.
The doctype is not represented in the tree.
The document mode is represented via the Mode
interface on the Document node if the node implements
that interface (depends on the used node factory).
The form pointer is stored if the node factory supports storing it.
This package has its own node factory class because the official XOM node factory may return multiple nodes instead of one confusing the assumptions of the DOM-oriented HTML5 parsing algorithm.
- Version:
- $Id$
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<CharacterHandler> private booleanprivate XmlViolationPolicyprivate XmlViolationPolicyprivate XmlViolationPolicyprivate DoctypeExpectationprivate DocumentModeHandlerprivate Driverprivate EntityResolverprivate ErrorHandlerprivate Heuristicsprivate booleanprivate booleanprivate XmlViolationPolicyprivate booleanprivate booleanprivate final SimpleNodeFactoryprivate XmlViolationPolicyprivate TransitionHandlerprivate final XOMTreeBuilderprivate ErrorHandlerprivate XmlViolationPolicy -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with default node factory and fatal XML violation policy.HtmlBuilder(XmlViolationPolicy xmlPolicy) Constructor with default node factory and given XML violation policy.HtmlBuilder(SimpleNodeFactory nodeFactory) Constructor with given node factory and fatal XML violation policy.HtmlBuilder(SimpleNodeFactory nodeFactory, XmlViolationPolicy xmlPolicy) Constructor with given node factory and given XML violation policy. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCharacterHandler(CharacterHandler characterHandler) nu.xom.DocumentParse fromFile.nu.xom.Documentbuild(InputStream stream) Parse fromInputStream.nu.xom.Documentbuild(InputStream stream, String uri) Parse fromInputStream.nu.xom.DocumentParse fromReader.nu.xom.DocumentParse fromReader.nu.xom.DocumentParse from URI.nu.xom.DocumentParse fromString.nu.xom.Documentbuild(InputSource is) Parse from SAXInputSource.nu.xom.NodesbuildFragment(InputSource is, String context) Parse a fragment from SAXInputSource.Deprecated.Returns the commentPolicy.Returns the contentNonXmlCharPolicy.Returns the contentSpacePolicy.Returns the doctype expectation.Returns theLocatorduring parse.Returns the document mode handler.The policy for non-NCName element and attribute names.Gets the node factoryReturns the streamabilityViolationPolicy.Returns the xmlnsPolicy.booleanIndicates whether NFC normalization of source is being checked.booleanWhether the HTML 4 mode reports boolean attributes in a way that repeats the name in the value.booleanWhetherlangis mapped toxml:lang.booleanReturns the reportingDoctype.booleanWhether the parser considers scripting to be enabled for noscript treatment.private voidlazyInit()This class wraps different tree builders depending on configuration.private TokenizernewTokenizer(TokenHandler handler, boolean newAttributesEachTime) voidsetBogusXmlnsPolicy(XmlViolationPolicy bogusXmlnsPolicy) Deprecated.voidsetCheckingNormalization(boolean enable) Toggles the checking of the NFC normalization of source.voidsetCommentPolicy(XmlViolationPolicy commentPolicy) Sets the policy for consecutive hyphens in comments.voidsetContentNonXmlCharPolicy(XmlViolationPolicy contentNonXmlCharPolicy) Sets the policy for non-XML characters except white space.voidsetContentSpacePolicy(XmlViolationPolicy contentSpacePolicy) Sets the policy for non-XML white space.voidsetDoctypeExpectation(DoctypeExpectation doctypeExpectation) Sets the doctype expectation.voidsetDocumentModeHandler(DocumentModeHandler documentModeHandler) Sets the document mode handler.voidsetEntityResolver(EntityResolver resolver) voidsetErrorHandler(ErrorHandler handler) voidsetHeuristics(Heuristics heuristics) Sets the encoding sniffing heuristics.voidsetHtml4ModeCompatibleWithXhtml1Schemata(boolean html4ModeCompatibleWithXhtml1Schemata) Whether the HTML 4 mode reports boolean attributes in a way that repeats the name in the value.voidsetIgnoringComments(boolean ignoreComments) Sets whether comment nodes appear in the tree.voidsetMappingLangToXmlLang(boolean mappingLangToXmlLang) Whetherlangis mapped toxml:lang.voidsetNamePolicy(XmlViolationPolicy namePolicy) The policy for non-NCName element and attribute names.voidsetReportingDoctype(boolean reportingDoctype) voidsetScriptingEnabled(boolean scriptingEnabled) Sets whether the parser considers scripting to be enabled for noscript treatment.voidsetStreamabilityViolationPolicy(XmlViolationPolicy streamabilityViolationPolicy) Sets the streamabilityViolationPolicy.voidsetTransitionHander(TransitionHandler handler) voidsetXmlnsPolicy(XmlViolationPolicy xmlnsPolicy) Whether thexmlnsattribute on the root element is passed to through.voidsetXmlPolicy(XmlViolationPolicy xmlPolicy) This is a catch-all convenience method for setting name, xmlns, content space, content non-XML char and comment policies in one go.private voidtokenize(InputSource is) Methods inherited from class nu.xom.Builder
getNodeFactory
-
Field Details
-
driver
-
treeBuilder
-
simpleNodeFactory
-
entityResolver
-
errorHandler
-
documentModeHandler
-
doctypeExpectation
-
checkingNormalization
private boolean checkingNormalization -
scriptingEnabled
private boolean scriptingEnabled -
characterHandlers
-
contentSpacePolicy
-
contentNonXmlCharPolicy
-
commentPolicy
-
namePolicy
-
streamabilityViolationPolicy
-
html4ModeCompatibleWithXhtml1Schemata
private boolean html4ModeCompatibleWithXhtml1Schemata -
mappingLangToXmlLang
private boolean mappingLangToXmlLang -
xmlnsPolicy
-
reportingDoctype
private boolean reportingDoctype -
treeBuilderErrorHandler
-
heuristics
-
transitionHandler
-
-
Constructor Details
-
HtmlBuilder
public HtmlBuilder()Constructor with default node factory and fatal XML violation policy. -
HtmlBuilder
Constructor with given node factory and fatal XML violation policy.- Parameters:
nodeFactory- the factory
-
HtmlBuilder
Constructor with default node factory and given XML violation policy.- Parameters:
xmlPolicy- the policy
-
HtmlBuilder
Constructor with given node factory and given XML violation policy.- Parameters:
nodeFactory- the factoryxmlPolicy- the policy
-
-
Method Details
-
newTokenizer
-
lazyInit
private void lazyInit()This class wraps different tree builders depending on configuration. This method does the work of hiding this from the user of the class. -
tokenize
private void tokenize(InputSource is) throws nu.xom.ParsingException, IOException, MalformedURLException - Throws:
nu.xom.ParsingExceptionIOExceptionMalformedURLException
-
build
Parse from SAXInputSource.- Parameters:
is- theInputSource- Returns:
- the document
- Throws:
nu.xom.ParsingException- in case of an XML violationIOException- if IO goes wrang
-
buildFragment
public nu.xom.Nodes buildFragment(InputSource is, String context) throws IOException, nu.xom.ParsingException Parse a fragment from SAXInputSource.- Parameters:
is- theInputSourcecontext- the name of the context element- Returns:
- the fragment
- Throws:
nu.xom.ParsingException- in case of an XML violationIOException- if IO goes wrang
-
build
public nu.xom.Document build(File file) throws nu.xom.ParsingException, nu.xom.ValidityException, IOException Parse fromFile.- Overrides:
buildin classnu.xom.Builder- Parameters:
file- the file- Returns:
- the document
- Throws:
nu.xom.ParsingException- in case of an XML violationIOException- if IO goes wrangnu.xom.ValidityException- See Also:
-
build
public nu.xom.Document build(InputStream stream, String uri) throws nu.xom.ParsingException, nu.xom.ValidityException, IOException Parse fromInputStream.- Overrides:
buildin classnu.xom.Builder- Parameters:
stream- the streamuri- the base URI- Returns:
- the document
- Throws:
nu.xom.ParsingException- in case of an XML violationIOException- if IO goes wrangnu.xom.ValidityException- See Also:
-
build
public nu.xom.Document build(InputStream stream) throws nu.xom.ParsingException, nu.xom.ValidityException, IOException Parse fromInputStream.- Overrides:
buildin classnu.xom.Builder- Parameters:
stream- the stream- Returns:
- the document
- Throws:
nu.xom.ParsingException- in case of an XML violationIOException- if IO goes wrangnu.xom.ValidityException- See Also:
-
build
public nu.xom.Document build(Reader stream, String uri) throws nu.xom.ParsingException, nu.xom.ValidityException, IOException Parse fromReader.- Overrides:
buildin classnu.xom.Builder- Parameters:
stream- the readeruri- the base URI- Returns:
- the document
- Throws:
nu.xom.ParsingException- in case of an XML violationIOException- if IO goes wrangnu.xom.ValidityException- See Also:
-
build
public nu.xom.Document build(Reader stream) throws nu.xom.ParsingException, nu.xom.ValidityException, IOException Parse fromReader.- Overrides:
buildin classnu.xom.Builder- Parameters:
stream- the reader- Returns:
- the document
- Throws:
nu.xom.ParsingException- in case of an XML violationIOException- if IO goes wrangnu.xom.ValidityException- See Also:
-
build
public nu.xom.Document build(String content, String uri) throws nu.xom.ParsingException, nu.xom.ValidityException, IOException Parse fromString.- Overrides:
buildin classnu.xom.Builder- Parameters:
content- the HTML source as stringuri- the base URI- Returns:
- the document
- Throws:
nu.xom.ParsingException- in case of an XML violationIOException- if IO goes wrangnu.xom.ValidityException- See Also:
-
build
public nu.xom.Document build(String uri) throws nu.xom.ParsingException, nu.xom.ValidityException, IOException Parse from URI.- Overrides:
buildin classnu.xom.Builder- Parameters:
uri- the URI of the document- Returns:
- the document
- Throws:
nu.xom.ParsingException- in case of an XML violationIOException- if IO goes wrangnu.xom.ValidityException- See Also:
-
getSimpleNodeFactory
Gets the node factory -
setEntityResolver
- See Also:
-
setErrorHandler
- See Also:
-
setTransitionHander
-
isCheckingNormalization
public boolean isCheckingNormalization()Indicates whether NFC normalization of source is being checked.- Returns:
trueif NFC normalization of source is being checked.- See Also:
-
setCheckingNormalization
public void setCheckingNormalization(boolean enable) Toggles the checking of the NFC normalization of source.- Parameters:
enable-trueto check normalization- See Also:
-
setCommentPolicy
Sets the policy for consecutive hyphens in comments.- Parameters:
commentPolicy- the policy- See Also:
-
setContentNonXmlCharPolicy
Sets the policy for non-XML characters except white space.- Parameters:
contentNonXmlCharPolicy- the policy- See Also:
-
setContentSpacePolicy
Sets the policy for non-XML white space.- Parameters:
contentSpacePolicy- the policy- See Also:
-
isScriptingEnabled
public boolean isScriptingEnabled()Whether the parser considers scripting to be enabled for noscript treatment.- Returns:
trueif enabled- See Also:
-
setScriptingEnabled
public void setScriptingEnabled(boolean scriptingEnabled) Sets whether the parser considers scripting to be enabled for noscript treatment.- Parameters:
scriptingEnabled-trueto enable- See Also:
-
getDoctypeExpectation
Returns the doctype expectation.- Returns:
- the doctypeExpectation
-
setDoctypeExpectation
Sets the doctype expectation.- Parameters:
doctypeExpectation- the doctypeExpectation to set- See Also:
-
getDocumentModeHandler
Returns the document mode handler.- Returns:
- the documentModeHandler
-
setDocumentModeHandler
Sets the document mode handler.- Parameters:
documentModeHandler- the documentModeHandler to set- See Also:
-
getStreamabilityViolationPolicy
Returns the streamabilityViolationPolicy.- Returns:
- the streamabilityViolationPolicy
-
setStreamabilityViolationPolicy
Sets the streamabilityViolationPolicy.- Parameters:
streamabilityViolationPolicy- the streamabilityViolationPolicy to set
-
setHtml4ModeCompatibleWithXhtml1Schemata
public void setHtml4ModeCompatibleWithXhtml1Schemata(boolean html4ModeCompatibleWithXhtml1Schemata) Whether the HTML 4 mode reports boolean attributes in a way that repeats the name in the value.- Parameters:
html4ModeCompatibleWithXhtml1Schemata-
-
getDocumentLocator
Returns theLocatorduring parse.- Returns:
- the
Locator
-
isHtml4ModeCompatibleWithXhtml1Schemata
public boolean isHtml4ModeCompatibleWithXhtml1Schemata()Whether the HTML 4 mode reports boolean attributes in a way that repeats the name in the value.- Returns:
- the html4ModeCompatibleWithXhtml1Schemata
-
setMappingLangToXmlLang
public void setMappingLangToXmlLang(boolean mappingLangToXmlLang) Whetherlangis mapped toxml:lang.- Parameters:
mappingLangToXmlLang-- See Also:
-
isMappingLangToXmlLang
public boolean isMappingLangToXmlLang()Whetherlangis mapped toxml:lang.- Returns:
- the mappingLangToXmlLang
-
setXmlnsPolicy
Whether thexmlnsattribute on the root element is passed to through. (FATAL not allowed.)- Parameters:
xmlnsPolicy-- See Also:
-
getXmlnsPolicy
Returns the xmlnsPolicy.- Returns:
- the xmlnsPolicy
-
getCommentPolicy
Returns the commentPolicy.- Returns:
- the commentPolicy
-
getContentNonXmlCharPolicy
Returns the contentNonXmlCharPolicy.- Returns:
- the contentNonXmlCharPolicy
-
getContentSpacePolicy
Returns the contentSpacePolicy.- Returns:
- the contentSpacePolicy
-
setReportingDoctype
public void setReportingDoctype(boolean reportingDoctype) - Parameters:
reportingDoctype-- See Also:
-
isReportingDoctype
public boolean isReportingDoctype()Returns the reportingDoctype.- Returns:
- the reportingDoctype
-
setNamePolicy
The policy for non-NCName element and attribute names.- Parameters:
namePolicy-- See Also:
-
setHeuristics
Sets the encoding sniffing heuristics.- Parameters:
heuristics- the heuristics to set- See Also:
-
getHeuristics
-
setXmlPolicy
This is a catch-all convenience method for setting name, xmlns, content space, content non-XML char and comment policies in one go. This does not affect the streamability policy or doctype reporting.- Parameters:
xmlPolicy-
-
getNamePolicy
The policy for non-NCName element and attribute names.- Returns:
- the namePolicy
-
setBogusXmlnsPolicy
Deprecated.Does nothing. -
getBogusXmlnsPolicy
Deprecated.ReturnsXmlViolationPolicy.ALTER_INFOSET.- Returns:
XmlViolationPolicy.ALTER_INFOSET
-
addCharacterHandler
-
setIgnoringComments
public void setIgnoringComments(boolean ignoreComments) Sets whether comment nodes appear in the tree.- Parameters:
ignoreComments-trueto ignore comments- See Also:
-