## gate.email
Class EmailDocumentHandler

    java.lang.Object
      |
      +--gate.email.EmailDocumentHandler

public class EmailDocumentHandler
extends Object

This class implements the behaviour of the Email reader It takes the Gate Document representing a list with e-mails and creates Gate annotations on it.

Field Summary
`private AnnotationSet` `basicAS`
`private String` `content`
`private Collection` `day`
`private static boolean` `DEBUG` Debug flag
`private long` `documentSize`
`private Map` `element2StringMap`
`private int` `emails`
`private static int` `EMAILS_RATE`
`private String` `fieldName`
`private Document` `gateDocument`
`private Map` `markupElementsMap`
`private Collection` `month`
`protected List` `myStatusListeners`
`private String` `tmpDocContent`
`private Collection` `zone`

Constructor Summary
`EmailDocumentHandler()` Constructor used in tests mostly
`EmailDocumentHandler(Document aGateDocument, Map aMarkupElementsMap, Map anElement2StringMap)` Constructor initialises some private fields

Method Summary
`void` `addStatusListener(StatusListener listener)` This methos is called when a listener is registered with this class
`void` `annotateMessages()` Reads the Gate Document line by line and does the folowing things: Each line is analized in order to detect where an e-mail starts.
`private boolean` `canCreateAnnotation(long start, long end, long gateDocumentSize)` This method verifies if an Annotation can be created.
`private boolean` `containsSemicolon(String aString)` This method checks if a String contains a semicolon char
`private boolean` `containsWhiteSpaces(String aString)` This method checks if a String contains white spaces.
`private void` `createAnnotation(String anAnnotationName, long anAnnotationStart, long anAnnotationEnd, FeatureMap aFeatureMap)` This method creates a gate annotation given its name, start, end and feature map.
`private int` `detectNLSize()` This method detects if the text file which contains e-mail messages is under MSDOS or UNIX format.
`protected void` `fireStatusChangedEvent(String text)` This methos is called whenever we need to inform the listener about an event.
`private String` `getFieldName()` This method returns the value of the member fieldName.
`private boolean` `hasAMeaning(String aToken)` This method tests a token if is Day, Month, Zone, Time, Year
`private boolean` `isTime(String aToken)` Tests a token if is in time format HH:MM:SS
`private boolean` `lineBeginsMessage(String aTextLine)` Tests if the line begins an e-mail message
`private boolean` `lineBeginsWithField(String aTextLine)` Tests if the line begins with a field from the e-mail header If the answer is true then it also sets the member fieldName with the value of this e-mail header field.
`void` `removeStatusListener(StatusListener listener)` This methos is called when a listener is removed
`private void` `setUp()` Initialises the collections with data used by method lineBeginsMessage()
`private void` `testContainsSemicolon()` Test containsSemicolon
`private void` `testContainsWhiteSpaces()` Test containsWhiteSpaces
`private void` `testHasAMeaning()` Test hasAMeaning
`private void` `testIsTime()` Test isTime
`private void` `testLineBeginsMessage()` Test lineBeginsMessage
`private void` `testLineBeginsWithField()` Test lineBeginsWithField
`void` `testSelf()` Test final

Methods inherited from class java.lang.Object
`<clinit>, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait`

Field Detail

### DEBUG

    private static final boolean DEBUG

  Debug flag

### content

    private String content

### documentSize

    private long documentSize

### EMAILS_RATE

    private static final int EMAILS_RATE

### tmpDocContent

    private String tmpDocContent

### gateDocument

    private Document gateDocument

### basicAS

    private AnnotationSet basicAS

### markupElementsMap

    private Map markupElementsMap

### element2StringMap

    private Map element2StringMap

### myStatusListeners

    protected List myStatusListeners

### emails

    private int emails

### fieldName

    private String fieldName

### day

    private Collection day

### month

    private Collection month

### zone

    private Collection zone

Constructor Detail

### EmailDocumentHandler

    public EmailDocumentHandler()

  Constructor used in tests mostly

### EmailDocumentHandler

    public EmailDocumentHandler(Document aGateDocument,
                                Map aMarkupElementsMap,
                                Map anElement2StringMap)

  Constructor initialises some private fields

Method Detail

### annotateMessages

    public void annotateMessages()
                          throws IOException,
                                 InvalidOffsetException

  Reads the Gate Document line by line and does the folowing things:
  - Each line is analized in order to detect where an e-mail starts.
  - If the line belongs to an e-mail header then creates the annotation if the markupElementsMap allows that.
  - Lines belonging to the e-mail body are placed under a Gate annotation called messageBody.

### detectNLSize

    private int detectNLSize()

  This method detects if the text file which contains e-mail messages is under MSDOS or UNIX format. Under MSDOS the size of NL is 2 (\n \r) and under UNIX (\n) the size is 1
  Returns:
    the size of the NL (1,2 or 0 = if no \n is found)

### createAnnotation

    private void createAnnotation(String anAnnotationName,
                                  long anAnnotationStart,
                                  long anAnnotationEnd,
                                  FeatureMap aFeatureMap)
                           throws InvalidOffsetException

  This method creates a gate annotation given its name, start, end and feature map.

### canCreateAnnotation

    private boolean canCreateAnnotation(long start,
                                        long end,
                                        long gateDocumentSize)

  This method verifies if an Annotation can be created.

### lineBeginsMessage

    private boolean lineBeginsMessage(String aTextLine)

  Tests if the line begins an e-mail message
  Parameters:
    `aTextLine` - a line from the file containing the e-mail messages
  Returns:
    true if the line begins an e-mail message

### lineBeginsWithField

    private boolean lineBeginsWithField(String aTextLine)

  Tests if the line begins with a field from the e-mail header If the answer is true then it also sets the member fieldName with the value of this e-mail header field.
  Parameters:
    `aTextLine` - a line from the file containing the e-mail text
  Returns:
    true if the line begins with a field from the e-mail header

### containsWhiteSpaces

    private boolean containsWhiteSpaces(String aString)

  This method checks if a String contains white spaces.

### containsSemicolon

    private boolean containsSemicolon(String aString)

  This method checks if a String contains a semicolon char

### hasAMeaning

    private boolean hasAMeaning(String aToken)

  This method tests a token if is Day, Month, Zone, Time, Year

### isTime

    private boolean isTime(String aToken)

  Tests a token if is in time format HH:MM:SS

### setUp

    private void setUp()

  Initialises the collections with data used by method lineBeginsMessage()

### getFieldName

    private String getFieldName()

  This method returns the value of the member fieldName. fieldName is set by the method lineBeginsWithField(String line). Each time the the line begins with a field name, that fiels will be stored in this member.

### 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.

### testContainsSemicolon

    private void testContainsSemicolon()

  Test containsSemicolon

### testContainsWhiteSpaces

    private void testContainsWhiteSpaces()

  Test containsWhiteSpaces

### testHasAMeaning

    private void testHasAMeaning()

  Test hasAMeaning

### testIsTime

    private void testIsTime()

  Test isTime

### testLineBeginsMessage

    private void testLineBeginsMessage()

  Test lineBeginsMessage

### testLineBeginsWithField

    private void testLineBeginsWithField()

  Test lineBeginsWithField

### testSelf

    public void testSelf()

  Test final