|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.caucho.xml2.XmlPrinter
public class XmlPrinter
Controls printing of XML documents.
Typical use:
Node node = ...;
OutputStream os = Vfs.openWrite("test.xml");
XmlPrinter printer = new XmlPrinter(os);
printer.printXml(node);
Constructor Summary | |
---|---|
XmlPrinter()
Create an XmlPrinter. |
|
XmlPrinter(java.io.OutputStream os)
Creates a new XmlPrinter writing to an output stream. |
|
XmlPrinter(java.io.Writer writer)
Creates a new XmlPrinter writing to a writer. |
Method Summary | |
---|---|
void |
addCdataElement(java.lang.String elt)
|
void |
attribute(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
java.lang.String value)
Prints an attribute |
void |
cdata(char[] buffer,
int offset,
int length)
|
void |
cdata(java.lang.String text)
|
void |
comment(java.lang.String data)
Prints a comment |
void |
endDocument()
Callback when the document completes |
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
Prints the end tag of an element |
void |
endPrefixMapping(java.lang.String prefix)
|
boolean |
finishAttributes()
Complete printing of the attributes when the open tag completes. |
boolean |
getEscapeText()
Returns true if the text is currently being escaped |
boolean |
getEscaping()
Returns the current XML escaping. |
boolean |
getIncludeContentType()
Return true if the printer should automatically add the <meta content-type> to HTML. |
LineMap |
getLineMap()
|
Path |
getPath()
|
void |
init(WriteStream os)
Initialize the XmlPrinter with the write stream. |
boolean |
isJSP()
True if this is JSP special cased. |
boolean |
isPretty()
Returns true if the printer is currently pretty-printing the output. |
void |
print(org.w3c.dom.Node node)
|
static void |
print(Path path,
org.w3c.dom.Node node)
Prints the node as XML. |
void |
printHeader(java.lang.String top)
Prints the header, if necessary. |
void |
printHtml(org.w3c.dom.Node node)
Prints the node and children as HTML |
void |
printNode(org.w3c.dom.Node node)
|
void |
printPrettyXml(org.w3c.dom.Node node)
Prints the node and children as XML, automatically indending |
java.lang.String |
printString(org.w3c.dom.Node node)
Prints the node as XML to a string. |
void |
printXml(org.w3c.dom.Node node)
Prints the node as XML. |
void |
processingInstruction(java.lang.String name,
java.lang.String data)
Prints a processing instruction |
void |
setDocumentLocator(org.xml.sax.Locator locator)
Sets the locator. |
void |
setEncoding(java.lang.String encoding)
Sets the character set encoding for the output file. |
void |
setEscapeText(boolean isEscaped)
Sets true if the text should be escaped, else it will be printed verbatim. |
void |
setEscaping(boolean escapeText)
Sets to true if XML entities like < should be escaped as <. |
void |
setIncludeContentType(boolean include)
Set true if the printer should automatically add the <meta content-type> to HTML. |
void |
setJSP(boolean isJsp)
Set true if this is JSP special cased. |
void |
setLineMap(java.lang.String filename)
Creates a new line map. |
void |
setLocation(java.lang.String filename,
int line,
int column)
Sets the current location. |
void |
setMethod(java.lang.String method)
Sets the output methods, like the XSL <xsl:output method='method'/>. |
void |
setMimeType(java.lang.String mimeType)
|
void |
setPretty(boolean isPretty)
Set to true if the printer should add whitespace to 'pretty-print' the output. |
void |
setPrintDeclaration(boolean printDeclaration)
|
void |
setPublicId(java.lang.String id)
|
void |
setStandalone(java.lang.String standalone)
|
void |
setSystemId(java.lang.String id)
|
void |
setVersion(java.lang.String version)
Sets the XML/HTML version of the output file. |
void |
startDocument()
Callback when the document starts printing. |
void |
startDocument(org.w3c.dom.Document document)
|
void |
startElement(java.lang.String url,
java.lang.String localName,
java.lang.String qName)
Called at the start of a new element. |
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
|
void |
text(char[] buffer,
int offset,
int length)
Prints text. |
void |
text(java.lang.String text)
Prints text. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XmlPrinter()
public XmlPrinter(java.io.OutputStream os)
os
- output stream serving as the destinationpublic XmlPrinter(java.io.Writer writer)
writer
- destination of the serialized nodeMethod Detail |
---|
public void init(WriteStream os)
os
- WriteStream containing the results.public static void print(Path path, org.w3c.dom.Node node) throws java.io.IOException
node
- source DOM node
java.io.IOException
public void printXml(org.w3c.dom.Node node) throws java.io.IOException
node
- source DOM node
java.io.IOException
public void printHtml(org.w3c.dom.Node node) throws java.io.IOException
node
- the top node to print
java.io.IOException
public void printPrettyXml(org.w3c.dom.Node node) throws java.io.IOException
node
- the top node to print
java.io.IOException
public java.lang.String printString(org.w3c.dom.Node node) throws java.io.IOException
node
- the source node
java.io.IOException
public void setEscaping(boolean escapeText)
escapeText
- set to true if entities should be escaped.public boolean getEscaping()
public void setMethod(java.lang.String method)
public void setVersion(java.lang.String version)
version
- the output versionpublic void setEncoding(java.lang.String encoding)
encoding
- the mime name of the output encodingpublic void setMimeType(java.lang.String mimeType)
public void setJSP(boolean isJsp)
public boolean isJSP()
public void setPretty(boolean isPretty)
isPretty
- if true, add spaces for printingpublic boolean isPretty()
public void setPrintDeclaration(boolean printDeclaration)
public void setStandalone(java.lang.String standalone)
public void setSystemId(java.lang.String id)
public void setIncludeContentType(boolean include)
public boolean getIncludeContentType()
public void setPublicId(java.lang.String id)
public Path getPath()
public void setLineMap(java.lang.String filename)
public LineMap getLineMap()
public void addCdataElement(java.lang.String elt)
public void print(org.w3c.dom.Node node) throws java.io.IOException
java.io.IOException
public void printNode(org.w3c.dom.Node node) throws java.io.IOException
java.io.IOException
public void startDocument(org.w3c.dom.Document document) throws java.io.IOException
java.io.IOException
public void startDocument() throws java.io.IOException
startDocument
in interface XMLWriter
java.io.IOException
public void endDocument() throws java.io.IOException
endDocument
in interface XMLWriter
java.io.IOException
public void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator
in interface XMLWriter
public void setLocation(java.lang.String filename, int line, int column)
filename
- the source filenameline
- the source linecolumn
- the source columnpublic void startElement(java.lang.String url, java.lang.String localName, java.lang.String qName) throws java.io.IOException
startElement
in interface XMLWriter
url
- the namespace urllocalName
- the local nameqName
- the qualified name
java.io.IOException
public void printHeader(java.lang.String top) throws java.io.IOException
top
- name of the top element
java.io.IOException
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws java.io.IOException
startPrefixMapping
in interface XMLWriter
java.io.IOException
public void endPrefixMapping(java.lang.String prefix) throws java.io.IOException
endPrefixMapping
in interface XMLWriter
java.io.IOException
public void attribute(java.lang.String uri, java.lang.String localName, java.lang.String qName, java.lang.String value) throws java.io.IOException
attribute
in interface XMLWriter
uri
- namespace urilocalName
- localname of the attributeqName
- qualified name of the attributevalue
- value of the attribute.
java.io.IOException
public boolean finishAttributes() throws java.io.IOException
java.io.IOException
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws java.io.IOException
endElement
in interface XMLWriter
uri
- the namespace uri of the elementlocalName
- the localname of the element tagqName
- qualified name of the element
java.io.IOException
public void processingInstruction(java.lang.String name, java.lang.String data) throws java.io.IOException
processingInstruction
in interface XMLWriter
name
- the name of the processing instructiondata
- the processing instruction data
java.io.IOException
public void comment(java.lang.String data) throws java.io.IOException
comment
in interface XMLWriter
data
- the comment data
java.io.IOException
public boolean getEscapeText()
getEscapeText
in interface XMLWriter
public void setEscapeText(boolean isEscaped)
setEscapeText
in interface XMLWriter
public void text(java.lang.String text) throws java.io.IOException
text
in interface XMLWriter
java.io.IOException
public void text(char[] buffer, int offset, int length) throws java.io.IOException
text
in interface XMLWriter
java.io.IOException
public void cdata(java.lang.String text) throws java.io.IOException
cdata
in interface XMLWriter
java.io.IOException
public void cdata(char[] buffer, int offset, int length) throws java.io.IOException
cdata
in interface XMLWriter
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |