org.inria.ns.reflex.xml.sax
Class SAXSafeParser
java.lang.Object
org.xml.sax.helpers.XMLFilterImpl
org.inria.ns.reflex.xml.sax.SAXFilter
org.inria.ns.reflex.xml.sax.SAXSafeDocument
org.inria.ns.reflex.xml.sax.SAXSafeParser
- All Implemented Interfaces:
- Localizable, ContentHandler, DTDHandler, EntityResolver, ErrorHandler, DeclHandler, LexicalHandler, XMLFilter, XMLReader
- Direct Known Subclasses:
- CatalogReader, SAXAdaptableParser
public abstract class SAXSafeParser
- extends SAXSafeDocument
A SAXSafeParser parses a source as
if it was an XML source, and if it fails,
delegates the job to another fallback reader.
This class is convenient for example when
a data source may be supplied in XML as well
as in raw plain text : if the source is real
XML, it will be parsed as XMLReader does, but
if the source is not XML, the fallback process
should fire SAX events to the client handler while
reading the raw text. In both cases, the
client handler will receive SAX event as if the
source were XML.
The first attempt of parsing should fail as soon as
possible after reading the first characters, otherwise
the source should be valid (or have real XML errors).
Once the first element is encountered without errors,
the alternate parse will no longer be called.
- Author:
- Philippe Poulard
- See Also:
XMLReader
Methods inherited from class org.inria.ns.reflex.xml.sax.SAXFilter |
attributeDecl, comment, elementDecl, endCDATA, endDocument, endEntity, externalEntityDecl, getDeclHandler, getLexicalHandler, getLocation, getProperty, internalEntityDecl, isLocalizable, parse, setDeclHandler, setLexicalHandler, setLocation, setProperty, startCDATA, startDocument, startEntity |
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl |
endElement, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning |
SAXSafeParser
public SAXSafeParser(ParserConfiguration parserConfiguration)
- Create a SAXSafeParser.
- Parameters:
configuration
- The non-null
configuration
expected for the parser, if one is needed.
parse
public void parse(InputSource input)
throws SAXException,
IOException
- Parse a document.
- Specified by:
parse
in interface XMLReader
- Overrides:
parse
in class XMLFilterImpl
- Parameters:
input
- The document to parse.
- Throws:
SAXException
IOException
- See Also:
XMLFilterImpl.parse(org.xml.sax.InputSource)
startElement
public void startElement(String uri,
String localName,
String name,
Attributes atts)
throws SAXException
- Stop buffering the input the first time this event is
called. In any case, the event is processed as usually.
- Specified by:
startElement
in interface ContentHandler
- Overrides:
startElement
in class SAXSafeDocument
- Parameters:
uri
- The URI.localName
- The local name.name
- The qualified name.atts
- The attributes.
- Throws:
SAXException
- See Also:
XMLFilterImpl.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
alternateParse
public abstract void alternateParse(InputSource input)
throws SAXException,
IOException
- Parse a document with an alternate method.
This method is invoked by
parse(InputSource)
when a classical XML parsing fails.
This method should also fire SAX events to
the client handler.
- Parameters:
input
- The document to parse ; the wrapped reader
has been previously reset.
- Throws:
SAXException
IOException