Class PrettyPrintXMLWriter

java.lang.Object
org.codehaus.plexus.util.xml.PrettyPrintXMLWriter
All Implemented Interfaces:
XMLWriter
Direct Known Subclasses:
CompactXMLWriter

public class PrettyPrintXMLWriter extends Object implements XMLWriter
Implementation of XMLWriter which emits nicely formatted documents.
Version:
$Id$
  • Field Details

    • LS

      protected static final String LS
      Line separator ("\n" on UNIX)
    • writer

      private PrintWriter writer
    • elementStack

      private LinkedList<String> elementStack
    • tagInProgress

      private boolean tagInProgress
    • depth

      private int depth
    • lineIndenter

      private String lineIndenter
    • lineSeparator

      private String lineSeparator
    • encoding

      private String encoding
    • docType

      private String docType
    • readyForNewLine

      private boolean readyForNewLine
    • tagIsEmpty

      private boolean tagIsEmpty
    • amp

      private static final Pattern amp
    • lt

      private static final Pattern lt
    • gt

      private static final Pattern gt
    • dqoute

      private static final Pattern dqoute
    • sqoute

      private static final Pattern sqoute
    • crlf_str

      private static final String crlf_str
      See Also:
    • crlf

      private static final Pattern crlf
    • lowers

      private static final Pattern lowers
  • Constructor Details

    • PrettyPrintXMLWriter

      public PrettyPrintXMLWriter(PrintWriter writer, String lineIndenter)
      Parameters:
      writer - not null
      lineIndenter - could be null, but the normal way is some spaces.
    • PrettyPrintXMLWriter

      public PrettyPrintXMLWriter(Writer writer, String lineIndenter)
      Parameters:
      writer - not null
      lineIndenter - could be null, but the normal way is some spaces.
    • PrettyPrintXMLWriter

      public PrettyPrintXMLWriter(PrintWriter writer)
      Parameters:
      writer - not null
    • PrettyPrintXMLWriter

      public PrettyPrintXMLWriter(Writer writer)
      Parameters:
      writer - not null
    • PrettyPrintXMLWriter

      public PrettyPrintXMLWriter(PrintWriter writer, String lineIndenter, String encoding, String doctype)
      Parameters:
      writer - not null
      lineIndenter - could be null, but the normal way is some spaces.
      encoding - could be null or invalid.
      doctype - could be null.
    • PrettyPrintXMLWriter

      public PrettyPrintXMLWriter(Writer writer, String lineIndenter, String encoding, String doctype)
      Parameters:
      writer - not null
      lineIndenter - could be null, but the normal way is some spaces.
      encoding - could be null or invalid.
      doctype - could be null.
    • PrettyPrintXMLWriter

      public PrettyPrintXMLWriter(PrintWriter writer, String encoding, String doctype)
      Parameters:
      writer - not null
      encoding - could be null or invalid.
      doctype - could be null.
    • PrettyPrintXMLWriter

      public PrettyPrintXMLWriter(Writer writer, String encoding, String doctype)
      Parameters:
      writer - not null
      encoding - could be null or invalid.
      doctype - could be null.
    • PrettyPrintXMLWriter

      public PrettyPrintXMLWriter(PrintWriter writer, String lineIndenter, String lineSeparator, String encoding, String doctype)
      Parameters:
      writer - not null
      lineIndenter - could be null, but the normal way is some spaces.
      lineSeparator - could be null, but the normal way is valid line separator ("\n" on UNIX).
      encoding - could be null or invalid.
      doctype - could be null.
  • Method Details

    • startElement

      public void startElement(String name)
      Specified by:
      startElement in interface XMLWriter
    • writeText

      public void writeText(String text)
      Specified by:
      writeText in interface XMLWriter
    • writeMarkup

      public void writeMarkup(String text)
      Specified by:
      writeMarkup in interface XMLWriter
    • writeText

      private void writeText(String text, boolean escapeXml)
    • escapeXml

      private static String escapeXml(String text)
    • escapeXmlAttribute

      private static String escapeXmlAttribute(String text)
    • addAttribute

      public void addAttribute(String key, String value)
      Specified by:
      addAttribute in interface XMLWriter
    • endElement

      public void endElement()
      Specified by:
      endElement in interface XMLWriter
    • write

      private void write(String str)
      Write a string to the underlying writer
      Parameters:
      str -
    • finishTag

      private void finishTag()
    • getLineIndenter

      protected String getLineIndenter()
      Get the string used as line indenter
      Returns:
      the line indenter
    • setLineIndenter

      protected void setLineIndenter(String lineIndenter)
      Set the string used as line indenter
      Parameters:
      lineIndenter - new line indenter, could be null, but the normal way is some spaces.
    • getLineSeparator

      protected String getLineSeparator()
      Get the string used as line separator or LS if not set.
      Returns:
      the line separator
      See Also:
    • setLineSeparator

      protected void setLineSeparator(String lineSeparator)
      Set the string used as line separator
      Parameters:
      lineSeparator - new line separator, could be null but the normal way is valid line separator ("\n" on UNIX).
    • endOfLine

      protected void endOfLine()
      Write the end of line character (using specified line separator) and start new line with indentation
      See Also:
    • writeDocumentHeaders

      private void writeDocumentHeaders()
    • setWriter

      protected void setWriter(PrintWriter writer)
      Set the underlying writer
      Parameters:
      writer - not null writer
    • getWriter

      protected PrintWriter getWriter()
      Get the underlying writer
      Returns:
      the underlying writer
    • setDepth

      protected void setDepth(int depth)
      Set the depth in the xml indentation
      Parameters:
      depth - new depth
    • getDepth

      protected int getDepth()
      Get the current depth in the xml indentation
      Returns:
      the current depth
    • setEncoding

      protected void setEncoding(String encoding)
      Set the encoding in the xml
      Parameters:
      encoding - new encoding
    • getEncoding

      protected String getEncoding()
      Get the current encoding in the xml
      Returns:
      the current encoding
    • setDocType

      protected void setDocType(String docType)
      Set the docType in the xml
      Parameters:
      docType - new docType
    • getDocType

      protected String getDocType()
      Get the docType in the xml
      Returns:
      the current docType
    • getElementStack

      protected LinkedList<String> getElementStack()
      Returns:
      the current elementStack;