Class DOMFragmentParser
- java.lang.Object
-
- org.htmlunit.cyberneko.parsers.DOMFragmentParser
-
- All Implemented Interfaces:
XMLDocumentHandler
public class DOMFragmentParser extends Object implements XMLDocumentHandler
A DOM parser for HTML fragments.- Author:
- Andy Clark
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringERROR_HANDLERProperty identifier: error handler.protected static String[]RECOGNIZED_FEATURESRecognized features.protected static String[]RECOGNIZED_PROPERTIESRecognized properties.
-
Constructor Summary
Constructors Constructor Description DOMFragmentParser()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(XMLString text, Augmentations augs)Character content.voidcomment(XMLString text, Augmentations augs)A comment.voiddoctypeDecl(String root, String pubid, String sysid, Augmentations augs)Notifies of the presence of the DOCTYPE line in the document.voidemptyElement(QName element, XMLAttributes attrs, Augmentations augs)An empty element.voidendCDATA(Augmentations augs)End CDATA section.voidendDocument(Augmentations augs)End document.voidendElement(QName element, Augmentations augs)End element.XMLDocumentSourcegetDocumentSource()ErrorHandlergetErrorHandler()Return the current error handler.booleangetFeature(String featureId)Query the state of a feature.XMLParserConfigurationgetXMLParserConfiguration()voidparse(String systemId, DocumentFragment fragment)Parses a document fragmentvoidparse(InputSource source, DocumentFragment fragment)Parses a document fragmentvoidprocessingInstruction(String target, XMLString data, Augmentations augs)A processing instruction.voidsetDocumentSource(XMLDocumentSource source)Sets the document source.voidsetErrorHandler(ErrorHandler errorHandler)Allow an application to register an error event handler.voidsetFeature(String featureId, boolean state)Set the state of any feature in a SAX2 parser.voidsetProperty(String propertyId, Object value)Set the value of any property in a SAX2 parser.voidstartCDATA(Augmentations augs)Start CDATA section.voidstartDocument(XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)The start of the document.voidstartElement(QName element, XMLAttributes attrs, Augmentations augs)The start of an element.voidxmlDecl(String version, String encoding, String standalone, Augmentations augs)Notifies of the presence of an XMLDecl line in the document.
-
-
-
Field Detail
-
RECOGNIZED_FEATURES
protected static final String[] RECOGNIZED_FEATURES
Recognized features.
-
ERROR_HANDLER
protected static final String ERROR_HANDLER
Property identifier: error handler.- See Also:
- Constant Field Values
-
RECOGNIZED_PROPERTIES
protected static final String[] RECOGNIZED_PROPERTIES
Recognized properties.
-
-
Method Detail
-
parse
public void parse(String systemId, DocumentFragment fragment) throws SAXException, IOException
Parses a document fragment- Parameters:
systemId- systemIdfragment- fragment- Throws:
SAXException- in case of sax errorIOException- in case of io problems
-
parse
public void parse(InputSource source, DocumentFragment fragment) throws SAXException, IOException
Parses a document fragment- Parameters:
source- input sourcefragment- fragment- Throws:
SAXException- in case of sax errorIOException- in case of io problems
-
setErrorHandler
public void setErrorHandler(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:
NullPointerException- If the handler argument is null.- See Also:
getErrorHandler()
-
getErrorHandler
public 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(String featureId, boolean state) throws SAXNotRecognizedException, 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:
SAXNotRecognizedException- If the requested feature is not known.SAXNotSupportedException- If the requested feature is known, but the requested state is not supported.
-
getFeature
public boolean getFeature(String featureId) throws SAXNotRecognizedException, 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:
SAXNotRecognizedException- If the requested feature is not known.SAXNotSupportedException- If the requested feature is known but not supported.
-
setProperty
public void setProperty(String propertyId, Object value) throws SAXNotRecognizedException, 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:
SAXNotRecognizedException- If the requested property is not known.SAXNotSupportedException- If the requested property is known, but the requested value is not supported.
-
startDocument
public void startDocument(XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs) throws XNIException
Description copied from interface:XMLDocumentHandlerThe start of the document.- Specified by:
startDocumentin interfaceXMLDocumentHandler- Parameters:
locator- The document locator, or null if the document location cannot be reported during the parsing of this document. However, it is strongly recommended that a locator be supplied that can at least report the system identifier of the document.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).nscontext- 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(String version, String encoding, String standalone, Augmentations augs) throws XNIException
Description copied from interface:XMLDocumentHandlerNotifies of the presence of an XMLDecl line in the document. If present, this method will be called immediately following the startDocument call.- Specified by:
xmlDeclin interfaceXMLDocumentHandler- 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(String root, String pubid, String sysid, Augmentations augs) throws XNIException
Description copied from interface:XMLDocumentHandlerNotifies of the presence of the DOCTYPE line in the document.- Specified by:
doctypeDeclin interfaceXMLDocumentHandler- Parameters:
root- The name of the root element.pubid- The public identifier if an external DTD or null if the external DTD is specified using SYSTEM.sysid- 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.
-
processingInstruction
public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException
Description copied from interface:XMLDocumentHandlerA 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:
processingInstructionin interfaceXMLDocumentHandler- 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.
-
comment
public void comment(XMLString text, Augmentations augs) throws XNIException
Description copied from interface:XMLDocumentHandlerA comment.- Specified by:
commentin interfaceXMLDocumentHandler- Parameters:
text- The text in the comment.augs- Additional information that may include infoset augmentations- Throws:
XNIException- Thrown by application to signal an error.
-
startElement
public void startElement(QName element, XMLAttributes attrs, Augmentations augs) throws XNIException
Description copied from interface:XMLDocumentHandlerThe start of an element.- Specified by:
startElementin interfaceXMLDocumentHandler- Parameters:
element- The name of the element.attrs- 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 attrs, Augmentations augs) throws XNIException
Description copied from interface:XMLDocumentHandlerAn empty element.- Specified by:
emptyElementin interfaceXMLDocumentHandler- Parameters:
element- The name of the element.attrs- 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
Description copied from interface:XMLDocumentHandlerCharacter content.- Specified by:
charactersin interfaceXMLDocumentHandler- Parameters:
text- The content.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
Start CDATA section.- Specified by:
startCDATAin interfaceXMLDocumentHandler- 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
End CDATA section.- Specified by:
endCDATAin interfaceXMLDocumentHandler- Parameters:
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
End element.- Specified by:
endElementin interfaceXMLDocumentHandler- Parameters:
element- The name of the element.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
End document.- Specified by:
endDocumentin interfaceXMLDocumentHandler- Parameters:
augs- Additional information that may include infoset augmentations- Throws:
XNIException- Thrown by handler to signal an error.
-
getXMLParserConfiguration
public XMLParserConfiguration getXMLParserConfiguration()
- Returns:
- the XMLParserConfiguration
-
setDocumentSource
public void setDocumentSource(XMLDocumentSource source)
Sets the document source.- Specified by:
setDocumentSourcein interfaceXMLDocumentHandler- Parameters:
source- the new source
-
getDocumentSource
public XMLDocumentSource getDocumentSource()
- Specified by:
getDocumentSourcein interfaceXMLDocumentHandler- Returns:
- the document source.
-
-