gate.xml
Class GateFormatXmlDocumentHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by gate.xml.GateFormatXmlDocumentHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

Deprecated. GATE format XML documents are now handled by DocumentStaxUtils.

public class GateFormatXmlDocumentHandler
extends DefaultHandler

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


Nested Class Summary
(package private)  class GateFormatXmlDocumentHandler.AnnotationObject
          Deprecated. An inner class modeling the information contained by an annotation.
 
Field Summary
private  SimpleErrorHandler _seh
          Deprecated. This object indicates what to do when the parser encounts an error
private  TreeSet annotationIdSet
          Deprecated. A Set recording every annotation ID read from the XML file.
private  Map classCache
          Deprecated. Instead of creating a new Class object for every Feature object we store them in a map with a String as a key.
private  List colector
          Deprecated. We need a colection to retain all the CustomObjects that will be transformed into annotation over the gate document...
private  StringBuffer contentBuffer
          Deprecated. This is used to capture all data within two tags before calling the actual characters method
private  GateFormatXmlDocumentHandler.AnnotationObject currentAnnot
          Deprecated. This inner objects maps an annotation object.
private  AnnotationSet currentAnnotationSet
          Deprecated. the current annotation set that is being created and filled with annotations
private  Stack currentElementStack
          Deprecated. Holds the current element read.
private  String currentFeatureKeyClassName
          Deprecated. The class name of the key in the current feature
private  String currentFeatureKeyItemClassName
          Deprecated. If the key is a collection then we need to know the class name of the items present in this collection.
private  FeatureMap currentFeatureMap
          Deprecated. A map holding current annotation's features
private  String currentFeatureName
          Deprecated. A key of the current feature
private  String currentFeatureValue
          Deprecated. The value of the current feature
private  String currentFeatureValueClassName
          Deprecated. The class name for the value in the current feature
private  String currentFeatureValueItemClassName
          Deprecated. If the value is a collection then we need to know the class name of the items present in this collection.
private static boolean DEBUG
          Deprecated. Debug flag
private  Document doc
          Deprecated. A gate document
private  int elements
          Deprecated. This reports the the number of elements that have beed processed so far
(package private) static int ELEMENTS_RATE
          Deprecated. This constant indicates when to fire the status listener.
private  int gateXmlFormatType
          Deprecated. In the beginning we don't know the type of GATE XML format that we read.
private  Map id2Offset
          Deprecated. Maps nodes Ids to their offset in the document text.
protected  List myStatusListeners
          Deprecated. Listeners for status report
private static int NEW
          Deprecated. A NEW GATE XML format is the one in which Annotations IDs are present
private static int OLD
          Deprecated. An OLD GATE XML format is the one in which Annotations IDs are not present
private  boolean readCharacterStatus
          Deprecated. This is a variable that shows if characters have been read
private  StringBuffer tmpDocContent
          Deprecated. The content of the XML document, without any tag
private static int UNDEFINED
          Deprecated. This value signifies that the document being read can be either OLD or NEW
 
Constructor Summary
GateFormatXmlDocumentHandler(Document aDocument)
          Deprecated.  
 
Method Summary
 void addStatusListener(StatusListener listener)
          Deprecated. This methos is called when a listener is registered with this class
 void characters(char[] text, int start, int length)
          Deprecated. This method is called when the SAX parser encounts text in the XML doc.
 void charactersAction(char[] text, int start, int length)
          Deprecated. This method is called when all characters between specific tags have been read completely
 void comment(String text)
          Deprecated. This method is called when the SAX parser encounts a comment It works only if the XmlDocumentHandler implements a com.sun.parser.LexicalEventListener
private  Object createFeatKey()
          Deprecated. Creates a feature key using this information: currentFeatureKeyClassName, currentFeatureKeyItemClassName, currentFeatureName.
private  Object createFeatObject(String aFeatClassName, String aFeatItemClassName, String aFeatStringRepresentation)
          Deprecated. This method tries to reconstruct an object given its class name and its string representation.
private  Object createFeatValue()
          Deprecated. Creates a feature value using this information: currentFeatureValueClassName, currentFeatureValueItemClassName, currentFeatureValue.
 void endCDATA()
          Deprecated. This method is called when the SAX parser encounts the end of a CDATA section.
 void endDocument()
          Deprecated. This method is called when the SAX parser encounts the end of the XML document.
 void endElement(String uri, String qName, String elemName)
          Deprecated. This method is called when the SAX parser encounts the end of an XML element.
 void endParsedEntity(String name, boolean included)
          Deprecated. 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(SAXParseException ex)
          Deprecated. Error method.We deal with this exception inside SimpleErrorHandler class
 void fatalError(SAXParseException ex)
          Deprecated. FatalError method.
protected  void fireStatusChangedEvent(String text)
          Deprecated. This methos is called whenever we need to inform the listener about an event.
 void ignorableWhitespace(char[] ch, int start, int length)
          Deprecated. This method is called when the SAX parser encounts white spaces
private  void processAnnotationElement(Attributes atts)
          Deprecated. This method deals with a Annotation element.
