org.inria.ns.reflex.xml.sax
Class SAXFilter

java.lang.Object
  extended by org.xml.sax.helpers.XMLFilterImpl
      extended by org.inria.ns.reflex.xml.sax.SAXFilter
All Implemented Interfaces:
Localizable, ContentHandler, DTDHandler, EntityResolver, ErrorHandler, DeclHandler, LexicalHandler, XMLFilter, XMLReader
Direct Known Subclasses:
SAXBuffer, SAXFragmentParser, SAXMultihandler, SAXSafeDocument, StandaloneProducer.Impl, XPathFilter

public class SAXFilter
extends XMLFilterImpl
implements LexicalHandler, DeclHandler, ContentHandler, DTDHandler, Localizable

An XMLFilter invokable with system IDs that support many URI schemes.

Support lexical handler and DTD-declaration handler.

This filter takes care of multiple invokations of startDocument() and endDocument().

This filter is suitable for nested documents : no more that one startDocument() and its well-balanced endDocument() events will be fired.

This filter can be used with explicit invokation of startDocument(), then parse(...), and to finish endDocument().

***

This class is used to fix buggy XSLT processors :

***

Author:
Philippe Poulard

Constructor Summary
SAXFilter(ParserConfiguration parserConfiguration)
          Create a filter.
 
Method Summary
 void attributeDecl(String eName, String aName, String type, String valueDefault, String value)
          Fire a SAX event.
 void comment(char[] ch, int start, int length)
          Fire a SAX event.
 void elementDecl(String name, String model)
          Fire a SAX event.
 void endCDATA()
          Fire a SAX event.
 void endDocument()
          Fires an end document event if well balanced with the startDocument().
 void endDTD()
          Fire a SAX event.
 void endEntity(String name)
          Fire a SAX event.
 void externalEntityDecl(String name, String publicId, String systemId)
          Fire a SAX event.
 DeclHandler getDeclHandler()
          Return the DTD-declaration handler registered as a property to this filter.
 LexicalHandler getLexicalHandler()
          Return the lexical handler registered as a property to this filter.
 XFile getLocation()
          Get the base location of this filter, used to resolve relative system IDs.
 Object getProperty(String name)
           
 void internalEntityDecl(String name, String value)
          Fire a SAX event.
 boolean isLocalizable()
          Indicates if a base location has been set on this filter ; when true, getLocation() won't throw an exception.
 void parse(String systemId)
          Parse an XML document from a system identifier (URI).
 void setDeclHandler(DeclHandler handler)
          Set the decl handler.
 void setLexicalHandler(LexicalHandler handler)
          Set the lexical handler.
 void setLocation(XFile location)
          Set the base location of this filter, used to resolve relative system IDs.
 void setProperty(String name, Object value)
           
 void startCDATA()
          Fire a SAX event.
 void startDocument()
          Fires a start document event.
 void startDTD(String name, String publicId, String systemId)
          Fire a SAX event.
 void startEntity(String name)
          Fire a SAX event.
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
characters, endElement, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, ignorableWhitespace, notationDecl, parse, processingInstruction, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, skippedEntity, startElement, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
characters, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startElement, startPrefixMapping
 
Methods inherited from interface org.xml.sax.DTDHandler
notationDecl, unparsedEntityDecl
 

Constructor Detail

SAXFilter

public SAXFilter(ParserConfiguration parserConfiguration)
Create a filter.

Parameters:
configuration - The non-null configuration expected for the parser, if one is needed.
Method Detail

parse

public void parse(String systemId)
           throws SAXException,
                  IOException
Parse an XML document from a system identifier (URI).

Specified by:
parse in interface XMLReader
Overrides:
parse in class XMLFilterImpl
Parameters:
systemId - The system identifier (URI) of the document to parse. The scheme supported are those supported by the I/O module.
Throws:
SAXException
IOException
See Also:
XMLFilterImpl.parse(java.lang.String)

startDocument

public void startDocument()
                   throws SAXException
Fires a start document event. If this method is called several times, only the first invokation will fire the event. Other events are tracked, so that only the balanced end event will be fired.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class XMLFilterImpl
Throws:
SAXException - The client may throw an exception during processing.
See Also:
ContentHandler.startDocument()

endDocument

public void endDocument()
                 throws SAXException
Fires an end document event if well balanced with the startDocument().

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class XMLFilterImpl
Throws:
SAXException - The client may throw an exception during processing.
See Also:
ContentHandler.endDocument()

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws SAXException
Fire a SAX event.

Specified by:
startDTD in interface LexicalHandler
Throws:
SAXException
See Also:
LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)

endDTD

public void endDTD()
            throws SAXException
Fire a SAX event.

