org.opencyc.xml
Class XMLWriter

java.lang.Object
  |
  +--org.opencyc.xml.XMLWriter
Direct Known Subclasses:
XMLFileWriter, XMLPrintWriter, XMLStringWriter

public abstract class XMLWriter
extends java.lang.Object

Implements an XMLWriter with facilities for surrounding data elements with tags appropriately named and indented.

Author:
Stefano Bertolo

Copyright 2001 Cycorp, Inc., license is open source GNU LGPL.

the license

www.opencyc.org

OpenCyc at SourceForge

THIS SOFTWARE AND KNOWLEDGE BASE CONTENT ARE PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENCYC ORGANIZATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND KNOWLEDGE BASE CONTENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Constructor Summary
XMLWriter()
           
 
Method Summary
abstract  void close()
          Closes the XMLWriter.
abstract  void flush()
          Flushes the XMLWriter.
 int getIndentLength()
          Returns the length of the current value of @see #indentString.
abstract  void indentPrint(java.lang.String string, int indent, boolean relative)
          Prints a string to this XMLWriter indenting it by the number of spaces indicated by @see #indent either relative to the current indentation level (if @see #relative is true) or with respect to the beginning of the line (if @see #relative is false).
 void indentPrintln(java.lang.String string, int indent, boolean relative)
          Prints a string and terminates the line.
 void indentPrintSafe(java.lang.String string, int indent, boolean relative)
          Prints a string to this XMLWriter after replacing all the reserved XML characters with the appropriate XML entity references indenting it by the number of spaces indicated by @see #indent either relative to the current indentation level (if @see #relative is true) or with respect to the beginning of the line (if @see #relative is false).
 void indentPrintSafeln(java.lang.String string, int indent, boolean relative)
          Prints a string after replacing all the reserved XML characters with the appropriate XML entity references and terminates the line.
static java.lang.String introduceXMLEntities(java.lang.String inputString)
          Replaces all occurences of reserved characters <, &, >, ", ' with the predefined XML entities <, &, >, ", '
abstract  void print(java.lang.String string)
          Prints @see #string to this XMLWriter.
 void printSafe(java.lang.String string)
          Prints @see #string to this XMLWriter after performing all the appropriate substitutions of XML reserved characters.
 void printXMLAtomicTag(java.lang.String tag, int indent, boolean relative)
          Prints to this XMLWriter an atomic XML tag with no attributes.
 void printXMLAtomicTag(java.lang.String tag, java.util.ListIterator attributesIterator, int indent, boolean relative)
          Prints to this XMLWriter an atomic XML tag with attributes.
 void printXMLAtomicTag(java.lang.String tag, java.lang.String attributeName, java.lang.String attributeValue, int indent, boolean relative, boolean newline)
          Prints to this XMLWriter an atomic XML tag with a single attribute.
 void printXMLEndTag(java.lang.String tag)
          Prints to this XMLWriter an XML end tag.
 void printXMLEndTag(java.lang.String tag, int indent, boolean relative)
          Prints to this XMLWriter an XML end tag.
 void printXMLStartTag(java.lang.String tag, int indent, boolean relative)
           
 void printXMLStartTag(java.lang.String tag, int indent, boolean relative, boolean newline)
          Prints to this XMLWriter an XML start tag with no attributes.
 void printXMLStartTag(java.lang.String tag, java.util.ListIterator attributesIterator, int indent, boolean relative, boolean newline)
          Prints to this XMLWriter an XML start tag with attributes.
 void printXMLStartTag(java.lang.String tag, java.lang.String attributeName, java.lang.String attributeValue, int indent, boolean relative, boolean newline)
          Prints to this XMLWriter an XML start tag with a single attribute.
 void resetIndent()
          Resets the indentationof the XMLWriter to its default value.
 void setIndent(int indent, boolean relative)
          Sets the length of the indentation of the XMLFileWriter object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLWriter

public XMLWriter()
Method Detail

introduceXMLEntities

public static java.lang.String introduceXMLEntities(java.lang.String inputString)
Replaces all occurences of reserved characters <, &, >, ", ' with the predefined XML entities <, &, >, ", '
Parameters:
inputString - a string to be checked for the occurrence of reserved characters.
Returns:
a new string with all the reserved characters replaced by the appropriate XML Entities.

setIndent

public void setIndent(int indent,
                      boolean relative)
               throws java.lang.RuntimeException
