com.quiotix.html.parser
Class HtmlFormatter

java.lang.Object
  extended by com.quiotix.html.parser.HtmlVisitor
      extended by com.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:
HtmlVisitor, HtmlCollector, 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 Set tagsIndentBlock
           
protected static String[] tagsIndentStrings
           
protected static Set tagsNewlineBefore
           
protected static String[] tagsNewlineBeforeStrings
           
protected static Set tagsPreformatted
           
protected static String[] tagsPreformattedStrings
           
protected static Set tagsTryMatch
           
protected static String[] tagsTryMatchStrings
           
 
Constructor Summary
HtmlFormatter(OutputStream os)
          Constructor.
 
Method Summary
 void finish()
          Finish.
static void main(String[] args)
          Runnable.
 void setIndent(int indent)
           
 void setRightMargin(int margin)
           
 void start()
          Start.
 void visit(HtmlDocument.Comment c)
          Visit a Comment.
 void visit(HtmlDocument.EndTag t)
          Visit an EndTag.
 void visit(HtmlDocument.Newline n)
          Visit a Newline.
 void visit(HtmlDocument.Tag t)
          Visit a Tag.
 void visit(HtmlDocument.TagBlock block)
          Visit a TagBlock.
 void visit(HtmlDocument.Text t)
          Visit Text.
 
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 Set tagsIndentBlock

tagsNewlineBefore

protected static Set tagsNewlineBefore

tagsPreformatted

protected static Set tagsPreformatted

tagsTryMatch

protected static Set tagsTryMatch

tagsIndentStrings

protected static final String[] tagsIndentStrings

tagsNewlineBeforeStrings

protected static final String[] tagsNewlineBeforeStrings

tagsPreformattedStrings

protected static final String[] tagsPreformattedStrings

tagsTryMatchStrings

protected static final String[] tagsTryMatchStrings

blockRenderer

protected com.quiotix.html.parser.TagBlockRenderer blockRenderer

previousElement

protected HtmlDocument.HtmlElement previousElement

inPreBlock

protected boolean inPreBlock
Constructor Detail

HtmlFormatter

public HtmlFormatter(OutputStream os)
              throws Exception
Constructor.

Throws:
Exception
Method Detail

setRightMargin

public void setRightMargin(int margin)
Parameters:
margin - the right margin column to wrap at

setIndent

public void setIndent(int indent)
Parameters:
indent - the number of spaces to indent by

visit

public void visit(HtmlDocument.TagBlock block)
Description copied from class: HtmlVisitor
Visit a TagBlock.

Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.Tag t)
Description copied from class: HtmlVisitor
Visit a Tag.

Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.EndTag t)
Description copied from class: HtmlVisitor
Visit an EndTag.

Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.Comment c)
Description copied from class: HtmlVisitor
Visit a Comment.

Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.Text t)
Description copied from class: HtmlVisitor
Visit Text.

Overrides:
visit in class HtmlVisitor

visit

public void visit(HtmlDocument.Newline n)
Description copied from class: HtmlVisitor
Visit a Newline.

Overrides:
visit in class HtmlVisitor

start

public void start()
Description copied from class: HtmlVisitor
Start.

Overrides:
start in class HtmlVisitor

finish

public void finish()
Description copied from class: HtmlVisitor
Finish.

Overrides:
finish in class HtmlVisitor

main

public static void main(String[] args)
                 throws Exception
Runnable.

Throws:
Exception


Copyright © 1999-2011 Quiotix. All Rights Reserved.