com.lightdev.app.shtm
Class SHTMLWriter

java.lang.Object
  extended by com.lightdev.app.shtm.SHTMLWriter

public class SHTMLWriter
extends java.lang.Object

A writer for documents of application SimplyHTML.

SHTMLWriter implements an own approach to clean writing of HTML produced by application SimplyHTML. To keep it simple, SHTMLWriter only writes HTML and CSS content application SimplyHTML 'understands'. Documents not produced by SimplyHTML might or might not work with this writer.

With stage 9 the mode property has been added as a workaround for bug id 4765271 (see http://developer.java.sun.com/developer/bugParade/bugs/4765271.html). By passing MODE_HTML, font-size attribute contents are written as is, with MODE_JAVA, values of attribute font-size are adjusted to (wrong) sizes expected in Java.

With release 2 of stage 9 this writer is used only when the user selects not to write HTML 3.2. The standard HTMLWriter with a fix for writing font sizes inside content is used when HTML 3.2 is to be written.


Nested Class Summary
 class SHTMLWriter.PropertiesMissingException
          inner class for signaling that properties were missing for proper execution.
 
Field Summary
static char cssAttributeSeparator
           
static char cssAttributeTerminator
           
static char htmlAttributeSeparator
           
static char htmlAttributeStartEnd
           
static char htmlAttributeTerminator
           
static char htmlEndTagIndicator
           
static char htmlTagEnd
           
static char htmlTagStart
           
static int MODE_HTML
          indicator for writing 'normal' HTML
static int MODE_JAVA
          indicator for writing 'adjusted Java HTML'
 
Constructor Summary
SHTMLWriter(java.io.Writer w)
          construct an uninitialized SHTMLWriter
SHTMLWriter(java.io.Writer w, javax.swing.text.html.HTMLDocument doc)
          construct a new SHTMLWriter to generate HTML for a given document
SHTMLWriter(java.io.Writer w, javax.swing.text.html.HTMLDocument doc, int mode)
          construct a new SHTMLWriter to generate HTML for a given document
SHTMLWriter(java.io.Writer w, javax.swing.text.html.HTMLDocument doc, int pos, int len)
          construct a new SHTMLWriter to generate HTML for a given part of a document
SHTMLWriter(java.io.Writer w, javax.swing.text.html.HTMLDocument doc, int pos, int len, int mode)
          construct a new SHTMLWriter to generate HTML for a given part of a document
 
Method Summary
 void endTag(java.lang.String name)
          write out an end tag for a given tag name
 void setDocument(SHTMLDocument doc)
          set the document to write from
 void setWriteSegment(int pos, int len)
          specify the text segment of the document to be written
 void startTag(java.lang.String name, javax.swing.text.AttributeSet a)
          write out a start tag for a given tag name including tag attributes (if any)
 void write()
          invoke HTML creation for the document or part of document given in the constructor of this SHTMLWriter
 void write(javax.swing.text.Element e)
          invoke HTML creation for a given element and all its children
 void write(javax.swing.text.Element start, javax.swing.text.Element end)
          write elements and their children starting at a given element until a given element is reached.
 void writeChildElements(javax.swing.text.Element elem)
          invoke HTML creation for all children of a given element.
 void writeElementsUntil(javax.swing.text.Element e, javax.swing.text.Element end)
          write an element and all its children.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_HTML

public static final int MODE_HTML
indicator for writing 'normal' HTML

This is built in as a workaround for bug id 4765271 (see http://developer.java.sun.com/developer/bugParade/bugs/4765271.html)

See Also:
Constant Field Values

MODE_JAVA

public static final int MODE_JAVA
indicator for writing 'adjusted Java HTML'

This is built in as a workaround for bug id 4765271 (see http://developer.java.sun.com/developer/bugParade/bugs/4765271.html)

See Also:
Constant Field Values

htmlTagStart

public static final char htmlTagStart
See Also:
Constant Field Values

htmlTagEnd

public static final char htmlTagEnd
See Also:
Constant Field Values

htmlEndTagIndicator

public static final char htmlEndTagIndicator
See Also:
Constant Field Values

htmlAttributeSeparator

public static final char htmlAttributeSeparator
See Also:
Constant Field Values

htmlAttributeTerminator

public static final char htmlAttributeTerminator
See Also:
Constant Field Values

htmlAttributeStartEnd

public static final char htmlAttributeStartEnd
See Also:
Constant Field Values

cssAttributeTerminator

public static final char cssAttributeTerminator
See Also:
Constant Field Values

cssAttributeSeparator

public static final char cssAttributeSeparator
See Also:
Constant Field Values
Constructor Detail

SHTMLWriter

public SHTMLWriter(java.io.Writer w,
                   javax.swing.text.html.HTMLDocument doc,
                   int pos,
                   int len,
                   int mode)
construct a new SHTMLWriter to generate HTML for a given part of a document

Parameters:
w - the writer for HTML output
doc - the document to generate HTML from
pos - the start position of the part of the document to generate HTML for
len - the length of the part of the document to generate HTML for
mode - the writing mode, one of MODE_HTML and MODE_JAVA

SHTMLWriter

public SHTMLWriter(java.io.Writer w,
                   javax.swing.text.html.HTMLDocument doc,
                   int pos,
                   int len)
construct a new SHTMLWriter to generate HTML for a given part of a document

Parameters:
w - the writer for HTML output
doc - the document to generate HTML from
pos - the start position of the part of the document to generate HTML for
len - the length of the part of the document to generate HTML for

SHTMLWriter

public SHTMLWriter(java.io.Writer w,
                   javax.swing.text.html.HTMLDocument doc,
                   int mode)
construct a new SHTMLWriter to generate HTML for a given document

Parameters:
w - the writer for HTML output
doc - the document to generate HTML from
mode - the writing mode, one of MODE_HTML and MODE_JAVA

SHTMLWriter

public SHTMLWriter(java.io.Writer w,
                   javax.swing.text.html.HTMLDocument doc)
construct a new SHTMLWriter to generate HTML for a given document

Parameters:
w - the writer for HTML output
doc - the document to generate HTML from

SHTMLWriter

public SHTMLWriter(java.io.Writer w)
construct an uninitialized SHTMLWriter

This can be used for snythesizing HTML instead of reading it from the element structure of a document.

If a SHTMLWriter was constructed with this constructor which shall be used for writing a document, the document and writeSegment properties of the SHTMLWriter need to be set before calling its write() methods.

Parameters:
w - the writer to write to
Method Detail

setDocument

public void setDocument(SHTMLDocument doc)
set the document to write from

Parameters:
doc - the document to write from

setWriteSegment

public void setWriteSegment(int pos,
                            int len)
specify the text segment of the document to be written

Parameters:
pos - the start position of the text segment
len - the length of the text segment

write

public void write()
           throws java.io.IOException,
                  javax.swing.text.BadLocationException,
                  SHTMLWriter.PropertiesMissingException
invoke HTML creation for the document or part of document given in the constructor of this SHTMLWriter

Throws:
java.io.IOException - on any i/o error
javax.swing.text.BadLocationException - if text retrieval via doc.getText is passed an invalid location within the document
SHTMLWriter.PropertiesMissingException - if the document is not set prior to calling this method

write

public void write(javax.swing.text.Element e)
           throws java.io.IOException,
                  javax.swing.text.BadLocationException
invoke HTML creation for a given element and all its children

This iterates through the element structure below the given element by calling itself recursively for each branch element found.

Parameters:
e - the element to generate HTML for
Throws:
java.io.IOException - on any i/o error
javax.swing.text.BadLocationException - if text retrieval via doc.getText is passed an invalid location within the document

writeElementsUntil

public void writeElementsUntil(javax.swing.text.Element e,
                               javax.swing.text.Element end)
                        throws java.io.IOException,
                               javax.swing.text.BadLocationException
write an element and all its children. If a given element is reached, writing stops with this element. If the end element is a leaf, it is written as the last element, otherwise it is not written.

Parameters:
e - the element to write including its children (if any)
end - the last leaf element to write or the branch element to stop writing at (whatever applies)
Throws:
java.io.IOException
javax.swing.text.BadLocationException

write

public void write(javax.swing.text.Element start,
                  javax.swing.text.Element end)
           throws java.io.IOException,
                  javax.swing.text.BadLocationException
write elements and their children starting at a given element until a given element is reached. The end element is written as the last element, if it is a leaf element.

Parameters:
start - the element to start writing with
end - the last element to write
Throws:
java.io.IOException
javax.swing.text.BadLocationException

writeChildElements

public void writeChildElements(javax.swing.text.Element elem)
                        throws java.io.IOException,
                               javax.swing.text.BadLocationException,
                               SHTMLWriter.PropertiesMissingException
invoke HTML creation for all children of a given element.

Parameters:
elem - the element which children are to be written as HTML
Throws:
java.io.IOException
javax.swing.text.BadLocationException
SHTMLWriter.PropertiesMissingException

startTag

public void startTag(java.lang.String name,
                     javax.swing.text.AttributeSet a)
              throws java.io.IOException
write out a start tag for a given tag name including tag attributes (if any)

Parameters:
name - the name of the tag to generate
a - the set of attributes to generate in tag or null if none
Throws:
java.io.IOException - on any i/o error

endTag

public void endTag(java.lang.String name)
            throws java.io.IOException
write out an end tag for a given tag name

Parameters:
name - the name of the tag to generate an end tag for
Throws:
java.io.IOException