Sets the length of the indentation of the XMLFileWriter object. If relative = false the indentation will be a string consisting of the number of spaces specified by the `indent' parameter. If relative = true then the current indentation is augmented or decreased by the number of spaces specified by the `indent' parameter.
Parameters:
indent - the number of spaces that constitute the indentation.
relative - determines whether indentation should be relative to the current level of indentation -- relative = true -- or else absolute -- relative = false.

resetIndent

public void resetIndent()
Resets the indentationof the XMLWriter to its default value.

getIndentLength

public int getIndentLength()
Returns the length of the current value of @see #indentString.

flush

public abstract void flush()
                    throws java.io.IOException
Flushes the XMLWriter.

close

public abstract void close()
                    throws java.io.IOException
Closes the XMLWriter.

print

public abstract void print(java.lang.String string)
                    throws java.io.IOException
Prints @see #string to this XMLWriter.
Parameters:
string - the string to be printed.
Throws:
java.io.IOException - if the XMLWriter cannot print to the file specified.

printSafe

public void printSafe(java.lang.String string)
               throws java.io.IOException
Prints @see #string to this XMLWriter after performing all the appropriate substitutions of XML reserved characters.
Parameters:
string - the string to be printed.
Throws:
java.io.IOException - if the XMLWriter cannot print to the file specified.

indentPrint

public abstract void indentPrint(java.lang.String string,
                                 int indent,
                                 boolean relative)
                          throws java.io.IOException
Prints a string to this XMLWriter indenting it by the number of spaces indicated by @see #indent either relative to the current indentation level (if @see #relative is true) or with respect to the beginning of the line (if @see #relative is false).
Parameters:
string - the string to be printed.
indent - the number of spaces by which the string needs to be indented.
relative - id true the string is further indented with respect to the current indentation level, if false is indented with respect to the beginning of the line.

indentPrintSafe

public void indentPrintSafe(java.lang.String string,
                            int indent,
                            boolean relative)
                     throws java.io.IOException
Prints a string to this XMLWriter after replacing all the reserved XML characters with the appropriate XML entity references indenting it by the number of spaces indicated by @see #indent either relative to the current indentation level (if @see #relative is true) or with respect to the beginning of the line (if @see #relative is false).
Parameters:
string - the string to be printed.
indent - the number of spaces by which the string needs to be indented.
relative - id true the string is further indented with respect to the current indentation level, if false is indented with respect to the beginning of the line.

indentPrintln

public void indentPrintln(java.lang.String string,
                          int indent,
                          boolean relative)
                   throws java.io.IOException
Prints a string and terminates the line. The string is printed to this XMLWriter and indented by the number of spaces indicated by @see #indent either relative to the current indentation level (if @see #relative is true) or with respect to the beginning of the line (if @see #relative is false).
Parameters:
string - the string to be printed.
indent - the number of spaces by which the string needs to be indented.
relative - id true the string is further indented with respect to the current indentation level, if false is indented with respect to the beginning of the line.

indentPrintSafeln

public void indentPrintSafeln(java.lang.String string,
                              int indent,
                              boolean relative)
                       throws java.io.IOException
Prints a string after replacing all the reserved XML characters with the appropriate XML entity references and terminates the line. The string is printed to this XMLWriter and indented by the number of spaces indicated by @see #indent either relative to the current indentation level (if @see #relative is true) or with respect to the beginning of the line (if @see #relative is false).
Parameters:
string - the string to be printed.
indent - the number of spaces by which the string needs to be indented.
relative - id true the string is further indented with respect to the current indentation level, if false is indented with respect to the beginning of the line.

printXMLAtomicTag

public void printXMLAtomicTag(java.lang.String tag,
                              int indent,
                              boolean relative)
                       throws java.io.IOException