private  void processAnnotationSetElement(Attributes atts)
          Deprecated. This method deals with a AnnotationSet element.
private  void processFeatureElement(Attributes atts)
          Deprecated. This method deals with a Features element.
private  void processNameElement(Attributes atts)
          Deprecated. This method deals with the start of a Name element
private  void processNodeElement(Attributes atts)
          Deprecated. This method deals with a Node element.
private  void processTextOfNameElement(String text)
          Deprecated. This method deals with a Text belonging to Name element.
private  void processTextOfTextWithNodesElement(String text)
          Deprecated. This method deals with a Text belonging to TextWithNodes element.
private  void processTextOfValueElement(String text)
          Deprecated. This method deals with a Text belonging to Value element.
private  void processValueElement(Attributes atts)
          Deprecated. This method deals with the start of a Value element
private  String recoverNewLineSequence(String text)
          Deprecated. Restore new line as in the original document if needed
 void removeStatusListener(StatusListener listener)
          Deprecated. This methos is called when a listener is removed
 void startCDATA()
          Deprecated. 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()
          Deprecated. This method is called when the SAX parser encounts the beginning of the XML document.
 void startElement(String uri, String qName, String elemName, Attributes atts)
          Deprecated. This method is called when the SAX parser encounts the beginning of an XML element.
 void startParsedEntity(String name)
          Deprecated. This method is called when the SAX parser encounts a parsed Entity It works only if the XmlDocumentHandler implements a com.sun.parser.LexicalEventListener
private  void testAnnotationIdUnicity(Integer anAnnotId)
          Deprecated. This method tests if the Annotation ID has been used previously (in which case will rase an exception) and also adds the ID being tested to the annotationIdSet
 void warning(SAXParseException ex)
          Deprecated. Warning method comment.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Deprecated. 
Debug flag

See Also:
Constant Field Values

contentBuffer

private StringBuffer contentBuffer
Deprecated. 
This is used to capture all data within two tags before calling the actual characters method


readCharacterStatus

private boolean readCharacterStatus
Deprecated. 
This is a variable that shows if characters have been read


OLD

private static final int OLD
Deprecated. 
An OLD GATE XML format is the one in which Annotations IDs are not present

See Also:
Constant Field Values

NEW

private static final int NEW
Deprecated. 
A NEW GATE XML format is the one in which Annotations IDs are present

See Also:
Constant Field Values

UNDEFINED

private static final int UNDEFINED
Deprecated. 
This value signifies that the document being read can be either OLD or NEW

See Also:
Constant Field Values

gateXmlFormatType

private int gateXmlFormatType
Deprecated. 
In the beginning we don't know the type of GATE XML format that we read. We need to be able to read both types, but not a mixture of them


annotationIdSet

private TreeSet annotationIdSet
Deprecated. 
A Set recording every annotation ID read from the XML file. It is used to check the consistency of the annotations being read. At the end we need the maximum ID in order to set the annotation ID generator on the document. This is why we need a TreeSet.


classCache

private Map classCache
Deprecated. 
Instead of creating a new Class object for every Feature object we store them in a map with a String as a key.


ELEMENTS_RATE

static final int ELEMENTS_RATE
Deprecated. 
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

See Also:
Constant Field Values

_seh

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


tmpDocContent

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


doc

private Document doc
Deprecated. 
A gate document


myStatusListeners

protected List myStatusListeners
Deprecated. 
Listeners for status report


elements

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


colector

private List colector
Deprecated. 
We need a colection to retain all the CustomObjects that will be transformed into annotation over the gate document... At the end of every annotation set read the objects in the colector are transformed into annotations...


id2Offset

private Map id2Offset
Deprecated. 
Maps nodes Ids to their offset in the document text. Those offsets will be used when creating annotations


currentElementStack

private Stack currentElementStack
Deprecated. 
Holds the current element read.


currentAnnot

private GateFormatXmlDocumentHandler.AnnotationObject currentAnnot
Deprecated. 
This inner objects maps an annotation object. When an annotation from the xml document was read this structure is filled out


currentFeatureMap

private FeatureMap currentFeatureMap
Deprecated. 
A map holding current annotation's features


currentFeatureName

private String currentFeatureName
Deprecated. 
A key of the current feature


currentFeatureValue

private String currentFeatureValue
Deprecated. 
The value of the current feature


currentFeatureKeyClassName

private String currentFeatureKeyClassName
Deprecated. 
The class name of the key in the current feature


currentFeatureKeyItemClassName

private String currentFeatureKeyItemClassName
Deprecated. 
If the key is a collection then we need to know the class name of the items present in this collection. The next field holds just that.


currentFeatureValueClassName

private String currentFeatureValueClassName
Deprecated. 
The class name for the value in the current feature


currentFeatureValueItemClassName

private String currentFeatureValueItemClassName
Deprecated. 
If the value is a collection then we need to know the class name of the items present in this collection. The next field holds just that.


currentAnnotationSet

private AnnotationSet currentAnnotationSet
Deprecated. 
the current annotation set that is being created and filled with annotations

