public class ResolverSAXHandler extends DefaultHandler2 implements LSResourceResolver, InputSourceCaching
Modifier and Type | Class and Description |
---|---|
static class |
ResolverSAXHandler.ExceptionResult
Represent an exception result returned after the parsing.
|
static class |
ResolverSAXHandler.InformationResult
Represent an information result returned after the parsing.
|
class |
ResolverSAXHandler.SourceWrapper
A class which wraps around an
InputSource to create a LSInput . |
Modifier and Type | Field and Description |
---|---|
static short |
CACHE_DEFAULT
The default caching behavior.
|
protected URL |
dtd |
static int |
ERRORS
The enumeration value for parsings which fire XML errors in parsing.
|
static int |
FATAL
The enumeration value for parsings which fire XML fatal errors in parsing.
|
static int |
INFO
The enumeration value for parsings which fire informations.
|
protected Locator |
locator
The Locator used for the handler.
|
static int |
NO_ERRORS
The enumeration value for parsings which fire no errors.
|
protected String |
publicDTD |
protected EntityListResolver |
resolver
The EntityListResolver (may be null).
|
protected List<ResolverSAXHandler.ExceptionResult> |
results
The list of results (exceptions and comments) for the parsing.
|
int |
status
The parsing state.
|
static int |
WARNINGS
The enumeration value for parsings which fire XML warnings in parsing.
|
CACHING_DEFAULT, CACHING_SOURCES, NOT_CACHING_SOURCES
Constructor and Description |
---|
ResolverSAXHandler() |
ResolverSAXHandler(List<ResolverSAXHandler.ExceptionResult> results)
Create a new ResolverSAXHandler with an existing list of results.
|
Modifier and Type | Method and Description |
---|---|
void |
endDocument()
Called at the end of the XML document.
|
void |
endDTD() |
void |
error(SAXParseException e)
Parsing errors will be silently ignored if they are encountered before the beginning of the Document and an alternated public DTD has been
defined for the handler.
|
void |
error(SAXParseException e,
Object properties)
Parsing errors will be silently ignored if they are encountered before the beginning of the Document and an alternated public DTD has been
defined for the handler.
|
protected void |
errorImpl(SAXParseException e)
Do nothing by default.
|
void |
fatalError(SAXParseException e)
Parsing errors will be silently ignored if they are encountered before the beginning of the Document and an alternated public DTD or
resolver has been defined for the handler.
|
void |
fatalError(SAXParseException e,
Object properties)
Parsing errors will be silently ignored if they are encountered before the beginning of the Document and an alternated public DTD or
resolver has been defined for the handler.
|
protected void |
fatalErrorImpl(SAXParseException e)
Do nothing.
|
URL |
getDocumentBaseURL()
Return the base URL of the parsed document.
|
Locator |
getDocumentLocator()
Return the document locator.
|
URL |
getDTD()
Return this handler DTD.
|
EntityListResolver |
getEntityResolver()
Return the entity resolver to use with this handler.
|
List<ResolverSAXHandler.ExceptionResult> |
getExceptionResults()
Return the list of exceptions results encountered during parsing.
|
List<SAXParseException> |
getExceptions()
Return the list of exceptions encountered during parsing.
|
SortedMap<Integer,List<ResolverSAXHandler.ExceptionResult>> |
getExceptionsResultsByLine()
Return the exceptions results encountered during parsing, sorted by their line number.
|
InputSource |
getExternalSubset(String name,
String baseURI)
Resolves publicIDs and systemIDs.
|
SAXParseException |
getFirstException()
Return the first SAX exception encountered during parsing.
|
short |
getInputSourceCaching()
Return the InputSources caching behavior.
|
int |
getStatus()
Return the final result status.
|
boolean |
hasErrors()
Return true if there is at least one warning after the parsing.
|
boolean |
hasParserExceptions()
Return true if the parser has some parser exceptions.
|
boolean |
hasStartedElements()
Return true if the document content (after the DTD) has already started to be parsed.
|
void |
info(String message)
Add an information to the results.
|
void |
info(String message,
Object properties)
Add an information to the results.
|
boolean |
isDocumentStarted()
Return true if the document is started.
|
boolean |
isElementStarted()
Return true if the first element has been encountered.
|
void |
reset()
Reset this handler.
|
InputSource |
resolveEntity(String name,
String systemID)
Resolves publicIDs and systemIDs.
|
InputSource |
resolveEntity(String name,
String publicID,
String baseURI,
String systemID)
Resolves publicIDs and systemIDs.
|
LSInput |
resolveResource(String type,
String namespaceURI,
String publicID,
String systemID,
String baseURI)
Allow the application to resolve external resources.
|
void |
restart()
Restart this handler.
|
void |
setDocumentLocator(Locator locator)
Return the document locator.
|
void |
setDTD(URL dtd,
String publicDTD)
Allows to force the DTD to use for the parsing (for example a resource of the application).
|
void |
setEntityResolver(EntityListResolver resolver)
Set the entity resolver to use with this handler (null by default).
|
void |
setInputSourceCaching(short cachingType)
Set the InputSources caching behavior.
|
void |
setStatus(int status)
Force the status.
|
void |
startDocument()
Receive notification of the beginning of the document.
|
void |
startElement(String uri,
String localname,
String qname,
Attributes attr)
Receive notification of the beginning of an element.
|
void |
warning(SAXParseException e)
Parsing errors will be silently ignored if they are encountered before the beginning of the Document and an alternated public DTD or
resolver has been defined for the handler.
|
void |
warning(SAXParseException e,
Object properties)
Parsing errors will be silently ignored if they are encountered before the beginning of the Document and an alternated public DTD or
resolver has been defined for the handler.
|
protected void |
warningImpl(SAXParseException e)
Do nothing.
|
attributeDecl, comment, elementDecl, endCDATA, endEntity, externalEntityDecl, internalEntityDecl, startCDATA, startDTD, startEntity
characters, endElement, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, skippedEntity, startPrefixMapping, unparsedEntityDecl
public static final int NO_ERRORS
public static final int INFO
public static final int WARNINGS
public static final int ERRORS
public static final int FATAL
public static final short CACHE_DEFAULT
public int status
protected URL dtd
protected String publicDTD
protected Locator locator
protected List<ResolverSAXHandler.ExceptionResult> results
protected EntityListResolver resolver
public ResolverSAXHandler(List<ResolverSAXHandler.ExceptionResult> results)
results
- the existing list of resultspublic ResolverSAXHandler()
public void setInputSourceCaching(short cachingType)
setInputSourceCaching
in interface InputSourceCaching
cachingType
- the caching typepublic short getInputSourceCaching()
getInputSourceCaching
in interface InputSourceCaching
public void setEntityResolver(EntityListResolver resolver)
resolver
- the entity resolverpublic EntityListResolver getEntityResolver()
public void setDTD(URL dtd, String publicDTD)
dtd
- the DTDpublicDTD
- the DTD public IDpublic URL getDTD()
public final boolean isDocumentStarted()
public final boolean isElementStarted()
public void restart()
isDocumentStarted()
and isElementStarted()
properties. This method can be useful when the user
want to reuse the same handler without clearing its results.public void reset()
public List<ResolverSAXHandler.ExceptionResult> getExceptionResults()
public SortedMap<Integer,List<ResolverSAXHandler.ExceptionResult>> getExceptionsResultsByLine()
public List<SAXParseException> getExceptions()
public boolean hasParserExceptions()
public SAXParseException getFirstException()
public void endDTD()
endDTD
in interface LexicalHandler
endDTD
in class DefaultHandler2
public void startDocument() throws SAXException
hasStartedElements()
property.startDocument
in interface ContentHandler
startDocument
in class DefaultHandler
SAXException
public boolean hasStartedElements()
public void startElement(String uri, String localname, String qname, Attributes attr) throws SAXException
hasStartedElements()
property to true. Sub-implementations of
this class should then perform super.startElement(...)
.startElement
in interface ContentHandler
startElement
in class DefaultHandler
uri
- The Namespace URIlocalname
- The local name (without prefix)qname
- The qualified name (with prefix)attr
- The attributes attached to the element.SAXException
public void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
setDocumentLocator
in class DefaultHandler
public Locator getDocumentLocator()
public boolean hasErrors()
public int getStatus()
public URL getDocumentBaseURL()
public void setStatus(int status)
status
- the statuspublic void error(SAXParseException e, Object properties)
e
- the SAX exceptionproperties
- the additional propertiespublic void error(SAXParseException e)
error
in interface ErrorHandler
error
in class DefaultHandler
e
- the SAX exceptionprotected void errorImpl(SAXParseException e)
error(org.xml.sax.SAXParseException)
.e
- the SAXParseExceptionpublic void fatalError(SAXParseException e, Object properties)
e
- the SAX exceptionproperties
- the additional propertiespublic void fatalError(SAXParseException e)
fatalError
in interface ErrorHandler
fatalError
in class DefaultHandler
e
- the SAX exceptionprotected void fatalErrorImpl(SAXParseException e)
fatalError(org.xml.sax.SAXParseException)
.e
- the SAXParseExceptionpublic void warning(SAXParseException e, Object properties)
e
- the SAX exceptionproperties
- the additional propertiespublic void warning(SAXParseException e)
warning
in interface ErrorHandler
warning
in class DefaultHandler
e
- the SAX exceptionprotected void warningImpl(SAXParseException e)
warning(org.xml.sax.SAXParseException)
.e
- the SAXParseExceptionpublic void info(String message, Object properties)
message
- the information messageproperties
- the additional propertiespublic void info(String message)
message
- the information messagepublic void endDocument() throws SAXException
endDocument
in interface ContentHandler
endDocument
in class DefaultHandler
SAXException
public InputSource getExternalSubset(String name, String baseURI) throws SAXException, IOException
getExternalSubset
in interface EntityResolver2
getExternalSubset
in class DefaultHandler2
name
- the entity namebaseURI
- The absolute base URI of the resource being parsed, or null if there is no base URI.SAXException
IOException
public InputSource resolveEntity(String name, String publicID, String baseURI, String systemID) throws SAXException, IOException
resolveEntity
in interface EntityResolver2
resolveEntity
in class DefaultHandler2
name
- the entity namepublicID
- The public identifier of the external entity being referenced, or null if no public identifier was suppliedbaseURI
- The absolute base URI of the resource being parsed, or null if there is no base URI.systemID
- The system identifier, a URI reference of the external resource being referenced, or null if no system identifier was suppliedSAXException
IOException
public InputSource resolveEntity(String name, String systemID) throws SAXException, IOException
resolveEntity
in interface EntityResolver
resolveEntity
in class DefaultHandler2
name
- the entity namesystemID
- The system identifier, a URI reference of the external resource being referenced, or null if no system identifier was suppliedSAXException
IOException
public LSInput resolveResource(String type, String namespaceURI, String publicID, String systemID, String baseURI)
resolveResource
in interface LSResourceResolver
type
- The type of the resource being resolved. For XML resources applications must use the value "http://www.w3.org/TR/REC-xml"
. For
XML Schema, applications must use the value "http://www.w3.org/2001/XMLSchema"
.namespaceURI
- The namespace of the resource being resolvedpublicID
- The public identifier of the external entity being referenced, or null if no public identifier was suppliedsystemID
- The system identifier, a URI reference of the external resource being referenced, or null if no system identifier was suppliedbaseURI
- The absolute base URI of the resource being parsed, or null if there is no base URI.