Class DefaultContentHandler
- java.lang.Object
-
- com.aquima.interactions.foundation.xml.parsing.DefaultContentHandler
-
- All Implemented Interfaces:
ContentHandler
public class DefaultContentHandler extends Object implements ContentHandler
Default SAX2 ContentHandler base class. Does nothing (all handling methods are empty).Subclass this and override the methods you need, then set this class as the ContentHandler for the SAX parser. This way you don't have to implement the methods you don't need, because this base class has an implementation.
This contenthandler also has a special method to be able to use sub-contenthandlers easily.
Some stuff is implemented here: the location handler and some methods to get a location string / exception.
- Since:
- 5.0
- Author:
- IdJ
-
-
Constructor Summary
Constructors Constructor Description DefaultContentHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] chars, int start, int length)
void
endDocument()
void
endElement(String namespaceURI, String localName, String qName)
void
endPrefixMapping(String prefix)
String
getLocationString()
Returns a string of the current location.void
ignorableWhitespace(char[] chars, int start, int length)
void
parseError(String msg)
Throws a SAXException with location string.void
processingInstruction(String target, String data)
void
setDocumentLocator(Locator loc)
SAX2 document locator, called when parser starts.void
skippedEntity(String name)
void
startDocument()
void
startElement(String namespaceURI, String localName, String qName, Attributes attrs)
void
startPrefixMapping(String prefix, String uri)
void
subHandlerFinished(String nsURI, String lName, String qName)
called by a subhandler when it is done, it will supply the data of the last XML element.
-
-
-
Method Detail
-
setDocumentLocator
public void setDocumentLocator(Locator loc)
SAX2 document locator, called when parser starts.- Specified by:
setDocumentLocator
in interfaceContentHandler
- Parameters:
loc
- The document locator that should be used.
-
parseError
public void parseError(String msg) throws SAXException
Throws a SAXException with location string. You can use this yourself when you discover additional problems while parsing the XML. Your Content Handler can call this.parseError("something's wrong") and bail out easily.- Parameters:
msg
- Message containing the cause of the error.- Throws:
SAXException
- This exception is always thrown containing the message and the location in the XML.
-
getLocationString
public String getLocationString()
Returns a string of the current location.- Returns:
- a string of the current location.
-
startDocument
public void startDocument() throws SAXException
- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXException
- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
- Specified by:
endPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) throws SAXException
- Specified by:
startElement
in interfaceContentHandler
- Throws:
SAXException
-
endElement
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
- Specified by:
endElement
in interfaceContentHandler
- Throws:
SAXException
-
characters
public void characters(char[] chars, int start, int length) throws SAXException
- Specified by:
characters
in interfaceContentHandler
- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] chars, int start, int length) throws SAXException
- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Throws:
SAXException
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
- Specified by:
processingInstruction
in interfaceContentHandler
- Throws:
SAXException
-
skippedEntity
public void skippedEntity(String name) throws SAXException
- Specified by:
skippedEntity
in interfaceContentHandler
- Throws:
SAXException
-
subHandlerFinished
public void subHandlerFinished(String nsURI, String lName, String qName)
called by a subhandler when it is done, it will supply the data of the last XML element.- Parameters:
nsURI
- the namespace URI of the eltlName
- the local name of the eltqName
- the qualified (prefixed) name of the elt
-
-