org.apache.crimson.tree
Class XmlWriteContext

java.lang.Object
  extended byorg.apache.crimson.tree.XmlWriteContext
Direct Known Subclasses:
XmlDocument.ExtWriteContext

public class XmlWriteContext
extends Object

This captures context used when writing XML text, such as state used to "pretty print" output or to identify entities which are defined. Pretty printing is useful when displaying structure in XML documents that need to be read or edited by people (rather than only by machines).

Author:
David Brownell
See Also:
XmlWritable, XmlDocument.createWriteContext(java.io.Writer)

Field Summary
private  int indentLevel
           
private  boolean prettyOutput
           
private  Writer writer
           
 
Constructor Summary
XmlWriteContext(Writer out)
          Constructs a write context that doesn't pretty-print output.
XmlWriteContext(Writer out, int level)
          Constructs a write context that supports pretty-printing output starting at the specified number of spaces.
 
Method Summary
 int getIndentLevel()
          Returns the current indent level, in terms of spaces, for use in pretty printing XML text.
 Writer getWriter()
          Returns the writer to which output should be written.
 boolean isEntityDeclared(String name)
          Returns true if the specified entity was already declared in this output context, so that entity references may be written rather than their expanded values.
 boolean isPrettyOutput()
          Returns true if writes using the context should "pretty print", displaying structure through indentation as appropriate.
 void printIndent()
          If pretty printing is enabled, this writes a newline followed by indentLevel spaces.
 void setIndentLevel(int level)
          Assigns the current indent level, in terms of spaces, for use in pretty printing XML text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writer

private Writer writer

indentLevel

private int indentLevel

prettyOutput

private boolean prettyOutput
Constructor Detail

XmlWriteContext

public XmlWriteContext(Writer out)
Constructs a write context that doesn't pretty-print output.


XmlWriteContext

public XmlWriteContext(Writer out,
                       int level)
Constructs a write context that supports pretty-printing output starting at the specified number of spaces.

Method Detail

getWriter

public Writer getWriter()
Returns the writer to which output should be written.


isEntityDeclared

public boolean isEntityDeclared(String name)
Returns true if the specified entity was already declared in this output context, so that entity references may be written rather than their expanded values. The predefined XML entities are always declared.


getIndentLevel

public int getIndentLevel()
Returns the current indent level, in terms of spaces, for use in pretty printing XML text.


setIndentLevel

public void setIndentLevel(int level)
Assigns the current indent level, in terms of spaces, for use in pretty printing XML text.


printIndent

public void printIndent()
                 throws IOException
If pretty printing is enabled, this writes a newline followed by indentLevel spaces. At the beginning of a line, groups of eight consecutive spaces are replaced by tab characters, for storage efficiency.

Note that this method should not be used except in cases where the additional whitespace is guaranteed to be semantically meaningless. This is the default, and is controlled through the xml:space attribute, inherited from parent elements. When this attribute value is preserve, this method should not be used. Otherwise, text normalization is expected to remove excess whitespace such as that added by this call.

Throws:
IOException

isPrettyOutput

public boolean isPrettyOutput()
Returns true if writes using the context should "pretty print", displaying structure through indentation as appropriate.