org.qedeq.kernel.xml.handler.common
Class SaxDefaultHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.qedeq.kernel.xml.handler.common.SimpleHandler
          extended by org.qedeq.kernel.xml.handler.common.SaxDefaultHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class SaxDefaultHandler
extends SimpleHandler

Default SAX handler. Delegates SAX events to a AbstractSimpleHandler which could also delegate events to other AbstractSimpleHandlers.

Before anything is parsed the method setExceptionList(SourceFileExceptionList) must be called.

Author:
Michael Meyling

Constructor Summary
SaxDefaultHandler(ModuleService plugin)
          Constructor.
 
Method Summary
 void changeHandler(AbstractSimpleHandler newHandler, java.lang.String elementName, SimpleAttributes attributes)
          Change current handler to new one.
 void characters(char[] ch, int start, int length)
           
 org.xml.sax.SAXParseException createSAXParseException(java.lang.Exception e)
          Wraps exception in new SAXParseException including parsing position information.
 org.xml.sax.SAXParseException createSAXParseException(java.lang.String message)
          Creates new SAXParseException including parsing position information.
 SourceArea createSourceArea()
          Create current source area.
 void endDocument()
           
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
           
 int getLevel()
          Get current level.
 ModuleService getPlugin()
          Get plugin we work for.
 void setBasisDocumentHandler(AbstractSimpleHandler handler)
          Set basis handler for documents.
 void setExceptionList(SourceFileExceptionList errorList)
          Set parse exception list.
 void startDocument()
           
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes amap)
           
 
Methods inherited from class org.qedeq.kernel.xml.handler.common.SimpleHandler
getEncoding, getLocator, getUrl, setDocumentLocator, setUrl
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SaxDefaultHandler

public SaxDefaultHandler(ModuleService plugin)
Constructor.

Parameters:
plugin - The plugin we work for.
Method Detail

setExceptionList

public void setExceptionList(SourceFileExceptionList errorList)
Set parse exception list. This list collects occurring parsing errors.

Parameters:
errorList - Collect errors here.

setBasisDocumentHandler

public final void setBasisDocumentHandler(AbstractSimpleHandler handler)
Set basis handler for documents.

Parameters:
handler - Basis handler for documents. This handler might also pass control to another handler via the AbstractSimpleHandler.changeHandler(AbstractSimpleHandler, String, SimpleAttributes) method.

startDocument

public final void startDocument()
                         throws org.xml.sax.SAXException
Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endDocument

public final void endDocument()
                       throws org.xml.sax.SAXException
Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

startElement

public final void startElement(java.lang.String uri,
                               java.lang.String localName,
                               java.lang.String qName,
                               org.xml.sax.Attributes amap)
                        throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endElement

public final void endElement(java.lang.String uri,
                             java.lang.String localName,
                             java.lang.String qName)
                      throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

characters

public final void characters(char[] ch,
                             int start,
                             int length)
Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler

changeHandler

public final void changeHandler(AbstractSimpleHandler newHandler,
                                java.lang.String elementName,
                                SimpleAttributes attributes)
                         throws XmlSyntaxException
Change current handler to new one. The new handler is initialized by calling AbstractSimpleHandler.init(). The new handler also gets a AbstractSimpleHandler.startElement(String, SimpleAttributes) event. The current handler is stacked. After the new handler gets the appropriate endElement event, the control is switched back to the old handler.

The switch back is also done, if the tag level gets back to the same number. That means if for example the new handler starts with the <banana> tag, the old handler is restored when the misspelled </bnana> tag occurs:

 <banana>
      <one />
      <two >
          <one />
          <one />
      </two >
 </bnana>
 

Parameters:
newHandler - This handler gets the new events.
elementName - Element name.
attributes - Element attributes.
Throws:
XmlSyntaxException - New Handler detected a semantic problem.

getLevel

public final int getLevel()
Get current level.

Returns:
Current level.

createSAXParseException

public final org.xml.sax.SAXParseException createSAXParseException(java.lang.Exception e)
Wraps exception in new SAXParseException including parsing position information.

Parameters:
e - Exception to wrap.
Returns:
Exception to throw.

createSAXParseException

public final org.xml.sax.SAXParseException createSAXParseException(java.lang.String message)
Creates new SAXParseException including parsing position information.

Parameters:
message - Problem description.
Returns:
Exception to throw.

createSourceArea

public final SourceArea createSourceArea()
Create current source area.

Returns:
Current area.

getPlugin

public ModuleService getPlugin()
Get plugin we work for.

Returns:
Plugin.


Copyright © 2014. All Rights Reserved.