com.groiss.gui
Class HTMLOutputter

java.lang.Object
  extended by com.groiss.gui.HTMLOutputter

public class HTMLOutputter
extends java.lang.Object


Field Summary
protected static java.lang.String STANDARD_INDENT
          standard value to indent by, if we are indenting, is two spaces
 
Constructor Summary
HTMLOutputter()
          default constructor
 
Method Summary
protected  java.lang.String escapeAttributeEntities(java.lang.String st)
           This will take the pre-defined entities in XML 1.0 and convert their character representation to the appropriate entity reference, suitable for XML attributes.
protected  java.lang.String escapeElementEntities(java.lang.String st)
           This will take the three pre-defined entities in XML 1.0 (used specifically in XML elements) and convert their character representation to the appropriate entity reference, suitable for XML element.
protected  java.lang.String escapeTextEntities(java.lang.String st)
          only escape ampersand
protected  void indent(java.io.Writer out, int level)
           This will print the proper indent characters for the given indent level.
protected  java.io.Writer makeWriter(java.io.OutputStream out)
          Get an OutputStreamWriter, use preferred encoding.
protected  java.io.Writer makeWriter(java.io.OutputStream out, java.lang.String enc)
          Get an OutputStreamWriter, use specified encoding.
protected  void maybePrintln(java.io.Writer out)
           This will print a new line only if the newlines flag was set to true
 void output(org.jdom.Comment comment, java.io.OutputStream out)
           Print out a Comment
 void output(org.jdom.Comment comment, java.io.Writer out)
           Print out a Comment
 void output(org.jdom.Document doc, java.io.OutputStream out)
           This will print the Document to the given output stream.
 void output(org.jdom.Document doc, java.io.Writer out)
           This will print the Document to the given Writer.
 void output(org.jdom.Element element, java.io.OutputStream out)
           Print out an Element, including its Attributes, and its value, and all contained (child) elements etc.
 void output(org.jdom.Element element, java.io.Writer out)
           Print out an Element, including its Attributes, and its value, and all contained (child) elements etc.
 void output(java.lang.String string, java.io.OutputStream out)
           Print out a String.
 void output(java.lang.String string, java.io.Writer out)
           Print out a String.
 void output(org.jdom.Text text, java.io.OutputStream out)
           Print out a Text.
 void output(org.jdom.Text text, java.io.Writer out)
           Print out a Text.
 void outputElementContent(org.jdom.Element element, java.io.OutputStream out)
           This will handle printing out an Element's content only, not including its tag, and attributes.
 void outputElementContent(org.jdom.Element element, java.io.Writer out)
           This will handle printing out an Element's content only, not including its tag, and attributes.
 java.lang.String outputString(org.jdom.Comment comment)
          Return a string representing a comment.
 java.lang.String outputString(org.jdom.Document doc)
          Return a string representing a document.
 java.lang.String outputString(org.jdom.Element element)
          Return a string representing an element.
protected  void printAttributes(java.util.List attributes, org.jdom.Element parent, java.io.Writer out)
           This will handle printing out an Attribute list.
protected  void printComment(org.jdom.Comment comment, java.io.Writer out)
           This will write the comment to the specified writer.
protected  void printElement(org.jdom.Element element, java.io.Writer out, int indentLevel)
           This will handle printing out an Element, its Attributes, and its value.
protected  void printElementContent(org.jdom.Element element, java.io.Writer out, int indentLevel, java.util.List eltContent)
           This will handle printing out an Element's content only, not including its tag, attributes, and namespace info.
 void printRawElement(RawElement element, java.io.Writer out)
           
