|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nl.justobjects.toolkit.xml.HTMLPrintVisitor
HTMLPrintVisitor implements the Visitor interface in the visitor design pattern for the purpose of printing in HTML-like format the various DOM-Nodes.
In HTML-like printing, only the following Nodes are printed:
<BR>
instead of <BR/>
.The following sample code uses the HTMLPrintVisitor on a hierarchy of nodes:
PrintWriter printWriter = new PrintWriter(); Visitor htmlPrintVisitor = new HTMLPrintVisitor(printWriter); TreeWalker treeWalker = new TreeWalker(htmlPrintVisitor); treeWalker.traverse(document); printWriter.close();
By default, this doesn't print non-specified attributes.
Visitor
,
TreeWalker
Field Summary | |
protected java.lang.String |
doctype
|
protected int |
level
|
(package private) static java.util.Hashtable |
s_empties
|
(package private) static java.util.Hashtable |
s_entities
|
protected java.io.Writer |
writer
|
Constructor Summary | |
HTMLPrintVisitor(java.io.Writer writer)
Constructor for default encoding. |
|
HTMLPrintVisitor(java.io.Writer writer,
java.lang.String encoding)
Constructor for customized encoding. |
|
HTMLPrintVisitor(java.io.Writer writer,
java.lang.String encoding,
java.lang.String doctype)
Constructor for customized encoding and doctype. |
Method Summary | |
(package private) static void |
|
private void |
flush()
|
static void |
main(java.lang.String[] args)
Ignore GeneralReference Nodes. |
void |
visitAttributePre(org.w3c.dom.Attr attr)
Creates a formatted string representation of the specified attribute Node and its associated attributes, and directs it to the print writer. |
void |
visitDocumentPost(org.w3c.dom.Document document)
Flush the writer. |
void |
visitDocumentPre(org.w3c.dom.Document document)
Writes the doctype from the constructor (if any). |
void |
visitElementPost(org.w3c.dom.Element element)
Creates a formatted string representation of the end of the specified element Node, and directs it to the print writer. |
void |
visitElementPre(org.w3c.dom.Element element)
Creates a formatted string representation of the start of the specified element Node and its associated attributes, and directs it to the print writer. |
void |
visitText(org.w3c.dom.Text text)
Creates a formatted string representation of the specified text Node, and directs it to the print writer. |
private void |
write(java.lang.String s)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
Field Detail |
protected java.io.Writer writer
protected int level
protected java.lang.String doctype
static java.util.Hashtable s_empties
static java.util.Hashtable s_entities
Constructor Detail |
public HTMLPrintVisitor(java.io.Writer writer, java.lang.String encoding, java.lang.String doctype)
writer
- The character output stream to use.encoding
- Java character encoding in use by writer.doctype
- String to be printed at the top of the document.public HTMLPrintVisitor(java.io.Writer writer, java.lang.String encoding)
writer
- The character output stream to use.encoding
- Java character encoding in use by writer.public HTMLPrintVisitor(java.io.Writer writer)
writer
- The character output stream to use.Method Detail |
static void()
public void visitDocumentPre(org.w3c.dom.Document document)
visitDocumentPre
in interface Visitor
document
- Node print as HTML.public void visitDocumentPost(org.w3c.dom.Document document)
visitDocumentPost
in interface Visitor
document
- Node to print as HTML.public void visitElementPre(org.w3c.dom.Element element)
visitElementPre
in interface Visitor
element
- Node to print as HTML.public void visitElementPost(org.w3c.dom.Element element)
visitElementPost
in interface Visitor
element
- Node to print as HTML.public void visitAttributePre(org.w3c.dom.Attr attr)
Note that TXAttribute Nodes are not parsed into the document object hierarchy by the XML4J parser; attributes exist as part of a Element Node.
element
- Node to print as HTML.public void visitText(org.w3c.dom.Text text)
visitText
in interface Visitor
text
- Node to print with format.private void write(java.lang.String s)
private void flush()
public static void main(java.lang.String[] args)
generalReference
- CURRENTLY NOT IMPLEMENTED.
public void visitGeneralReferencePre(GeneralReference generalReference) throws Exception {
String name = generalReference.getName();
if (s_entities.get(name) != null && generalReference.getChildNodes().getLength() == 1) {
Node child = generalReference.getFirstChild();
if (child.getNodeType() == Node.TEXT_NODE && child.getNodeValue().length() == 1) {
write((char)'&' + name + (char)';');
throw new ToNextSiblingTraversalException();
}
}
}
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |