org.apache.empire.xml
Class XMLWriter

java.lang.Object
  extended by org.apache.empire.xml.XMLWriter

public class XMLWriter
extends Object

This class prints out a XML-DOM-Tree to an output stream.


Field Summary
protected  boolean canonical
          Canonical output.
protected static org.slf4j.Logger log
           
protected  PrintWriter out
          Print writer.
 
Constructor Summary
XMLWriter(OutputStream outStream)
          Constructor
XMLWriter(OutputStream outStream, String charsetEncoding)
          Creates a XML Writer object.
XMLWriter(Writer writer, String charsetEncoding)
          Creates a XML Writer object.
 
Method Summary
static void debug(Document doc)
          Prints out the DOM-Tree on System.out for debugging purposes.
static void debugToFile(Document doc, String filename)
          Prints out the DOM-Tree to a file for debugging purposes.
protected  String normalize(String s)
          Converts a string to valid XML-Syntax replacing XML entities.
static String normalize(String s, boolean canonical)
           
 void print(Document doc)
          Prints the specified document.
 void print(Document doc, String styleSheet)
          Prints the specified document.
 int print(Node node, int level)
          Prints the specified node recursively
static void saveAsFile(Document doc, String filename)
          Prints out the DOM-Tree.
static void setXmlWriterDebugPath(String path)
           
protected  Attr[] sortAttributes(NamedNodeMap attrs)
          Sorts attributes by name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.slf4j.Logger log

out

protected PrintWriter out
Print writer.


canonical

protected boolean canonical
Canonical output.

Constructor Detail

XMLWriter

public XMLWriter(Writer writer,
                 String charsetEncoding)
Creates a XML Writer object.

Parameters:
writer - a writer to the output stream
charsetEncoding - encoding type (i.e. utf-8)

XMLWriter

public XMLWriter(OutputStream outStream,
                 String charsetEncoding)
          throws UnsupportedEncodingException
Creates a XML Writer object.

Parameters:
outStream - the output stream
charsetEncoding - The name of a supported charset
Throws:
UnsupportedEncodingException - If the named encoding is not supported

XMLWriter

public XMLWriter(OutputStream outStream)
Constructor

Parameters:
outStream - the output stream
Method Detail

debug

public static void debug(Document doc)
Prints out the DOM-Tree on System.out for debugging purposes.

Parameters:
doc - The XML-Document to print

debugToFile

public static void debugToFile(Document doc,
                               String filename)
Prints out the DOM-Tree to a file for debugging purposes. The file will be truncated if it exists or created if if does not exist.

Parameters:
doc - The XML-Document to print
filename - The name of the file to write the XML-Document to

saveAsFile

public static void saveAsFile(Document doc,
                              String filename)
Prints out the DOM-Tree. The file will be truncated if it exists or created if if does not exist.

Parameters:
doc - The XML-Document to print
filename - The name of the file to write the XML-Document to

setXmlWriterDebugPath

public static void setXmlWriterDebugPath(String path)

print

public int print(Node node,
                 int level)
Prints the specified node recursively

Parameters:
node - the current node to print
level - the nesting level used for indenting the output
Returns:
the node type of this node

print

public void print(Document doc)
Prints the specified document.

Parameters:
doc - the XML-DOM-Document to print

print

public void print(Document doc,
                  String styleSheet)
Prints the specified document.

Parameters:
doc - the XML-DOM-Document to print
styleSheet - the XML-DOM-Document to print

sortAttributes

protected Attr[] sortAttributes(NamedNodeMap attrs)
Sorts attributes by name.

Parameters:
attrs - the unsorted list of attributes
Returns:
the sorted list of attributes

normalize

protected String normalize(String s)
Converts a string to valid XML-Syntax replacing XML entities.

Parameters:
s - the string to normalize

normalize

public static String normalize(String s,
                               boolean canonical)


Copyright © 2008–2014 Apache Software Foundation. All rights reserved.