protected  void printString(java.lang.String s, java.io.Writer out)
          Print a string.
 void setEncoding(java.lang.String encoding)
          Sets the output encoding.
 void setExpandEmptyElements(boolean expandEmptyElements)
           This will set whether empty elements are expanded from <tagName> to <tagName></tagName>.
 void setIndent(boolean doIndent)
          Set the indent on or off.
 void setIndent(java.lang.String indent)
           This will set the indent String to use; this is usually a String of empty spaces.
 void setIndentSize(int indentSize)
           This will set the indent String's size; an indentSize of 4 would result in the indentation being equivalent to the String "    " (four space chars).
 void setLineSeparator(java.lang.String separator)
          This will set the new-line separator.
 void setNewlines(boolean newlines)
           
 void setOmitEncoding(boolean omitEncoding)
           This will set whether the XML declaration (<?
 void setTextNormalize(boolean textNormalize)
           This will set whether the text is output verbatim (false) or with whitespace normalized as per Element.getTextNormalize().
 void setTrimText(boolean textTrim)
          Deprecated. Deprecated in beta7, use setTextNormalize() instead
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STANDARD_INDENT

protected static final java.lang.String STANDARD_INDENT
standard value to indent by, if we are indenting, is two spaces

See Also:
Constant Field Values
Constructor Detail

HTMLOutputter

public HTMLOutputter()
default constructor

Method Detail

setLineSeparator

public void setLineSeparator(java.lang.String separator)

This will set the new-line separator. The default is \r\n. Note that if the "newlines" property is false, this value is irrelevant. To make it output the system default line ending string, call setLineSeparator(System.getProperty("line.separator"))

To output "UNIX-style" documents, call setLineSeparator("\n"). To output "Mac-style" documents, call setLineSeparator("\r"). DOS-style documents use CR-LF ("\r\n"), which is the default.

Note that this only applies to newlines generated by the outputter. If you parse an XML document that contains newlines embedded inside a text node, and you do not call setTextNormalize, then the newlines will be output verbatim, as "\n" which is how parsers normalize them.

Parameters:
separator - String line separator to use.
See Also:
setNewlines(boolean), setTextNormalize(boolean)

setNewlines

public void setNewlines(boolean newlines)
Parameters:
newlines - true indicates new lines should be printed, else new lines are ignored (compacted).
See Also:
setLineSeparator(String)

setEncoding

public void setEncoding(java.lang.String encoding)
Sets the output encoding. The name should be an accepted XML encoding.

Parameters:
encoding - the encoding format. Use XML-style names like "UTF-8" or "ISO-8859-1" or "US-ASCII"

setOmitEncoding

public void setOmitEncoding(boolean omitEncoding)

This will set whether the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) includes the encoding of the document. It is common to omit this in uses such as WML and other wireless device protocols.

Parameters:
omitEncoding - boolean indicating whether or not the XML declaration should indicate the document encoding.

setExpandEmptyElements

public void setExpandEmptyElements(boolean expandEmptyElements)

This will set whether empty elements are expanded from <tagName> to <tagName></tagName>.

Parameters:
expandEmptyElements - boolean indicating whether or not empty elements should be expanded.

setTextNormalize

public void setTextNormalize(boolean textNormalize)

This will set whether the text is output verbatim (false) or with whitespace normalized as per Element.getTextNormalize().

Default: false

Parameters:
textNormalize - boolean true=>normalize the whitespace, false=>use text verbatim

setTrimText

public void setTrimText(boolean textTrim)
Deprecated. Deprecated in beta7, use setTextNormalize() instead

This will set whether the text is output verbatim (false) or with whitespace stripped.

Default: false

Parameters:
textTrim - boolean true=>trim the whitespace, false=>use text verbatim

setIndent

public void setIndent(java.lang.String indent)

This will set the indent String to use; this is usually a String of empty spaces. If you pass null, or the empty string (""), then no indentation will happen.

Default: none (null)

Parameters:
indent - String to use for indentation.

setIndent

public void setIndent(boolean doIndent)
Set the indent on or off. If setting on, will use the value of STANDARD_INDENT, which is usually two spaces.

Parameters:
doIndent - if true, set indenting on; if false, set indenting off

setIndentSize

public void setIndentSize(int indentSize)

This will set the indent String's size; an indentSize of 4 would result in the indentation being equivalent to the String "    " (four space chars).

