edu.northwestern.at.wordhoard.tools
Class Context

java.lang.Object
  extended by edu.northwestern.at.wordhoard.tools.Context
All Implemented Interfaces:
java.lang.Cloneable

public class Context
extends java.lang.Object
implements java.lang.Cloneable

Parsing context for building works.

All of the variables which can vary during the parsing of a work are gathered together into a parsing context, which is passed as a parameter to all of the parsing methods as we recursively descend the DOM tree for the work. Each parsing method clones the context to make any necessary context changes during the processing of its element in the DOM tree.


Constructor Summary
Context()
           
 
Method Summary
 void addSpeech(Speech speech)
          Adds a speech to the speech list.
 void addWord(Word word)
          Adds a word to the word list.
 void appendBlankLine()
          Appends a blank line.
 void appendText(java.lang.String str)
          Appends untagged text to the current line.
 Word appendWord(java.lang.String str)
          Appends a word.
 java.lang.Object clone()
          Clones the context.
 void endLine()
          Ends the current text line.
 TextWrapper finalizeText()
          Finalizes the text.
 void flushRun()
          Flushes a style run.
 boolean getFirstLineOfStanza()
          Gets the first line of stanza attribute.
 boolean getInTaggedLine()
          Gets the tagged line attribute.
 boolean getLemmaTagging()
          Gets the lemma tagging attribute.
 Line getLine()
          Gets the current line object.
 java.util.ArrayList getLineList()
          Gets the line list.
 int getPartLevel()
          Gets the work part level.
 Prosodic getProsodic()
          Gets the prosodic attribute.
 Speech getSpeech()
          Gets the current speech.
 java.util.ArrayList getSpeechList()
          Gets the speech list.
 java.lang.String getStanzaNumber()
          Gets the stanza number.
 boolean getStanzaNumbering()
          Gets the stanza numbering attribute.
 int getStyle()
          Gets the style.
 java.util.ArrayList getWordList()
          Gets the word list.
 WorkPart getWorkPart()
          Gets the work part.
 void indent(int indentation)
          Indents or undents subsequent lines.
 void setBold(boolean bold)
          Sets the bold style.
 void setCharset(byte charset)
          Sets the character set.
 void setFirstLineOfStanza(boolean firstLineOfStanza)
          Sets the first line of stanza attribute.
 void setInTaggedLine(boolean inTaggedLine)
          Sets the tagged line attribute.
 void setItalic(boolean italic)
          Sets the italic style.
 void setJustification(byte justification)
          Sets the line justification.
 void setLemmaTagging(boolean lemmaTagging)
          Sets the lemma tagging attribute.
 void setLine(Line line)
          Sets the line object.
 void setLineLocation()
          Sets the line location.
 void setNormal()
          Sets the normal style.
 void setProsodic(org.w3c.dom.Element el)
          Sets the prosodic attribute.
 void setProsodic(Prosodic prosodic)
          Sets the prosodic attribute.
 void setSize(byte size)
          Sets the font size.
 void setSpeech(Speech speech)
          Sets the current speech.
 void setStanzaNumber(java.lang.String stanzaNumber)
          Sets the stanza number.
 void setStanzaNumbering(boolean stanzaNumbering)
          Sets the stanza numbering attribute.
 void setStyle(int style)
          Sets the style.
 void setStyle(int mask, boolean set)
          Sets a style.
 void setWorkPart(WorkPart workPart)
          Sets the work part.
 void startLine()
          Starts a new text line.
 void startNewText(boolean lineNumbers)
          Starts new text.
 void startWorkPart(WorkPart workPart, org.w3c.dom.Element headerEl)
          Starts a new work part.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Context

public Context()
Method Detail

clone

public java.lang.Object clone()
Clones the context.

Overrides:
clone in class java.lang.Object

setCharset

public void setCharset(byte charset)
Sets the character set.

Parameters:
charset - Character set.

getWorkPart

public WorkPart getWorkPart()
Gets the work part.

Returns:
The work part.

setWorkPart

public void setWorkPart(WorkPart workPart)
Sets the work part.

Parameters:
workPart - The work part.

startWorkPart

public void startWorkPart(WorkPart workPart,
                          org.w3c.dom.Element headerEl)
Starts a new work part.

Parameters:
workPart - The work part.
headerEl - Header element for part.

getPartLevel

public int getPartLevel()
Gets the work part level.

Returns:
The current work part level.

startNewText

public void startNewText(boolean lineNumbers)
Starts new text.

Parameters:
lineNumbers - True if the text has line numbers.

finalizeText

public TextWrapper finalizeText()
Finalizes the text.

Returns:
A TextWrapper object containing the finalized text.

getWordList

public java.util.ArrayList getWordList()
Gets the word list.

Returns:
The word list.

addWord

public void addWord(Word word)
Adds a word to the word list.

Parameters:
word - Word.

getLineList

public java.util.ArrayList getLineList()
Gets the line list.

Returns:
The line list.

getSpeechList

public java.util.ArrayList getSpeechList()
Gets the speech list.

Returns:
The speech list.

addSpeech

public void addSpeech(Speech speech)
Adds a speech to the speech list.

Parameters:
speech - Speech.

getSpeech

public Speech getSpeech()
Gets the current speech.

Returns:
Current speech, or null if none.

setSpeech

public void setSpeech(Speech speech)
Sets the current speech.

Parameters:
speech - Current speech, or null if none.

getStanzaNumbering

public boolean getStanzaNumbering()
Gets the stanza numbering attribute.

Returns:
True if the work part uses stanza numbering.

setStanzaNumbering

public void setStanzaNumbering(boolean stanzaNumbering)
Sets the stanza numbering attribute.

Parameters:
stanzaNumbering - True if the work part uses stanza numbering.

getLemmaTagging

public boolean getLemmaTagging()
Gets the lemma tagging attribute.

Returns:
True if the work part uses lemma tagging.

setLemmaTagging

public void setLemmaTagging(boolean lemmaTagging)
Sets the lemma tagging attribute.

Parameters:
lemmaTagging - True if the work part uses lemma tagging.

getStanzaNumber

public java.lang.String getStanzaNumber()
Gets the stanza number.

Returns:
The stanza number as a string, or null if none.

setStanzaNumber

public void setStanzaNumber(java.lang.String stanzaNumber)
Sets the stanza number.

Parameters:
stanzaNumber - The stanza number as a string, or null if none.

getFirstLineOfStanza

public boolean getFirstLineOfStanza()
Gets the first line of stanza attribute.

Returns:
True if first line of stanza.

setFirstLineOfStanza

public void setFirstLineOfStanza(boolean firstLineOfStanza)
Sets the first line of stanza attribute.

Parameters:
firstLineOfStanza - True if first line of stanza.

getInTaggedLine

public boolean getInTaggedLine()
Gets the tagged line attribute.

Returns:
True if in tagged line.

setInTaggedLine

public void setInTaggedLine(boolean inTaggedLine)
Sets the tagged line attribute.

Parameters:
inTaggedLine - True if in tagged line.

indent

public void indent(int indentation)
Indents or undents subsequent lines.

Parameters:
indentation - The additional indentation for subsequent lines. A negative value undents.

getLine

public Line getLine()
Gets the current line object.

Returns:
The current line object.

setJustification

public void setJustification(byte justification)
Sets the line justification.

Parameters:
justification - Line justification (TextLine.LEFT, TextLine.CENTER, or TextLine.RIGHT).

setLine

public void setLine(Line line)
Sets the line object.

The line object is also added to the line list if it is not null.

Parameters:
line - Line object, or null if none.

startLine

public void startLine()
Starts a new text line.


endLine

public void endLine()
Ends the current text line.


appendWord

public Word appendWord(java.lang.String str)
Appends a word.

The returned word object has the spelling, work part, line, and location attributes set. This class also takes care of setting the puncBefore and puncAfter attributes. All other attributes must be set by the caller.

Parameters:
str - The word.
Returns:
A new word object for the word.

appendText

public void appendText(java.lang.String str)
Appends untagged text to the current line.

Parameters:
str - String of untagged text.

flushRun

public void flushRun()
Flushes a style run.


setSize

public void setSize(byte size)
Sets the font size.

Parameters:
size - Font size.

getStyle

public int getStyle()
Gets the style.

Returns:
The style.

setStyle

public void setStyle(int style)
Sets the style.

Parameters:
style - The style.

setStyle

public void setStyle(int mask,
                     boolean set)
Sets a style.

Parameters:
mask - Style mask.
set - True to set the style, false to clear the style.

setNormal

public void setNormal()
Sets the normal style.


setBold

public void setBold(boolean bold)
Sets the bold style.

Parameters:
bold - The bold style.

setItalic

public void setItalic(boolean italic)
Sets the italic style.

Parameters:
italic - The italic style.

appendBlankLine

public void appendBlankLine()
Appends a blank line.


setLineLocation

public void setLineLocation()
Sets the line location.


getProsodic

public Prosodic getProsodic()
Gets the prosodic attribute.

Returns:
The prosodic attribute.

setProsodic

public void setProsodic(org.w3c.dom.Element el)
Sets the prosodic attribute.

Parameters:
el - Element with "prosodic" attribute.

setProsodic

public void setProsodic(Prosodic prosodic)
Sets the prosodic attribute.

Parameters:
prosodic - Prosodic attribute.