gate.xml
Class GateFormatXmlDocumentHandler

java.lang.Object
  |
  +--org.xml.sax.HandlerBase
        |
        +--gate.xml.GateFormatXmlDocumentHandler
All Implemented Interfaces:
org.xml.sax.DocumentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class GateFormatXmlDocumentHandler
extends org.xml.sax.HandlerBase

Implements the behaviour of the XML reader. This is the reader for Gate Xml documents saved with DocumentImplementation.toXml() method.


Field Summary
private  SimpleErrorHandler _seh
          This object indicates what to do when the parser encounts an error
private  AnnotationSet basicAS
          An annotation set used for creating annotation reffering the doc
private  List colector
          We need a colection to retain all the CustomObjects that will be transformed into annotation over the gate document...
private  AnnotationObject currentAnnot
           
private  AnnotationSet currentAnnotationSet
           
private  Stack currentElementStack
           
private  FeatureMap currentFeatureMap
           
private  String currentFeatureName
           
private  String currentFeatureValue
           
private static boolean DEBUG
          Debug flag
private  Document doc
          A gate document
private  int elements
          This reports the the number of elements that have beed processed so far
(package private) static int ELEMENTS_RATE
          This constant indicates when to fire the status listener.
private  Map id2Offset
           
protected  List myStatusListeners
          Listeners for status report
private  StringBuffer tmpDocContent
          The content of the XML document, without any tag
 
Constructor Summary
GateFormatXmlDocumentHandler(Document aDocument)
           
 
Method Summary
 void addStatusListener(StatusListener listener)
          This methos is called when a listener is registered with this class
 void characters(char[] text, int start, int length)
          This method is called when the SAX parser encounts text in the XML doc.
 void comment(String text)
          This method is called when the SAX parser encounts a comment It works only if the XmlDocumentHandler implements a com.sun.parser.LexicalEventListener
 void endCDATA()
          This method is called when the SAX parser encounts the end of a CDATA section.
 void endDocument()
          This method is called when the SAX parser encounts the end of the XML document.
 void endElement(String elemName)
          This method is called when the SAX parser encounts the end of an XML element.
 void endParsedEntity(String name, boolean included)
          This method is called when the SAX parser encounts a parsed entity and informs the application if that entity was parsed or not It's working only if the CustomDocumentHandler implements a com.sun.parser.LexicalEventListener
 void error(org.xml.sax.SAXParseException ex)
          Error method.We deal with this exception inside SimpleErrorHandler class
 void fatalError(org.xml.sax.SAXParseException ex)
          FatalError method.
protected  void fireStatusChangedEvent(String text)
          This methos is called whenever we need to inform the listener about an event.
 void ignorableWhitespace(char[] ch, int start, int length)
          This method is called when the SAX parser encounts white spaces
private  void processAnnotationElement(org.xml.sax.AttributeList atts)
          This method deals with a Annotation element.
private  void processAnnotationSetElement(org.xml.sax.AttributeList atts)
          This method deals with a AnnotationSet element.
private  void processFeatureElement(org.xml.sax.AttributeList atts)
          This method deals with a Features element.
private  void processNodeElement(org.xml.sax.AttributeList atts)
          This method deals with a Node element.
private  void processTextOfNameElement(String text)
          This method deals with a Text belonging to Name element.
private  void processTextOfTextWithNodesElement(String text)
          This method deals with a Text belonging to TextWithNodes element.
private  void processTextOfValueElement(String text)
          This method deals with a Text belonging to Value element.
 void removeStatusListener(StatusListener listener)
          This methos is called when a listener is removed
 void startCDATA()
          This method is called when the SAX parser encounts a start of a CDATA section It works only if the XmlDocumentHandler implements a com.sun.parser.LexicalEventListener
 void startDocument()
          This method is called when the SAX parser encounts the beginning of the XML document.
 void startElement(String elemName, org.xml.sax.AttributeList atts)
          This method is called when the SAX parser encounts the beginning of an XML element.
 void startParsedEntity(String name)
          This method is called when the SAX parser encounts a parsed Entity It works only if the XmlDocumentHandler implements a com.sun.parser.LexicalEventListener
 void warning(org.xml.sax.SAXParseException ex)
          Warning method comment.
 
Methods inherited from class org.xml.sax.HandlerBase
notationDecl, processingInstruction, resolveEntity, setDocumentLocator, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Debug flag

ELEMENTS_RATE

static final int ELEMENTS_RATE
This constant indicates when to fire the status listener. This listener will add an overhead and we don't want a big overhead. It will be callled from ELEMENTS_RATE to ELEMENTS_RATE

_seh

private SimpleErrorHandler _seh
This object indicates what to do when the parser encounts an error

tmpDocContent

private StringBuffer tmpDocContent
The content of the XML document, without any tag

doc

private Document doc
A gate document

basicAS

private AnnotationSet basicAS
An annotation set used for creating annotation reffering the doc

myStatusListeners

