Class AbstractDOMParser
- java.lang.Object
-
- org.htmlunit.cyberneko.xerces.parsers.XMLParser
-
- org.htmlunit.cyberneko.xerces.parsers.AbstractXMLDocumentParser
-
- org.htmlunit.cyberneko.xerces.parsers.AbstractDOMParser
-
- All Implemented Interfaces:
XMLDocumentHandler
- Direct Known Subclasses:
DOMParser
public class AbstractDOMParser extends AbstractXMLDocumentParser
This is the base class of all DOM parsers. It implements the XNI callback methods to create the DOM tree. After a successful parse of an XML document, the DOM Document object can be queried using thegetDocument
method. The actual pipeline is defined in parser configuration.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
CREATE_CDATA_NODES_FEATURE
Feature id: create cdata nodes.private static boolean
DEBUG_EVENTS
private QName
fAttrQName
Attribute QName.protected java.util.Stack<java.lang.String>
fBaseURIStack
Base uri stackprotected boolean
fCreateCDATANodes
Create cdata nodes.protected org.w3c.dom.CDATASection
fCurrentCDATASection
protected EntityImpl
fCurrentEntityDecl
protected org.w3c.dom.Node
fCurrentNode
Current node.protected org.w3c.dom.Document
fDocument
The document.protected java.lang.Class<? extends DocumentImpl>
fDocumentClass
The document class to use.protected CoreDocumentImpl
fDocumentImpl
The default Xerces document implementation, if used.protected org.w3c.dom.DocumentType
fDocumentType
The document type node.protected boolean
fFirstChunk
True if saw the first chunk of charactersprotected boolean
fInCDATASection
True if inside CDATA section.protected boolean
fIncludeComments
Include Comments.private XMLLocator
fLocator
Document locator.protected boolean
fNamespaceAware
protected XMLString
fStringBuffer
Character bufferprotected static java.lang.String
INCLUDE_COMMENTS_FEATURE
Feature id: include comments.protected static java.lang.String
NAMESPACES
Feature id: namespace.private static java.lang.String[]
RECOGNIZED_FEATURES
Recognized features.private static java.lang.String[]
RECOGNIZED_PROPERTIES
Recognized properties.-
Fields inherited from class org.htmlunit.cyberneko.xerces.parsers.XMLParser
ERROR_HANDLER, parserConfiguration_
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDOMParser(XMLParserConfiguration config, java.lang.Class<? extends DocumentImpl> documentClass)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(XMLString text, Augmentations augs)
Character content.void
comment(XMLString text, Augmentations augs)
A comment.protected org.w3c.dom.Attr
createAttrNode(QName attrQName)
protected org.w3c.dom.Element
createElementNode(QName element)
void
doctypeDecl(java.lang.String rootElement, java.lang.String publicId, java.lang.String systemId, Augmentations augs)
Notifies of the presence of the DOCTYPE line in the document.void
emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
An empty element.void
endCDATA(Augmentations augs)
The end of a CDATA section.void
endDocument(Augmentations augs)
The end of the document.void
endElement(QName element, Augmentations augs)
The end of an element.org.w3c.dom.Document
getDocument()
org.xml.sax.ErrorHandler
getErrorHandler()
Return the current error handler.boolean
getFeature(java.lang.String featureId)
Query the state of a feature.XMLParserConfiguration
getXMLParserConfiguration()
protected void
handleBaseURI(org.w3c.dom.Node node)
Record baseURI information for the Element (by adding xml:base attribute) or for the ProcessingInstruction (by setting a baseURI field) Non deferred DOM.void
parse(java.lang.String systemId)
Parses the input source specified by the given system identifier.void
parse(org.xml.sax.InputSource inputSource)
Parse.void
processingInstruction(java.lang.String target, XMLString data, Augmentations augs)
A processing instruction.void
reset()
Resets the parser state.protected void
setCharacterData(boolean sawChars)
protected void
setDocumentClass(java.lang.Class<? extends DocumentImpl> documentClass)
This method allows the programmer to decide which document factory to use when constructing the DOM tree.void
setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Allow an application to register an error event handler.void
setFeature(java.lang.String featureId, boolean state)
Set the state of any feature in a SAX2 parser.void
setProperty(java.lang.String propertyId, java.lang.Object value)
Set the value of any property in a SAX2 parser.void
startCDATA(Augmentations augs)
The start of a CDATA section.void
startDocument(XMLLocator locator, java.lang.String encoding, NamespaceContext namespaceContext, Augmentations augs)
The start of the document.void
startElement(QName element, XMLAttributes attributes, Augmentations augs)
The start of an element.void
xmlDecl(java.lang.String version, java.lang.String encoding, java.lang.String standalone, Augmentations augs)
Notifies of the presence of an XMLDecl line in the document.-
Methods inherited from class org.htmlunit.cyberneko.xerces.parsers.AbstractXMLDocumentParser
getDocumentSource, setDocumentSource
-
-
-
-
Field Detail
-
NAMESPACES
protected static final java.lang.String NAMESPACES
Feature id: namespace.- See Also:
- Constant Field Values
-
INCLUDE_COMMENTS_FEATURE
protected static final java.lang.String INCLUDE_COMMENTS_FEATURE
Feature id: include comments.- See Also:
- Constant Field Values
-
CREATE_CDATA_NODES_FEATURE
protected static final java.lang.String CREATE_CDATA_NODES_FEATURE
Feature id: create cdata nodes.- See Also:
- Constant Field Values
-
RECOGNIZED_FEATURES
private static final java.lang.String[] RECOGNIZED_FEATURES
Recognized features.
-
RECOGNIZED_PROPERTIES
private static final java.lang.String[] RECOGNIZED_PROPERTIES
Recognized properties.
-
DEBUG_EVENTS
private static final boolean DEBUG_EVENTS
- See Also:
- Constant Field Values
-
fIncludeComments
protected boolean fIncludeComments
Include Comments.
-
fCreateCDATANodes
protected boolean fCreateCDATANodes
Create cdata nodes.
-
fDocument
protected org.w3c.dom.Document fDocument
The document.
-
fDocumentImpl
protected CoreDocumentImpl fDocumentImpl
The default Xerces document implementation, if used.
-
fDocumentClass
protected java.lang.Class<? extends DocumentImpl> fDocumentClass
The document class to use.
-
fDocumentType
protected org.w3c.dom.DocumentType fDocumentType
The document type node.
-
fCurrentNode
protected org.w3c.dom.Node fCurrentNode
Current node.
-
fCurrentCDATASection
protected org.w3c.dom.CDATASection fCurrentCDATASection
-
fCurrentEntityDecl
protected EntityImpl fCurrentEntityDecl
-
fStringBuffer
protected final XMLString fStringBuffer
Character buffer
-
fNamespaceAware
protected boolean fNamespaceAware
-
fInCDATASection
protected boolean fInCDATASection
True if inside CDATA section.
-
fFirstChunk
protected boolean fFirstChunk
True if saw the first chunk of characters
-
fBaseURIStack
protected final java.util.Stack<java.lang.String> fBaseURIStack
Base uri stack
-
fAttrQName
private final QName fAttrQName
Attribute QName.
-
fLocator
private XMLLocator fLocator
Document locator.
-
-
Constructor Detail
-
AbstractDOMParser
protected AbstractDOMParser(XMLParserConfiguration config, java.lang.Class<? extends DocumentImpl> documentClass)
-
-
Method Detail
-
setDocumentClass
protected void setDocumentClass(java.lang.Class<? extends DocumentImpl> documentClass)
This method allows the programmer to decide which document factory to use when constructing the DOM tree. However, doing so will lose the functionality of the default factory. Also, a document class other than the default will lose the ability to defer node expansion on the DOM tree produced.- Parameters:
documentClass
- The document factory to use when constructing the DOM tree.
-
getDocument
public org.w3c.dom.Document getDocument()
- Returns:
- the DOM document object.
-
reset
public void reset() throws XNIException
Resets the parser state.- Overrides:
reset
in classXMLParser
- Throws:
XNIException
- Thrown on initialization error.
-
comment
public void comment(XMLString text, Augmentations augs) throws XNIException
A comment.- Specified by:
comment
in interfaceXMLDocumentHandler
- Overrides:
comment
in classAbstractXMLDocumentParser
- Parameters:
text
- The text in the comment.augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by application to signal an error.
-
processingInstruction
public void processingInstruction(java.lang.String target, XMLString data, Augmentations augs) throws XNIException
A processing instruction. Processing instructions consist of a target name and, optionally, text data. The data is only meaningful to the application.Typically, a processing instruction's data will contain a series of pseudo-attributes. These pseudo-attributes follow the form of element attributes but are not parsed or presented to the application as anything other than text. The application is responsible for parsing the data.
- Specified by:
processingInstruction
in interfaceXMLDocumentHandler
- Overrides:
processingInstruction
in classAbstractXMLDocumentParser
- Parameters:
target
- The target.data
- The data or null if none specified.augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
startDocument
public void startDocument(XMLLocator locator, java.lang.String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException
The start of the document.- Specified by:
startDocument
in interfaceXMLDocumentHandler
- Overrides:
startDocument
in classAbstractXMLDocumentParser
- Parameters:
locator
- The system identifier of the entity if the entity is external, null otherwise.encoding
- The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal entities or a document entity that is parsed from a java.io.Reader).namespaceContext
- The namespace context in effect at the start of this document. This object represents the current context. Implementors of this class are responsible for copying the namespace bindings from the the current context (and its parent contexts) if that information is important.augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
xmlDecl
public void xmlDecl(java.lang.String version, java.lang.String encoding, java.lang.String standalone, Augmentations augs) throws XNIException
Notifies of the presence of an XMLDecl line in the document. If present, this method will be called immediately following the startDocument call.- Specified by:
xmlDecl
in interfaceXMLDocumentHandler
- Overrides:
xmlDecl
in classAbstractXMLDocumentParser
- Parameters:
version
- The XML version.encoding
- The IANA encoding name of the document, or null if not specified.standalone
- The standalone value, or null if not specified.augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
doctypeDecl
public void doctypeDecl(java.lang.String rootElement, java.lang.String publicId, java.lang.String systemId, Augmentations augs) throws XNIException
Notifies of the presence of the DOCTYPE line in the document.- Specified by:
doctypeDecl
in interfaceXMLDocumentHandler
- Overrides:
doctypeDecl
in classAbstractXMLDocumentParser
- Parameters:
rootElement
- The name of the root element.publicId
- The public identifier if an external DTD or null if the external DTD is specified using SYSTEM.systemId
- The system identifier if an external DTD, null otherwise.augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
startElement
public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException
The start of an element. If the document specifies the start element by using an empty tag, then the startElement method will immediately be followed by the endElement method, with no intervening methods.- Specified by:
startElement
in interfaceXMLDocumentHandler
- Overrides:
startElement
in classAbstractXMLDocumentParser
- Parameters:
element
- The name of the element.attributes
- The element attributes.augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
emptyElement
public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException
An empty element.- Specified by:
emptyElement
in interfaceXMLDocumentHandler
- Overrides:
emptyElement
in classAbstractXMLDocumentParser
- Parameters:
element
- The name of the element.attributes
- The element attributes.augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
characters
public void characters(XMLString text, Augmentations augs) throws XNIException
Character content.- Specified by:
characters
in interfaceXMLDocumentHandler
- Overrides:
characters
in classAbstractXMLDocumentParser
- Parameters:
text
- The content.augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
endElement
public void endElement(QName element, Augmentations augs) throws XNIException
The end of an element.- Specified by:
endElement
in interfaceXMLDocumentHandler
- Overrides:
endElement
in classAbstractXMLDocumentParser
- Parameters:
element
- The name of the element.augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
startCDATA
public void startCDATA(Augmentations augs) throws XNIException
The start of a CDATA section.- Specified by:
startCDATA
in interfaceXMLDocumentHandler
- Overrides:
startCDATA
in classAbstractXMLDocumentParser
- Parameters:
augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
endCDATA
public void endCDATA(Augmentations augs) throws XNIException
The end of a CDATA section.- Specified by:
endCDATA
in interfaceXMLDocumentHandler
- Overrides:
endCDATA
in classAbstractXMLDocumentParser
- Parameters:
augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
endDocument
public void endDocument(Augmentations augs) throws XNIException
The end of the document.- Specified by:
endDocument
in interfaceXMLDocumentHandler
- Overrides:
endDocument
in classAbstractXMLDocumentParser
- Parameters:
augs
- Additional information that may include infoset augmentations- Throws:
XNIException
- Thrown by handler to signal an error.
-
handleBaseURI
protected final void handleBaseURI(org.w3c.dom.Node node)
Record baseURI information for the Element (by adding xml:base attribute) or for the ProcessingInstruction (by setting a baseURI field) Non deferred DOM.- Parameters:
node
- the node
-
createElementNode
protected org.w3c.dom.Element createElementNode(QName element)
-
createAttrNode
protected org.w3c.dom.Attr createAttrNode(QName attrQName)
-
setCharacterData
protected void setCharacterData(boolean sawChars)
-
parse
public void parse(java.lang.String systemId) throws org.xml.sax.SAXException, java.io.IOException
Parses the input source specified by the given system identifier.This method is equivalent to the following:
parse(new InputSource(systemId));
- Parameters:
systemId
- The system identifier (URI).- Throws:
org.xml.sax.SAXException
- Throws exception on SAX error.java.io.IOException
- Throws exception on i/o error.
-
parse
public void parse(org.xml.sax.InputSource inputSource) throws org.xml.sax.SAXException, java.io.IOException
Parse.- Parameters:
inputSource
- the input source- Throws:
org.xml.sax.SAXException
- on errorjava.io.IOException
- on error
-
setErrorHandler
public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Allow an application to register an error event handler.If the application does not register an error handler, all error events reported by the SAX parser will be silently ignored; however, normal processing may not continue. It is highly recommended that all SAX applications implement an error handler to avoid unexpected bugs.
Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.
- Parameters:
errorHandler
- The error handler.- Throws:
java.lang.NullPointerException
- If the handler argument is null.- See Also:
getErrorHandler()
-
getErrorHandler
public org.xml.sax.ErrorHandler getErrorHandler()
Return the current error handler.- Returns:
- The current error handler, or null if none has been registered.
- See Also:
setErrorHandler(org.xml.sax.ErrorHandler)
-
setFeature
public void setFeature(java.lang.String featureId, boolean state) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Set the state of any feature in a SAX2 parser. The parser might not recognize the feature, and if it does recognize it, it might not be able to fulfill the request.- Parameters:
featureId
- The unique identifier (URI) of the feature.state
- The requested state of the feature (true or false).- Throws:
org.xml.sax.SAXNotRecognizedException
- If the requested feature is not known.org.xml.sax.SAXNotSupportedException
- If the requested feature is known, but the requested state is not supported.
-
getFeature
public boolean getFeature(java.lang.String featureId) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Query the state of a feature.Query the current state of any feature in a SAX2 parser. The parser might not recognize the feature.
- Parameters:
featureId
- The unique identifier (URI) of the feature being set.- Returns:
- The current state of the feature.
- Throws:
org.xml.sax.SAXNotRecognizedException
- If the requested feature is not known.org.xml.sax.SAXNotSupportedException
- If the requested feature is known but not supported.
-
setProperty
public void setProperty(java.lang.String propertyId, java.lang.Object value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Set the value of any property in a SAX2 parser. The parser might not recognize the property, and if it does recognize it, it might not support the requested value.- Parameters:
propertyId
- The unique identifier (URI) of the property being set.value
- The value to which the property is being set.- Throws:
org.xml.sax.SAXNotRecognizedException
- If the requested property is not known.org.xml.sax.SAXNotSupportedException
- If the requested property is known, but the requested value is not supported.
-
getXMLParserConfiguration
public XMLParserConfiguration getXMLParserConfiguration()
- Returns:
- this parser's XMLParserConfiguration.
-
-