Parameters:
indentSize - int number of spaces in indentation.

indent

protected void indent(java.io.Writer out,
                      int level)
               throws java.io.IOException

This will print the proper indent characters for the given indent level.

Parameters:
out - Writer to write to
level - int indentation level
Throws:
java.io.IOException

maybePrintln

protected void maybePrintln(java.io.Writer out)
                     throws java.io.IOException

This will print a new line only if the newlines flag was set to true

Parameters:
out - Writer to write to
Throws:
java.io.IOException

makeWriter

protected java.io.Writer makeWriter(java.io.OutputStream out)
                             throws java.io.UnsupportedEncodingException
Get an OutputStreamWriter, use preferred encoding.

Throws:
java.io.UnsupportedEncodingException

makeWriter

protected java.io.Writer makeWriter(java.io.OutputStream out,
                                    java.lang.String enc)
                             throws java.io.UnsupportedEncodingException
Get an OutputStreamWriter, use specified encoding.

Throws:
java.io.UnsupportedEncodingException

output

public void output(org.jdom.Document doc,
                   java.io.OutputStream out)
            throws java.io.IOException

This will print the Document to the given output stream. The characters are printed using the encoding specified in the constructor, or a default of UTF-8.

Parameters:
doc - Document to format.
out - OutputStream to write to.
Throws:
java.io.IOException - - if there's any problem writing.

output

public void output(org.jdom.Document doc,
                   java.io.Writer out)
            throws java.io.IOException

This will print the Document to the given Writer.

Warning: using your own Writer may cause the outputter's preferred character encoding to be ignored. If you use encodings other than UTF-8, we recommend using the method that takes an OutputStream instead.

Parameters:
doc - Document to format.
out - Writer to write to.
Throws:
java.io.IOException - - if there's any problem writing.

output

public void output(org.jdom.Element element,
                   java.io.Writer out)
            throws java.io.IOException

Print out an Element, including its Attributes, and its value, and all contained (child) elements etc.

Parameters:
element - Element to output.
out - Writer to write to.
Throws:
java.io.IOException

output

public void output(org.jdom.Element element,
                   java.io.OutputStream out)
            throws java.io.IOException

Print out an Element, including its Attributes, and its value, and all contained (child) elements etc.

Parameters:
element - Element to output.
out - Writer to write to.
Throws:
java.io.IOException

outputElementContent

public void outputElementContent(org.jdom.Element element,
                                 java.io.Writer out)
                          throws java.io.IOException

This will handle printing out an Element's content only, not including its tag, and attributes. This can be useful for printing the content of an element that contains HTML, like "<description>JDOM is <b>fun>!</description>".

Parameters:
element - Element to output.
out - Writer to write to.
Throws:
java.io.IOException

outputElementContent

public void outputElementContent(org.jdom.Element element,
                                 java.io.OutputStream out)
                          throws java.io.IOException

This will handle printing out an Element's content only, not including its tag, and attributes. This can be useful for printing the content of an element that contains HTML, like "<description>JDOM is <b>fun>!</description>".

Parameters:
element - Element to output.
out - OutputStream to write to.
Throws:
java.io.IOException

output

public void output(org.jdom.Comment comment,
                   java.io.Writer out)
            throws java.io.IOException

Print out a Comment

Parameters:
comment - Comment to output.
out - Writer to write to.
Throws:
java.io.IOException

output

public void output(org.jdom.Comment comment,
                   java.io.OutputStream out)
            throws java.io.IOException

Print out a Comment

Parameters:
comment - Comment to output.
out - OutputStream to write to.
Throws:
java.io.IOException

output

public void output(java.lang.String string,
                   java.io.Writer out)
            throws java.io.IOException

Print out a String. Perfoms the necessary entity escaping and whitespace stripping.

Parameters:
string - String to output.
out - Writer to write to.
Throws:
java.io.IOException

output

public void output(java.lang.String string,
                   java.io.OutputStream out)
            throws java.io.IOException

Print out a String. Perfoms the necessary entity escaping and whitespace stripping.

Parameters:
string - String to output.
out - OutputStream to write to.
Throws:
java.io.IOException

output

public void output(org.jdom.Text text,
                   java.io.Writer out)
            throws java.io.IOException

Print out a Text. Perfoms the necessary entity escaping and whitespace stripping.

Parameters:
text - Text to output.
out - Writer to write to.
Throws:
java.io.IOException

output

public void output(org.jdom.Text text,
                   java.io.OutputStream out)
            throws java.io.IOException

Print out a Text. Perfoms the necessary entity escaping and whitespace stripping.

Parameters:
text - Text to output.
out - OutputStream to write to.
Throws:
java.io.IOException

outputString

public java.lang.String outputString(org.jdom.Document doc)
Return a string representing a document. Uses an internal StringWriter. Warning: a String is Unicode, which may not match the outputter's specified encoding.

Parameters:
doc - Document to format.

outputString

public java.lang.String outputString(org.jdom.Element element)
Return a string representing an element. Warning: a String is Unicode, which may not match the outputter's specified encoding.

Parameters:
element - Element to format.

outputString

public java.lang.String outputString(org.jdom.Comment comment)
Return a string representing a comment. Warning: a String is Unicode, which may not match the outputter's specified encoding.

Parameters:
comment - Comment to format.

printComment

protected void printComment(org.jdom.Comment comment,
                            java.io.Writer out)
                     throws java.io.IOException

This will write the comment to the specified writer.

Parameters:
comment - Comment to write.
out - Writer to write to.
Throws:
java.io.IOException

printElement

protected void printElement(org.jdom.Element element,
                            java.io.Writer out,
                            int indentLevel)
                     throws java.io.IOException

This will handle printing out an Element, its Attributes, and its value.

Parameters:
element - Element to output.
out - Writer to write to.
indentLevel - int level of indention.
Throws:
java.io.IOException

printRawElement

public void printRawElement(RawElement element,
                            java.io.Writer out)
                     throws java.io.IOException
Throws:
java.io.IOException

printElementContent

protected void printElementContent(org.jdom.Element element,
                                   java.io.Writer out,
                                   int indentLevel,
                                   java.util.List eltContent)
                            throws java.io.IOException

This will handle printing out an Element's content only, not including its tag, attributes, and namespace info.

Parameters:
element - Element to output.
out - Writer to write to.
indentLevel - int level of indention.
eltContent - the content to print
Throws:
java.io.IOException

printString

protected void printString(java.lang.String s,
                           java.io.Writer out)
                    throws java.io.IOException
Print a string. Escapes the element entities, trims interior whitespace if necessary.

Throws:
java.io.IOException

printAttributes

protected void printAttributes(java.util.List attributes,
                               org.jdom.Element parent,
                               java.io.Writer out)
                        throws java.io.IOException

This will handle printing out an Attribute list.

Parameters:
attributes - List of Attribute objcts
out - Writer to write to
Throws:
java.io.IOException

escapeAttributeEntities

protected java.lang.String escapeAttributeEntities(java.lang.String st)

This will take the pre-defined entities in XML 1.0 and convert their character representation to the appropriate entity reference, suitable for XML attributes. It does no converstion for ' because it's not necessary as the outputter writes attributes surrounded by double-quotes.

Parameters:
st - String input to escape.
Returns:
String with escaped content.

escapeTextEntities

protected java.lang.String escapeTextEntities(java.lang.String st)
only escape ampersand


escapeElementEntities

protected java.lang.String escapeElementEntities(java.lang.String st)

This will take the three pre-defined entities in XML 1.0 (used specifically in XML elements) and convert their character representation to the appropriate entity reference, suitable for XML element.

Parameters:
st - String input to escape.
Returns:
String with escaped content.


Copyright © 2001-2006 Groiss Informatics GmbH. All Rights Reserved.