Class XMLWriter

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

public class XMLWriter extends Object
This class prints out a XML-DOM-Tree to an output stream.

  • Field Details

    • log

      protected static final org.slf4j.Logger log
    • out

      protected PrintWriter out
      Print writer.
    • canonical

      protected boolean canonical
      Canonical output.
  • Constructor Details

    • 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 Details

    • 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)
      Saves an XML-Document as file. 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
      Throws:
      FileWriteException
    • 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)