com.quiotix.html.parser
Class HtmlFormatter

java.lang.Object
  extended bycom.quiotix.html.parser.HtmlVisitor
      extended bycom.quiotix.html.parser.HtmlFormatter

public class HtmlFormatter
extends HtmlVisitor

HtmlFormatter is a Visitor which traverses an HtmlDocument, dumping the contents of the document to a specified output stream. It assumes that the documents has been preprocessed by HtmlCollector (which matches up beginning and end tags) and by HtmlScrubber (which formats tags in a consistent way). In particular, HtmlScrubber should be invoked with the TRIM_SPACES option to remove trailing spaces, which can confuse the formatting algorithm.

The right margin and indent increment can be specified as properties.

Author:
Brian Goetz, Quiotix
See Also:
com.quiotix.html.HtmlVisitor, com.quiotix.html.HtmlCollector, com.quiotix.html.HtmlScrubber

Field Summary
protected  com.quiotix.html.parser.TagBlockRenderer blockRenderer
           
protected  int indentSize
           
protected  boolean inPreBlock
           
protected  com.quiotix.html.parser.MarginWriter out
           
protected  HtmlDocument.HtmlElement previousElement
           
protected  int rightMargin
           
protected static java.util.Hashtable tagsIndentBlock
           
protected static java.lang.String[] tagsIndentStrings
           
protected static java.util.Hashtable tagsNewlineBefore
           
protected static java.lang.String[] tagsNewlineBeforeStrings
           
protected static java.util.Hashtable tagsPreformatted
           
protected static java.lang.String[] tagsPreformattedStrings
           
protected static java.util.Hashtable tagsTryMatch
           
protected static java.lang.String[] tagsTryMatchStrings
           
 
Constructor Summary
HtmlFormatter(java.io.OutputStream os)
           
 
Method Summary
 void finish()
           
static void main(java.lang.String[] args)
           
 void setIndent(int indent)
           
 void setRightMargin(int margin)
           
 void start()
           
 void visit(HtmlDocument.Comment c)
           
 void visit(HtmlDocument.EndTag t)
           
 void visit(HtmlDocument.Newline n)
           
 void visit(HtmlDocument.Tag t)
           
 void visit(HtmlDocument.TagBlock block)
           
 void visit(HtmlDocument.Text t)
           
 
Methods inherited from class com.quiotix.html.parser.HtmlVisitor
visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected com.quiotix.html.parser.MarginWriter out

rightMargin

protected int rightMargin

indentSize

protected int indentSize

tagsIndentBlock

protected static java.util.Hashtable tagsIndentBlock

tagsNewlineBefore

protected static java.util.Hashtable tagsNewlineBefore

tagsPreformatted

protected static java.util.Hashtable tagsPreformatted

tagsTryMatch

protected static java.util.Hashtable tagsTryMatch

tagsIndentStrings

protected static final java.lang.String[] tagsIndentStrings

tagsNewlineBeforeStrings

protected static final java.lang.String[] tagsNewlineBeforeStrings

tagsPreformattedStrings

protected static final java.lang.String[] tagsPreformattedStrings

tagsTryMatchStrings

protected static final java.lang.String[] tagsTryMatchStrings

blockRenderer

protected com.quiotix.html.parser.TagBlockRenderer blockRenderer

previousElement

protected HtmlDocument.HtmlElement previousElement

inPreBlock

protected boolean inPreBlock
Constructor Detail

HtmlFormatter

public HtmlFormatter(java.io.OutputStream os)
              throws java.lang.Exception
Method Detail

setRightMargin

public void setRightMargin(int margin)

setIndent

public void setIndent(int indent)

visit

public void visit(HtmlDocument.TagBlock block)
Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.Tag t)
Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.EndTag t)
Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.Comment c)
Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.Text t)
Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.Newline n)
Overrides:
visit in class HtmlVisitor

start

public void start()
Overrides:
start in class HtmlVisitor

finish

public void finish()
Overrides:
finish in class HtmlVisitor

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception