net.sourceforge.saxadapter
Class SAXAdapter

java.lang.Object
  |
  +--org.xml.sax.helpers.XMLFilterImpl
        |
        +--net.sourceforge.saxadapter.SAXAdapter
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader

public class SAXAdapter
extends org.xml.sax.helpers.XMLFilterImpl
implements org.xml.sax.ext.DeclHandler, org.xml.sax.ext.LexicalHandler

This utility allows handlers to register and then parses an XML input source using the SAX2 spec and calls the appropriate callbacks on registered handlers.

Author:
Mark Priest

Inner Class Summary
(package private)  class SAXAdapter.NamespaceContextImpl
          This class wraps the NamespaceSupport object
 
Constructor Summary
SAXAdapter()
          Default constructor which creates an XMLReader based on the SAX2 bootstrap mechanism
SAXAdapter(java.lang.String argReaderClass)
          Creates an XMLReader with the supplied XMLReader implementation class
SAXAdapter(org.xml.sax.XMLReader argReader)
          Sets the specified XMLReader as the parent of this XMLFilter
 
Method Summary
 void attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value)
           
 void characters(char[] ch, int start, int length)
           
 void comment(char[] ch, int start, int length)
           
 void elementDecl(java.lang.String name, java.lang.String model)
           
 void endCDATA()
           
 void endDocument()
           
 void endDTD()
           
 void endElement(java.lang.String argNamespaceURI, java.lang.String argLocalName, java.lang.String argQName)
           
 void endEntity(java.lang.String name)
           
 void endPrefixMapping(java.lang.String prefix)
           
 void error(org.xml.sax.SAXParseException argExc)
           
 void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
           
 void fatalError(org.xml.sax.SAXParseException argExc)
           
 org.xml.sax.ContentHandler getContentHandler()
           
 org.xml.sax.Locator getDocumentLocator()
          This method allows client code to obtain the Locator for parsing events that may indicate application errors but not XML syntax errors
 org.xml.sax.ErrorHandler getErrorHandler()
           
 int getNamespaceMode()
          Returns the XML namespace awareness mode set on the parent parser
 java.lang.Object getProperty(java.lang.String argPropURI)
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void internalEntityDecl(java.lang.String name, java.lang.String value)
           
 void parse(org.xml.sax.InputSource argInputSource)
          Parse the XML doc in the InputSource
 java.util.Map parse(org.xml.sax.InputSource argInputSource, java.util.Map argContextMap)
          Parse the XML doc in the InputStream and use the passed in Map
 void parse(java.lang.String systemId)
           
 java.util.Map parse(java.lang.String systemId, java.util.Map argMap)
           
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 void registerDefaultHandler(SAXTagHandler argHandler)
          Registers a handler that is invoked whenever no other handler is found that can handle a given tag
 void registerDefaultHandler(java.lang.String argNamespace, SAXTagHandler argHandler)
          Registers a handler that is invoked whenever no other handler is found that can handle a given tag in the specified namespace
 void registerHandler(java.lang.String argQName, SAXTagHandler argHandler)
          Registers a handler using the qualified name (used when parser is not namespace aware)
 void registerHandler(java.lang.String argTagNamespace, java.lang.String argLocalTagName, SAXTagHandler argHandler)
          Registers a handler based on the tag namespace and unqualified tag name
 void reset()
          This method resets all internal state including registered handlers of all types.
 void setContentHandler(org.xml.sax.ContentHandler argHandler)
           
 void setDocumentLocator(org.xml.sax.Locator locator)
           
 void setErrorHandler(org.xml.sax.ErrorHandler argErrorHandler)
          Registers a custom error handler to deal with parsing errors.
 void setMap(java.util.Map argMap)
          This method allows the context map to be set if it cannot be set through parse (i.e.
 void setMaxBufferSize(int argMaxBufferSize)
          This method allows the maximum buffer size to be set for this instance.
 void setNamespaceMode(int argMode)
          Determines the settings from the two SAX namespace flags This is a convenience method and the same effect can be achieved by setting the features flags through setFeature().
(package private)  void setParentState(org.xml.sax.XMLReader argParent)
          Sets this object as the implementor of DeclHandler and/or LexicalHandler if those handlers have been previously set
 void setProperty(java.lang.String argPropURI, java.lang.Object argValue)
          Sets a property on the parser (for setting vendor specific properties)
 void setValidating(boolean argBool)
          Controls whether the SAX parser will validate the XML document Convenience method to set the SAX validating feature
 void skippedEntity(java.lang.String name)
           
 void startCDATA()
           
 void startDocument()
           
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
           
 void startElement(java.lang.String argNamespaceURI, java.lang.String argLocalName, java.lang.String argQName, org.xml.sax.Attributes argAtts)
           
 void startEntity(java.lang.String name)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 void warning(org.xml.sax.SAXParseException argExc)
           
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
getDTDHandler, getEntityResolver, getFeature, getParent, notationDecl, resolveEntity, setDTDHandler, setEntityResolver, setFeature, setParent, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAXAdapter

public SAXAdapter()
           throws org.xml.sax.SAXException
Default constructor which creates an XMLReader based on the SAX2 bootstrap mechanism
Throws:
org.xml.sax.SAXException -  

SAXAdapter

public SAXAdapter(java.lang.String argReaderClass)
           throws org.xml.sax.SAXException
Creates an XMLReader with the supplied XMLReader implementation class
Parameters:
argReaderClass - the fully-qualified classname of the XMLReader impl
Throws:
org.xml.sax.SAXException -  

SAXAdapter

public SAXAdapter(org.xml.sax.XMLReader argReader)
           throws org.xml.sax.SAXException
Sets the specified XMLReader as the parent of this XMLFilter
Parameters:
argReader - the XMLReader that will be the parent of the adapter
Throws:
org.xml.sax.SAXException -  
Method Detail

registerHandler

public void registerHandler(java.lang.String argTagNamespace,
                            java.lang.String argLocalTagName,
                            SAXTagHandler argHandler)
Registers a handler based on the tag namespace and unqualified tag name
Parameters:
argTagNamespace - tag namespace URI
argLocalTagName - unqualified tag name
argHandler - the handler to register

registerHandler

public void registerHandler(java.lang.String argQName,
                            SAXTagHandler argHandler)
Registers a handler using the qualified name (used when parser is not namespace aware)
Parameters:
argQName - qualified name
argHandler - handler to be registered

registerDefaultHandler

public void registerDefaultHandler(SAXTagHandler argHandler)
Registers a handler that is invoked whenever no other handler is found that can handle a given tag
Parameters:
argHandler - default handler to be registered

registerDefaultHandler

public void registerDefaultHandler(java.lang.String argNamespace,
                                   SAXTagHandler argHandler)
Registers a handler that is invoked whenever no other handler is found that can handle a given tag in the specified namespace
Parameters:
argNamespace - the namespace defined for this default handler
argHandler - default handler to be registered

setValidating

public void setValidating(boolean argBool)
                   throws org.xml.sax.SAXException
Controls whether the SAX parser will validate the XML document Convenience method to set the SAX validating feature
Parameters:
argBool - the value to set
Throws:
org.xml.sax.SAXException -  

setNamespaceMode

public void setNamespaceMode(int argMode)
                      throws org.xml.sax.SAXException
Determines the settings from the two SAX namespace flags This is a convenience method and the same effect can be achieved by setting the features flags through setFeature(). This cannot be changed during a parse.
Parameters:
argMode - the namespace awareness mode to be used
Throws:
org.xml.sax.SAXException -  

getNamespaceMode

public int getNamespaceMode()
                     throws org.xml.sax.SAXException
Returns the XML namespace awareness mode set on the parent parser
Returns:
the namespace mode as a coded integer
Throws:
org.xml.sax.SAXException -  

reset

public void reset()
This method resets all internal state including registered handlers of all types. This does NOT affect registrations of handlers done with the XMLReader API such as DTDHandler, etc since they cannot be "reset" once set

getDocumentLocator

public org.xml.sax.Locator getDocumentLocator()
This method allows client code to obtain the Locator for parsing events that may indicate application errors but not XML syntax errors
Returns:
the locator associated with this XMLReader

setMap

public void setMap(java.util.Map argMap)
This method allows the context map to be set if it cannot be set through parse (i.e. if this has a parent XMLReader
Parameters:
argMap - the context Map to be used during parsing

setMaxBufferSize

public void setMaxBufferSize(int argMaxBufferSize)
This method allows the maximum buffer size to be set for this instance. At the end of each parse the capacity of the internal StringBuffer is compared to the maximum value. If the capacity exceeds the maximum value then the buffer is reallocated and the previous buffer is freed for garbage collection. This ensures that a very large buffer does not use up excess memory. The default maximum value is 1024 characters.
Parameters:
argMaxBufferSize - the maximum size of the internal StringBuffer to be maintained between document parse events

parse

public java.util.Map parse(org.xml.sax.InputSource argInputSource,
                           java.util.Map argContextMap)
                    throws org.xml.sax.SAXException,
                           java.io.IOException
Parse the XML doc in the InputStream and use the passed in Map
Parameters:
argInputSource - input source to be parsed
argContextMap - the map to be passed to the handlers
Returns:
the Map used to hold application state
Throws:
java.io.IOException -  
org.xml.sax.SAXException -  

parse

public java.util.Map parse(java.lang.String systemId,
                           java.util.Map argMap)
                    throws java.io.IOException,
                           org.xml.sax.SAXException

parse

public void parse(org.xml.sax.InputSource argInputSource)
           throws org.xml.sax.SAXException,
                  java.io.IOException
Parse the XML doc in the InputSource
Overrides:
parse in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
argInputSource - input source to be parsed
Throws:
java.io.IOException -  
org.xml.sax.SAXException -  

parse

public void parse(java.lang.String systemId)
           throws java.io.IOException,
                  org.xml.sax.SAXException
Overrides:
parse in class org.xml.sax.helpers.XMLFilterImpl

setErrorHandler

public void setErrorHandler(org.xml.sax.ErrorHandler argErrorHandler)
Registers a custom error handler to deal with parsing errors. By default, errors and fatal errors are thrown during parse and warnings are ignored
Overrides:
setErrorHandler in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
argErrorHandler - the error handler to be registered

getErrorHandler

public org.xml.sax.ErrorHandler getErrorHandler()
Overrides:
getErrorHandler in class org.xml.sax.helpers.XMLFilterImpl

setContentHandler

public void setContentHandler(org.xml.sax.ContentHandler argHandler)
Overrides:
setContentHandler in class org.xml.sax.helpers.XMLFilterImpl

getContentHandler

public org.xml.sax.ContentHandler getContentHandler()
Overrides:
getContentHandler in class org.xml.sax.helpers.XMLFilterImpl

setProperty

public void setProperty(java.lang.String argPropURI,
                        java.lang.Object argValue)
                 throws org.xml.sax.SAXNotRecognizedException,
                        org.xml.sax.SAXNotSupportedException
Sets a property on the parser (for setting vendor specific properties)
Overrides:
setProperty in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
argPropURI - URI of the property (see Megginson list)
argValue - Property value
Throws:
org.xml.sax.SAXNotRecognizedException -  
org.xml.sax.SAXNotSupportedException -  

getProperty

public java.lang.Object getProperty(java.lang.String argPropURI)
                             throws org.xml.sax.SAXNotRecognizedException,
                                    org.xml.sax.SAXNotSupportedException
Overrides:
getProperty in class org.xml.sax.helpers.XMLFilterImpl

startElement

public void startElement(java.lang.String argNamespaceURI,
                         java.lang.String argLocalName,
                         java.lang.String argQName,
                         org.xml.sax.Attributes argAtts)
                  throws org.xml.sax.SAXException
Overrides:
startElement in class org.xml.sax.helpers.XMLFilterImpl

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Overrides:
characters in class org.xml.sax.helpers.XMLFilterImpl

endElement

public void endElement(java.lang.String argNamespaceURI,
                       java.lang.String argLocalName,
                       java.lang.String argQName)
                throws org.xml.sax.SAXException
Overrides:
endElement in class org.xml.sax.helpers.XMLFilterImpl

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Overrides:
startPrefixMapping in class org.xml.sax.helpers.XMLFilterImpl

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
Overrides:
endPrefixMapping in class org.xml.sax.helpers.XMLFilterImpl

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Overrides:
ignorableWhitespace in class org.xml.sax.helpers.XMLFilterImpl

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Overrides:
processingInstruction in class org.xml.sax.helpers.XMLFilterImpl

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Overrides:
setDocumentLocator in class org.xml.sax.helpers.XMLFilterImpl

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Overrides:
skippedEntity in class org.xml.sax.helpers.XMLFilterImpl

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Overrides:
startDocument in class org.xml.sax.helpers.XMLFilterImpl

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Overrides:
endDocument in class org.xml.sax.helpers.XMLFilterImpl

error

public void error(org.xml.sax.SAXParseException argExc)
           throws org.xml.sax.SAXException
Overrides:
error in class org.xml.sax.helpers.XMLFilterImpl

fatalError

public void fatalError(org.xml.sax.SAXParseException argExc)
                throws org.xml.sax.SAXException
Overrides:
fatalError in class org.xml.sax.helpers.XMLFilterImpl

warning

public void warning(org.xml.sax.SAXParseException argExc)
             throws org.xml.sax.SAXException
Overrides:
warning in class org.xml.sax.helpers.XMLFilterImpl

attributeDecl

public void attributeDecl(java.lang.String eName,
                          java.lang.String aName,
                          java.lang.String type,
                          java.lang.String valueDefault,
                          java.lang.String value)
                   throws org.xml.sax.SAXException
Specified by:
attributeDecl in interface org.xml.sax.ext.DeclHandler

elementDecl

public void elementDecl(java.lang.String name,
                        java.lang.String model)
                 throws org.xml.sax.SAXException
Specified by:
elementDecl in interface org.xml.sax.ext.DeclHandler

externalEntityDecl

public void externalEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId)
                        throws org.xml.sax.SAXException
Specified by:
externalEntityDecl in interface org.xml.sax.ext.DeclHandler

internalEntityDecl

public void internalEntityDecl(java.lang.String name,
                               java.lang.String value)
                        throws org.xml.sax.SAXException
Specified by:
internalEntityDecl in interface org.xml.sax.ext.DeclHandler

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws org.xml.sax.SAXException
Specified by:
comment in interface org.xml.sax.ext.LexicalHandler

startCDATA

public void startCDATA()
                throws org.xml.sax.SAXException
Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler

endCDATA

public void endCDATA()
              throws org.xml.sax.SAXException
Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.String systemId)
              throws org.xml.sax.SAXException
Specified by:
startDTD in interface org.xml.sax.ext.LexicalHandler

endDTD

public void endDTD()
            throws org.xml.sax.SAXException
Specified by:
endDTD in interface org.xml.sax.ext.LexicalHandler

startEntity

public void startEntity(java.lang.String name)
                 throws org.xml.sax.SAXException
Specified by:
startEntity in interface org.xml.sax.ext.LexicalHandler

endEntity

public void endEntity(java.lang.String name)
               throws org.xml.sax.SAXException
Specified by:
endEntity in interface org.xml.sax.ext.LexicalHandler

setParentState

void setParentState(org.xml.sax.XMLReader argParent)
              throws org.xml.sax.SAXNotRecognizedException,
                     org.xml.sax.SAXNotSupportedException
Sets this object as the implementor of DeclHandler and/or LexicalHandler if those handlers have been previously set
Parameters:
argParent - the parent XMLReader with which the handlers may be registered
Throws:
org.xml.sax.SAXNotRecognizedException -  
org.xml.sax.SAXNotSupportedException -