|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nl.justobjects.toolkit.xml.XMLPrintVisitor
XMLPrintVisitor 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 XMLPrintVisitor on a hierarchy of nodes:
PrintWriter printWriter = new PrintWriter(); Visitor htmlPrintVisitor = new XMLPrintVisitor(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
|
protected java.io.Writer |
writer
|
Constructor Summary | |
XMLPrintVisitor(java.lang.String fileName)
Constructor for default encoding. |
|
XMLPrintVisitor(java.io.Writer writer)
Constructor for default encoding. |
|
XMLPrintVisitor(java.io.Writer writer,
java.lang.String encoding)
Constructor for customized encoding. |
|
XMLPrintVisitor(java.io.Writer writer,
java.lang.String encoding,
java.lang.String doctype)
Constructor for customized encoding and doctype. |
Method Summary | |
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 |
|
Field Detail |
protected java.io.Writer writer
protected int level
protected java.lang.String doctype
Constructor Detail |
public XMLPrintVisitor(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 XMLPrintVisitor(java.io.Writer writer, java.lang.String encoding)
writer
- The character output stream to use.encoding
- Java character encoding in use by writer.public XMLPrintVisitor(java.io.Writer writer)
writer
- The character output stream to use.public XMLPrintVisitor(java.lang.String fileName)
writer
- The character output stream to use.Method Detail |
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 XML.public void visitElementPost(org.w3c.dom.Element element)
visitElementPost
in interface Visitor
element
- Node to print as XML.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 |