net.charlesames.utility.html
Class HtmlBuilder

java.lang.Object
  extended by net.charlesames.utility.html.HtmlBuilder
Direct Known Subclasses:
BarGraphBuilder, ContinuousGraphBuilder, DiscreteGraphBuilder, IndentPanelBuilder, ProgressBarBuilder, TimeGraphBuilder

public class HtmlBuilder
extends java.lang.Object

HTML text-building class

Author:
Charles Ames

Nested Class Summary
static class HtmlBuilder.Tags
           
 
Field Summary
static java.lang.String FILE_EXTENSION
          Extension for files containing HTML-formatted text.
 
Constructor Summary
HtmlBuilder()
          Constructor for HtmlBuilder instances
 
Method Summary
 void addTableCell(java.lang.String text, java.lang.String attributes)
          Add an HTML table cell.
 void append(java.lang.String text)
          Appends unformatted text to the buffer.
 void appendLineBreak()
          Append a line break to the HTML buffer.
 void beginBlockQuote(java.lang.String attributes)
          Begin centered text.
 void beginBody()
          Begin an HTML body block.
 void beginCenter(java.lang.String attributes)
          Begin centered text.
 void beginDiv(java.lang.String attributes)
          Begin an HTML division.
 void beginHead()
          Begin an HTML header block.
 void beginHtml()
          Begin an HTML text block.
 void beginListItem(java.lang.String attributes)
          Begin an HTML list item.
 void beginOrderedList(java.lang.String attributes)
          Begin an HTML ordered list.
 void beginParagraph(java.lang.String attributes)
          Begin an HTML paragraph.
 void beginSpan(java.lang.String attributes)
          Begin an HTML span.
 void beginStyle()
          Begin an HTML style block.
 void beginStyleRule(java.lang.String selector)
          Begin an HTML style rule.
 void beginTable(java.lang.String attributes)
          Begin an HTML table.
 void beginTableBody(java.lang.String attributes)
          Begin an HTML table body block.
 void beginTableCell(java.lang.String attributes)
          Begin an HTML table cell
 void beginTableHeader(java.lang.String attributes)
          Begin an HTML table head block.
 void beginTableHeaderCell(java.lang.String attributes)
          Begin an HTML table header cell
 void beginTableRow(java.lang.String attributes)
          Begin an HTML table row.
 void beginTag(java.lang.String tag, java.lang.String attributes)
          Begins a nested HTML text block with the indicated tag and attributes.
 void beginUnorderedList(java.lang.String attributes)
          Begin an HTML unordered list.
static java.lang.String buildAttribute(java.lang.String name, java.lang.String value)
          Build an HTML attribute assignment
 java.lang.String buildColorDeclaration(HtmlColor value)
           
static java.lang.String buildLink(java.lang.String name, java.lang.String href)
          Build an HTML link
 java.lang.String buildStyleDeclaration(java.lang.String name, java.lang.String value)
          Build an HTML style declaration.
 void endBlockQuote()
          Conclude centered text.
 void endBody()
          Conclude an HTML body block.
 void endCenter()
          Conclude centered text.
 void endDiv()
          Conclude an HTML division.
 void endHead()
          Conclude an HTML header block.
 void endHtml()
          Conclude an HTML text block.
 void endListItem()
          Conclude an HTML list item.
 void endOrderedList()
          Conclude an HTML ordered list.
 void endParagraph()
          Conclude an HTML paragraph.
 void endSpan()
          Conclude an HTML span.
 void endStyle()
          Conclude an HTML style block.
 void endStyleRule(java.lang.String selector)
          Conclude an HTML style rule.
 void endTable()
          Conclude an HTML table.
 void endTableBody()
          Conclude an HTML table body block.
 void endTableCell()
          Conclude an HTML table cell.
 void endTableHeader()
          Conclude an HTML table head block.
 void endTableHeaderCell()
          Conclude an HTML table cell.
 void endTableRow()
          Conclude an HTML table row.
 void endTag(java.lang.String tag)
          Concludes a nested HTML text block with the indicated tag.
 void endUnorderedList()
          Conclude an HTML unordered list.
 void newline()
          Append a newline to the HTML buffer.
 void popTag(java.lang.String tag)
          Pops a tag from the stack.
 void pushTag(java.lang.String tag)
          Pushes a tag onto the stack.
 void reset()
          Empties the HTML buffer and clears the tag stack.
 void save(java.io.File file)
          Save the text to the indicated File.
 void tab()
          Append a tab to the HTML buffer.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILE_EXTENSION

public static final java.lang.String FILE_EXTENSION
Extension for files containing HTML-formatted text.

See Also:
Constant Field Values
Constructor Detail

HtmlBuilder

public HtmlBuilder()
Constructor for HtmlBuilder instances

Method Detail

reset

public void reset()
Empties the HTML buffer and clears the tag stack.


append

public void append(java.lang.String text)
Appends unformatted text to the buffer.

Parameters:
text -

pushTag

public void pushTag(java.lang.String tag)
Pushes a tag onto the stack.

Parameters:
tag - The element tag.

popTag

public void popTag(java.lang.String tag)
Pops a tag from the stack.

Parameters:
tag - The expected tag value.

beginTag

public void beginTag(java.lang.String tag,
                     java.lang.String attributes)
Begins a nested HTML text block with the indicated tag and attributes.

Parameters:
tag - The tag text.
attributes - The block attributes

endTag

public void endTag(java.lang.String tag)
Concludes a nested HTML text block with the indicated tag.

Parameters:
tag - The tag text.

buildAttribute

public static java.lang.String buildAttribute(java.lang.String name,
                                              java.lang.String value)
Build an HTML attribute assignment

Parameters:
name - The attribute name.
value - The text value to be assigned to the attribute.
Returns:
An HTML text fragment setting the attribute to the value.

buildLink

public static java.lang.String buildLink(java.lang.String name,
                                         java.lang.String href)
Build an HTML link

Parameters:
name - The text displayed within the link.
href - An HTML HREF value.
Returns:
An HTML anchor block surrounding the name text, with the href attribute set as indicated.

tab

public void tab()
Append a tab to the HTML buffer.


newline

public void newline()
Append a newline to the HTML buffer.


appendLineBreak

public void appendLineBreak()
Append a line break to the HTML buffer.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

beginHtml

public void beginHtml()
Begin an HTML text block.


endHtml

public void endHtml()
Conclude an HTML text block.


beginHead

public void beginHead()
Begin an HTML header block.


endHead

public void endHead()
Conclude an HTML header block.


beginStyle

public void beginStyle()
Begin an HTML style block.


endStyle

public void endStyle()
Conclude an HTML style block.


beginStyleRule

public void beginStyleRule(java.lang.String selector)
Begin an HTML style rule.

Parameters:
selector -

endStyleRule

public void endStyleRule(java.lang.String selector)
Conclude an HTML style rule.

Parameters:
selector -

buildStyleDeclaration

public java.lang.String buildStyleDeclaration(java.lang.String name,
                                              java.lang.String value)
Build an HTML style declaration.

Parameters:
name - The style attribute name
value - The value
Returns:
An HTML text fragment setting the style to the value.

buildColorDeclaration

public java.lang.String buildColorDeclaration(HtmlColor value)
Parameters:
value - An HTML color
Returns:
An HTML text fragment setting "color" to the indicated value.

beginBody

public void beginBody()
Begin an HTML body block.


endBody

public void endBody()
Conclude an HTML body block.


beginUnorderedList

public void beginUnorderedList(java.lang.String attributes)
Begin an HTML unordered list.

Parameters:
attributes - One or more attributes

endUnorderedList

public void endUnorderedList()
Conclude an HTML unordered list.


beginOrderedList

public void beginOrderedList(java.lang.String attributes)
Begin an HTML ordered list.

Parameters:
attributes - One or more attributes

endOrderedList

public void endOrderedList()
Conclude an HTML ordered list.


beginListItem

public void beginListItem(java.lang.String attributes)
Begin an HTML list item.

Parameters:
attributes - One or more attributes

endListItem

public void endListItem()
Conclude an HTML list item.


beginDiv

public void beginDiv(java.lang.String attributes)
Begin an HTML division.

Parameters:
attributes - One or more attributes

endDiv

public void endDiv()
Conclude an HTML division.


beginCenter

public void beginCenter(java.lang.String attributes)
Begin centered text.

Parameters:
attributes - One or more attributes

endCenter

public void endCenter()
Conclude centered text.


beginBlockQuote

public void beginBlockQuote(java.lang.String attributes)
Begin centered text.

Parameters:
attributes - One or more attributes

endBlockQuote

public void endBlockQuote()
Conclude centered text.


beginSpan

public void beginSpan(java.lang.String attributes)
Begin an HTML span.

Parameters:
attributes - One or more attributes

endSpan

public void endSpan()
Conclude an HTML span.


beginTable

public void beginTable(java.lang.String attributes)
Begin an HTML table.

Parameters:
attributes - One or more attributes

endTable

public void endTable()
Conclude an HTML table.


beginTableHeader

public void beginTableHeader(java.lang.String attributes)
Begin an HTML table head block.

Parameters:
attributes - One or more attributes

endTableHeader

public void endTableHeader()
Conclude an HTML table head block.


beginTableBody

public void beginTableBody(java.lang.String attributes)
Begin an HTML table body block.

Parameters:
attributes - One or more attributes

endTableBody

public void endTableBody()
Conclude an HTML table body block.


beginTableRow

public void beginTableRow(java.lang.String attributes)
Begin an HTML table row.

Parameters:
attributes - One or more attributes

endTableRow

public void endTableRow()
Conclude an HTML table row.


beginTableHeaderCell

public void beginTableHeaderCell(java.lang.String attributes)
Begin an HTML table header cell

Parameters:
attributes - One or more attributes

endTableHeaderCell

public void endTableHeaderCell()
Conclude an HTML table cell.


beginTableCell

public void beginTableCell(java.lang.String attributes)
Begin an HTML table cell

Parameters:
attributes - One or more attributes

endTableCell

public void endTableCell()
Conclude an HTML table cell.


addTableCell

public void addTableCell(java.lang.String text,
                         java.lang.String attributes)
Add an HTML table cell.

Parameters:
text - The text content that will be displayed within the table cell.
attributes - One or more attributes

beginParagraph

public void beginParagraph(java.lang.String attributes)
Begin an HTML paragraph.

Parameters:
attributes - One or more attributes

endParagraph

public void endParagraph()
Conclude an HTML paragraph.


save

public void save(java.io.File file)
Save the text to the indicated File.

Parameters:
file - The indicated File.