Specified by:
endDTD in interface LexicalHandler
Throws:
SAXException
See Also:
LexicalHandler.endDTD()

startEntity

public void startEntity(String name)
                 throws SAXException
Fire a SAX event.

Specified by:
startEntity in interface LexicalHandler
Throws:
SAXException
See Also:
LexicalHandler.startEntity(java.lang.String)

endEntity

public void endEntity(String name)
               throws SAXException
Fire a SAX event.

Specified by:
endEntity in interface LexicalHandler
Throws:
SAXException
See Also:
LexicalHandler.endEntity(java.lang.String)

startCDATA

public void startCDATA()
                throws SAXException
Fire a SAX event.

Specified by:
startCDATA in interface LexicalHandler
Throws:
SAXException
See Also:
LexicalHandler.startCDATA()

endCDATA

public void endCDATA()
              throws SAXException
Fire a SAX event.

Specified by:
endCDATA in interface LexicalHandler
Throws:
SAXException
See Also:
LexicalHandler.endCDATA()

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Fire a SAX event.

Specified by:
comment in interface LexicalHandler
Throws:
SAXException
See Also:
LexicalHandler.comment(char[], int, int)

getLexicalHandler

public LexicalHandler getLexicalHandler()
Return the lexical handler registered as a property to this filter.

Returns:
The lexical handler, or null.

setLexicalHandler

public void setLexicalHandler(LexicalHandler handler)
Set the lexical handler.

Parameters:
handler - The new lexical handler.
Throws:
NullPointerException - If the handler is null.

elementDecl

public void elementDecl(String name,
                        String model)
                 throws SAXException
Fire a SAX event.

Specified by:
elementDecl in interface DeclHandler
Throws:
SAXException
See Also:
DeclHandler.elementDecl(java.lang.String, java.lang.String)

attributeDecl

public void attributeDecl(String eName,
                          String aName,
                          String type,
                          String valueDefault,
                          String value)
                   throws SAXException
Fire a SAX event.

Specified by:
attributeDecl in interface DeclHandler
Throws:
SAXException
See Also:
DeclHandler.attributeDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

internalEntityDecl

public void internalEntityDecl(String name,
                               String value)
                        throws SAXException
Fire a SAX event.

Specified by:
internalEntityDecl in interface DeclHandler
Throws:
SAXException
See Also:
DeclHandler.internalEntityDecl(java.lang.String, java.lang.String)

externalEntityDecl

public void externalEntityDecl(String name,
                               String publicId,
                               String systemId)
                        throws SAXException
Fire a SAX event.

Specified by:
externalEntityDecl in interface DeclHandler
Throws:
SAXException
See Also:
DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)

getDeclHandler

public DeclHandler getDeclHandler()
Return the DTD-declaration handler registered as a property to this filter.

Returns:
The DTD-declaration handler, or null.

setDeclHandler

public void setDeclHandler(DeclHandler handler)
Set the decl handler.

Parameters:
handler - The new decl handler.
Throws:
NullPointerException - If the handler is null.

getProperty

public Object getProperty(String name)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException
Specified by:
getProperty in interface XMLReader
Overrides:
getProperty in class XMLFilterImpl
Throws:
SAXNotRecognizedException
SAXNotSupportedException
See Also:
XMLFilterImpl.getProperty(java.lang.String)

setProperty

public void setProperty(String name,
                        Object value)
                 throws SAXNotRecognizedException,
                        SAXNotSupportedException
Specified by:
setProperty in interface XMLReader
Overrides:
setProperty in class XMLFilterImpl
Throws:
SAXNotRecognizedException
SAXNotSupportedException
See Also:
XMLFilterImpl.setProperty(java.lang.String, java.lang.Object)

getLocation

public XFile getLocation()
                  throws UnlocalizableException
Get the base location of this filter, used to resolve relative system IDs.

Specified by:
getLocation in interface Localizable
Returns:
The base location.
Throws:
UnlocalizableException - If no base location has been set before.
See Also:
Localizable.getLocation(), isLocalizable()

setLocation

public void setLocation(XFile location)
                 throws UnlocalizableException
Set the base location of this filter, used to resolve relative system IDs.

Specified by:
setLocation in interface Localizable
Parameters:
location - The base location.
Throws:
UnlocalizableException - If a base URI is irrelevant for this instance.
See Also:
Localizable.setLocation(org.inria.ns.reflex.modules.io.XFile)

isLocalizable

public boolean isLocalizable()
Indicates if a base location has been set on this filter ; when true, getLocation() won't throw an exception.

Specified by:
isLocalizable in interface Localizable
Returns:
true if a base location has been set, false otherwise.
See Also:
Localizable.isLocalizable()