Prints to this XMLWriter an atomic XML tag with no attributes. The tag is indented by @see #indent spaces either from the beginning of the line (if @see #relative is false) or relative to the current indentation level(if @see #relative is true).
Parameters:
tag - the name of the XML tag.
indent - the number of spaces by which the tag needs to be indented.
relative - specifies whether the indentation is from the beginning of the line (if @see #relative is false) or from the current level of indentation (if @see #relative is true).

printXMLAtomicTag

public void printXMLAtomicTag(java.lang.String tag,
                              java.util.ListIterator attributesIterator,
                              int indent,
                              boolean relative)
                       throws java.io.IOException
Prints to this XMLWriter an atomic XML tag with attributes. The tag is indented by @see #indent spaces either from the beginning of the line (if @see #relative is false) or relative to the current indentation level(if @see #relative is true).
Parameters:
tag - the name of the XML tag.
attributesIterator - an iterator over a list of attribute/value Pairs.
indent - the number of spaces by which the tag needs to be indented.
relative - specifies whether the indentation is from the beginning of the line (if @see #relative is false) or from the current level of indentation (if @see #relative is true).

printXMLStartTag

public void printXMLStartTag(java.lang.String tag,
                             int indent,
                             boolean relative)
                      throws java.io.IOException

printXMLAtomicTag

public void printXMLAtomicTag(java.lang.String tag,
                              java.lang.String attributeName,
                              java.lang.String attributeValue,
                              int indent,
                              boolean relative,
                              boolean newline)
                       throws java.io.IOException
Prints to this XMLWriter an atomic XML tag with a single attribute. The tag is indented by @see #indent spaces either from the beginning of the line (if @see #relative is false) or relative to the current indentation level(if @see #relative is true).
Parameters:
tag - the name of the XML tag.
attributeName - the name of the attribute.
attributeValue - the value of the attribute.
indent - the number of spaces by which the tag needs to be indented.
relative - specifies whether the indentation is from the beginning of the line (if @see #relative is false) or from the current level of indentation (if @see #relative is true).
newline - specifies whether the line should be terminated after the tag has been printed

printXMLStartTag

public void printXMLStartTag(java.lang.String tag,
                             int indent,
                             boolean relative,
                             boolean newline)
                      throws java.io.IOException
Prints to this XMLWriter an XML start tag with no attributes. The tag is indented by @see #indent spaces either from the beginning of the line (if @see #relative is false) or relative to the current indentation level(if @see #relative is true).
Parameters:
tag - the name of the XML tag.
indent - the number of spaces by which the tag needs to be indented.
relative - specifies whether the indentation is from the beginning of the line (if @see #relative is false) or from the current level of indentation (if @see #relative is true).
newline - specifies whether the line should be terminated after the tag has been printed

printXMLStartTag

public void printXMLStartTag(java.lang.String tag,
                             java.util.ListIterator attributesIterator,
                             int indent,
                             boolean relative,
                             boolean newline)
                      throws java.io.IOException
Prints to this XMLWriter an XML start tag with attributes. The tag is indented by @see #indent spaces either from the beginning of the line (if @see #relative is false) or relative to the current indentation level(if @see #relative is true).
Parameters:
tag - the name of the XML tag.
attributesIterator - an iterator over a list of attribute/value
indent - the number of spaces by which the tag needs to be indented.
relative - specifies whether the indentation is from the beginning of the line (if @see #relative is false) or from the current level of indentation (if @see #relative is true).
newline - specifies whether the line should be terminated after the tag has been printed

printXMLStartTag

public void printXMLStartTag(java.lang.String tag,
                             java.lang.String attributeName,
                             java.lang.String attributeValue,
                             int indent,
                             boolean relative,
                             boolean newline)
                      throws java.io.IOException
Prints to this XMLWriter an XML start tag with a single attribute. The tag is indented by @see #indent spaces either from the beginning of the line (if @see #relative is false) or relative to the current indentation level(if @see #relative is true).
Parameters:
tag - the name of the XML tag.
attributesName - the name of the attribute.
attributesValue - the value of the attribute.
indent - the number of spaces by which the tag needs to be indented.
relative - specifies whether the indentation is from the beginning of the line (if @see #relative is false) or from the current level of indentation (if @see #relative is true).
newline - specifies whether the line should be terminated after the tag has been printed

printXMLEndTag

public void printXMLEndTag(java.lang.String tag,
                           int indent,
                           boolean relative)
                    throws java.io.IOException
Prints to this XMLWriter an XML end tag. The tag is indented by @see #indent spaces either from the beginning of the line (if @see #relative is false) or relative to the current indentation level(if @see #relative is true).
Parameters:
tag - the name of the XML tag.
indent - the number of spaces by which the tag needs to be indented.
relative - specifies whether the indentation is from the beginning of the line (if @see #relative is false) or from the current level of indentation (if @see #relative is true).

printXMLEndTag

public void printXMLEndTag(java.lang.String tag)
                    throws java.io.IOException
Prints to this XMLWriter an XML end tag.
Parameters:
tag - the name of the XML tag.