Constructor Detail

GateFormatXmlDocumentHandler

public GateFormatXmlDocumentHandler(Document aDocument)
Deprecated. 
Method Detail

startDocument

public void startDocument()
                   throws SAXException
Deprecated. 
This method is called when the SAX parser encounts the beginning of the XML document.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Deprecated. 
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.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler
Throws:
SAXException

startElement

public void startElement(String uri,
                         String qName,
                         String elemName,
                         Attributes atts)
                  throws SAXException
Deprecated. 
This method is called when the SAX parser encounts the beginning of an XML element.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Throws:
SAXException

endElement

public void endElement(String uri,
                       String qName,
                       String elemName)
                throws SAXException
Deprecated. 
This method is called when the SAX parser encounts the end of an XML element.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Throws:
SAXException

characters

public void characters(char[] text,
                       int start,
                       int length)
                throws SAXException
Deprecated. 
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.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Throws:
SAXException

charactersAction

public void charactersAction(char[] text,
                             int start,
                             int length)
                      throws SAXException
Deprecated. 
This method is called when all characters between specific tags have been read completely

Throws:
SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Deprecated. 
This method is called when the SAX parser encounts white spaces

Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class DefaultHandler
Throws:
SAXException

error

public void error(SAXParseException ex)
           throws SAXException
Deprecated. 
Error method.We deal with this exception inside SimpleErrorHandler class

Specified by:
error in interface ErrorHandler
Overrides:
error in class DefaultHandler
Throws:
SAXException

fatalError

public void fatalError(SAXParseException ex)
                throws SAXException
Deprecated. 
FatalError method.

Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class DefaultHandler
Throws:
SAXException

warning

public void warning(SAXParseException ex)
             throws SAXException
Deprecated. 
Warning method comment.

Specified by:
warning in interface ErrorHandler
Overrides:
warning in class DefaultHandler
Throws:
SAXException

processAnnotationSetElement

private void processAnnotationSetElement(Attributes atts)
Deprecated. 
This method deals with a AnnotationSet element.


processNameElement

private void processNameElement(Attributes atts)
Deprecated. 
This method deals with the start of a Name element


processValueElement

private void processValueElement(Attributes atts)
Deprecated. 
This method deals with the start of a Value element


processAnnotationElement

private void processAnnotationElement(Attributes atts)
Deprecated. 
This method deals with a Annotation element.


processFeatureElement

private void processFeatureElement(Attributes atts)
Deprecated. 
This method deals with a Features element.


processNodeElement

private void processNodeElement(Attributes atts)
Deprecated. 
This method deals with a Node element.


processTextOfTextWithNodesElement

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


recoverNewLineSequence

private String recoverNewLineSequence(String text)
Deprecated. 
Restore new line as in the original document if needed


processTextOfNameElement

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

Throws:
GateSaxException

processTextOfValueElement

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

Throws:
GateSaxException

createFeatKey

private Object createFeatKey()
Deprecated. 
Creates a feature key using this information: currentFeatureKeyClassName, currentFeatureKeyItemClassName, currentFeatureName. See createFeatObject() method for more details.


createFeatValue

private Object createFeatValue()
Deprecated. 
Creates a feature value using this information: currentFeatureValueClassName, currentFeatureValueItemClassName, currentFeatureValue. See createFeatObject() method for more details.


createFeatObject

private Object createFeatObject(String aFeatClassName,
                                String aFeatItemClassName,
                                String aFeatStringRepresentation)
Deprecated. 
This method tries to reconstruct an object given its class name and its string representation. If the object is a Collection then the items from its string representation must be separated by a ";". In that case, the currentFeatureValueItemClassName is used to create items belonging to this class.

Parameters:
aFeatClassName - represents the name of the class of the feat object being created. If it is null then the javaLang.String will be used as default.
aFeatItemClassName - is it used only if aFeatClassName is a collection.If it is null then java.lang.String will be used as default;
aFeatStringRepresentation - sais it all
Returns:
an Object created from aFeatClassName and its aFeatStringRepresentation. If not possible, then aFeatStringRepresentation is returned.
Throws:
GateRuntimeException - If it can't create an item, that does not comply with its class definition, to add to the collection.

testAnnotationIdUnicity

private void testAnnotationIdUnicity(Integer anAnnotId)
                              throws GateSaxException
Deprecated. 
This method tests if the Annotation ID has been used previously (in which case will rase an exception) and also adds the ID being tested to the annotationIdSet

Parameters:
anAnnotId - An Integer representing an annotation ID to be tested
Throws:
GateSaxException - if there is already an annotation wit the same ID

comment

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

Throws:
SAXException

startCDATA

public void startCDATA()
                throws SAXException
Deprecated. 
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

Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Deprecated. 
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

Throws:
SAXException

startParsedEntity

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

Throws:
SAXException

endParsedEntity

public void endParsedEntity(String name,
                            boolean included)
                     throws SAXException
Deprecated. 
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

Throws:
SAXException

addStatusListener

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


removeStatusListener

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


fireStatusChangedEvent

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