protected List myStatusListeners
Listeners for status report

elements

private int elements
This reports the the number of elements that have beed processed so far

colector

private List colector
We need a colection to retain all the CustomObjects that will be transformed into annotation over the gate document... The transformation will take place inside onDocumentEnd() method.

id2Offset

private Map id2Offset

currentElementStack

private Stack currentElementStack

currentAnnot

private AnnotationObject currentAnnot

currentFeatureMap

private FeatureMap currentFeatureMap

currentFeatureName

private String currentFeatureName

currentFeatureValue

private String currentFeatureValue

currentAnnotationSet

private AnnotationSet currentAnnotationSet
Constructor Detail

GateFormatXmlDocumentHandler

public GateFormatXmlDocumentHandler(Document aDocument)
Method Detail

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
This method is called when the SAX parser encounts the beginning of the XML document.
Overrides:
startDocument in class org.xml.sax.HandlerBase

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
This method is called when the SAX parser encounts the end of the XML document. Here we set the content of the gate Document to be the one generated inside this class (tmpDocContent). After that we use the colector to generate all the annotation reffering this new gate document.
Overrides:
endDocument in class org.xml.sax.HandlerBase

startElement

public void startElement(String elemName,
                         org.xml.sax.AttributeList atts)
This method is called when the SAX parser encounts the beginning of an XML element.
Overrides:
startElement in class org.xml.sax.HandlerBase

endElement

public void endElement(String elemName)
                throws org.xml.sax.SAXException
This method is called when the SAX parser encounts the end of an XML element.
Overrides:
endElement in class org.xml.sax.HandlerBase

characters

public void characters(char[] text,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
This method is called when the SAX parser encounts text in the XML doc. Here we calculate the end indices for all the elements present inside the stack and update with the new values.
Overrides:
characters in class org.xml.sax.HandlerBase

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
This method is called when the SAX parser encounts white spaces
Overrides:
ignorableWhitespace in class org.xml.sax.HandlerBase

error

public void error(org.xml.sax.SAXParseException ex)
           throws org.xml.sax.SAXException
Error method.We deal with this exception inside SimpleErrorHandler class
Overrides:
error in class org.xml.sax.HandlerBase

fatalError

public void fatalError(org.xml.sax.SAXParseException ex)
                throws org.xml.sax.SAXException
FatalError method.
Overrides:
fatalError in class org.xml.sax.HandlerBase

warning

public void warning(org.xml.sax.SAXParseException ex)
             throws org.xml.sax.SAXException
Warning method comment.
Overrides:
warning in class org.xml.sax.HandlerBase

processAnnotationSetElement

private void processAnnotationSetElement(org.xml.sax.AttributeList atts)
This method deals with a AnnotationSet element.

processAnnotationElement

private void processAnnotationElement(org.xml.sax.AttributeList atts)
This method deals with a Annotation element.

processFeatureElement

private void processFeatureElement(org.xml.sax.AttributeList atts)
This method deals with a Features element.

processNodeElement

private void processNodeElement(org.xml.sax.AttributeList atts)
This method deals with a Node element.

processTextOfTextWithNodesElement

private void processTextOfTextWithNodesElement(String text)
This method deals with a Text belonging to TextWithNodes element.

processTextOfNameElement

private void processTextOfNameElement(String text)
This method deals with a Text belonging to Name element.

processTextOfValueElement

private void processTextOfValueElement(String text)
This method deals with a Text belonging to Value element.

comment

public void comment(String text)
             throws org.xml.sax.SAXException
This method is called when the SAX parser encounts a comment It works only if the XmlDocumentHandler implements a com.sun.parser.LexicalEventListener

startCDATA

public void startCDATA()
                throws org.xml.sax.SAXException
This method is called when the SAX parser encounts a start of a CDATA section It works only if the XmlDocumentHandler implements a com.sun.parser.LexicalEventListener

endCDATA

public void endCDATA()
              throws org.xml.sax.SAXException
This method is called when the SAX parser encounts the end of a CDATA section. It works only if the XmlDocumentHandler implements a com.sun.parser.LexicalEventListener

startParsedEntity

public void startParsedEntity(String name)
                       throws org.xml.sax.SAXException
This method is called when the SAX parser encounts a parsed Entity It works only if the XmlDocumentHandler implements a com.sun.parser.LexicalEventListener

endParsedEntity

public void endParsedEntity(String name,
                            boolean included)
                     throws org.xml.sax.SAXException
This method is called when the SAX parser encounts a parsed entity and informs the application if that entity was parsed or not It's working only if the CustomDocumentHandler implements a com.sun.parser.LexicalEventListener

addStatusListener

public void addStatusListener(StatusListener listener)
This methos is called when a listener is registered with this class

removeStatusListener

public void removeStatusListener(StatusListener listener)
This methos is called when a listener is removed

fireStatusChangedEvent

protected void fireStatusChangedEvent(String text)
This methos is called whenever we need to inform the listener about an event.