org.freehep.xml.util
Class XMLWriter

java.lang.Object
  extended by org.freehep.xml.util.XMLWriter
All Implemented Interfaces:
XMLTagWriter
Direct Known Subclasses:
XHTMLWriter

public class XMLWriter
extends Object
implements XMLTagWriter

A class that makes it easy to write XML documents.

Version:
$Id: XMLWriter.java 10527 2007-02-13 17:49:08Z duns $
Author:
Tony Johnson, Mark Donszelmann

Field Summary
protected  boolean closed
           
protected  String defaultNameSpace
           
protected  org.freehep.util.io.IndentPrintWriter writer
           
 
Constructor Summary
XMLWriter(Writer w)
           
XMLWriter(Writer w, String indentString)
           
XMLWriter(Writer w, String indentString, String defaultNameSpace)
           
 
Method Summary
protected  void checkNameValid(String s)
           
 void close()
          closes the writer
 void closeDoc()
          Closes the document, and checks if you closed all the tags
 void closeTag()
          Closes the current XML tag and decreases the indentation level
static String normalize(String s)
          Normalizes the given string for an Attribute value
static String normalizeText(String s)
          Normalizes the given string for Text
 void openDoc()
          Opens the document with an xml header
 void openDoc(String version, String encoding, boolean standalone)
          Opens the document with an xml header
 void openTag(String name)
          Prints a new XML tag and increases the identation level
 void openTag(String namespace, String name)
          Prints a new XML tag and increases the identation level
 void print(Node node)
          Prints a DOM node, recursively.
 void print(String text)
          Prints character data, while escaping < and >
protected  void printAttributes(int tagLength)
           
 void printComment(String comment)
          Print a comment
 void println(String text)
          Prints character data, while escaping < and >
 void printTag(String name)
          Prints an empty XML tag.
 void printTag(String namespace, String name)
          Prints an empty XML tag.
 void referToDTD(String name, String system)
          Writes a reference to a DTD
 void referToDTD(String name, String pid, String ref)
          Writes a reference to a DTD
 void setAttribute(String name, boolean value)
          Set boolean attribute
 void setAttribute(String name, byte value)
          Set byte attribute
 void setAttribute(String name, char value)
          Set char attribute
 void setAttribute(String name, Color value)
          Set Color attribute
 void setAttribute(String name, double value)
          Set double attribute
 void setAttribute(String name, float value)
          Set float attribute
 void setAttribute(String name, int value)
          Set int attribute
 void setAttribute(String name, long value)
          Set long attribute
 void setAttribute(String name, short value)
          Set short attribute
 void setAttribute(String name, String value)
          Sets an attribute which will be included in the next tag printed by openTag or printTag
 void setAttribute(String ns, String name, boolean value)
          Set boolean attribute
 void setAttribute(String ns, String name, byte value)
          Set byte attribute
 void setAttribute(String ns, String name, char value)
          Set char attribute
 void setAttribute(String ns, String name, Color value)
          Set Color attribute
 void setAttribute(String ns, String name, double value)
          Set double attribute
 void setAttribute(String ns, String name, float value)
          Set float attribute
 void setAttribute(String ns, String name, int value)
          Set int attribute
 void setAttribute(String ns, String name, long value)
          Set long attribute
 void setAttribute(String ns, String name, short value)
          Set short attribute
 void setAttribute(String namespace, String name, String value)
          Set String attribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

closed

protected boolean closed

writer

protected org.freehep.util.io.IndentPrintWriter writer

defaultNameSpace

protected String defaultNameSpace
Constructor Detail

XMLWriter

public XMLWriter(Writer w,
                 String indentString,
                 String defaultNameSpace)

XMLWriter

public XMLWriter(Writer w,
                 String indentString)

XMLWriter

public XMLWriter(Writer w)
Method Detail

close

public void close()
           throws IOException
closes the writer

Specified by:
close in interface XMLTagWriter
Throws:
IOException - if stream cannot be written

openDoc

public void openDoc()
Opens the document with an xml header

Specified by:
openDoc in interface XMLTagWriter

openDoc

public void openDoc(String version,
                    String encoding,
                    boolean standalone)
Opens the document with an xml header

Specified by:
openDoc in interface XMLTagWriter
Parameters:
version - version string
encoding - encoding
standalone - if XML is standalone

referToDTD

public void referToDTD(String name,
                       String pid,
                       String ref)
Writes a reference to a DTD

Specified by:
referToDTD in interface XMLTagWriter

referToDTD

public void referToDTD(String name,
                       String system)
Writes a reference to a DTD

Specified by:
referToDTD in interface XMLTagWriter

closeDoc

public void closeDoc()
Closes the document, and checks if you closed all the tags

Specified by:
closeDoc in interface XMLTagWriter

printComment

public void printComment(String comment)
Print a comment

Specified by:
printComment in interface XMLTagWriter

print

public void print(String text)
Prints character data, while escaping < and >

Specified by:
print in interface XMLTagWriter

println

public void println(String text)
Prints character data, while escaping < and >


openTag

public void openTag(String namespace,
                    String name)
Prints a new XML tag and increases the identation level

Specified by:
openTag in interface XMLTagWriter
Parameters:
namespace - namespace
name - tagname

openTag

public void openTag(String name)
Prints a new XML tag and increases the identation level

Specified by:
openTag in interface XMLTagWriter
Parameters:
name - tagname

closeTag

public void closeTag()
Closes the current XML tag and decreases the indentation level

Specified by:
closeTag in interface XMLTagWriter

printTag

public void printTag(String namespace,
                     String name)
Prints an empty XML tag.

Specified by:
printTag in interface XMLTagWriter
Parameters:
namespace - namespace
name - tagname

printTag

public void printTag(String name)
Prints an empty XML tag.

Specified by:
printTag in interface XMLTagWriter
Parameters:
name - tagname

setAttribute

public void setAttribute(String name,
                         String value)
Sets an attribute which will be included in the next tag printed by openTag or printTag

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String namespace,
                         String name,
                         String value)
Description copied from interface: XMLTagWriter
Set String attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
namespace - namespace
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         byte value)
Description copied from interface: XMLTagWriter
Set byte attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         char value)
Description copied from interface: XMLTagWriter
Set char attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         long value)
Description copied from interface: XMLTagWriter
Set long attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         int value)
Description copied from interface: XMLTagWriter
Set int attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         short value)
Description copied from interface: XMLTagWriter
Set short attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         boolean value)
Description copied from interface: XMLTagWriter
Set boolean attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         float value)
Description copied from interface: XMLTagWriter
Set float attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         double value)
Description copied from interface: XMLTagWriter
Set double attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         Color value)
Description copied from interface: XMLTagWriter
Set Color attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String ns,
                         String name,
                         byte value)
Description copied from interface: XMLTagWriter
Set byte attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
ns - namespace
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String ns,
                         String name,
                         char value)
Description copied from interface: XMLTagWriter
Set char attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
ns - namespace
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String ns,
                         String name,
                         long value)
Description copied from interface: XMLTagWriter
Set long attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
ns - namespace
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String ns,
                         String name,
                         int value)
Description copied from interface: XMLTagWriter
Set int attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
ns - namespace
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String ns,
                         String name,
                         short value)
Description copied from interface: XMLTagWriter
Set short attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
ns - namespace
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String ns,
                         String name,
                         boolean value)
Description copied from interface: XMLTagWriter
Set boolean attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
ns - namespace
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String ns,
                         String name,
                         float value)
Description copied from interface: XMLTagWriter
Set float attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
ns - namespace
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String ns,
                         String name,
                         double value)
Description copied from interface: XMLTagWriter
Set double attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
ns - namespace
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String ns,
                         String name,
                         Color value)
Description copied from interface: XMLTagWriter
Set Color attribute

Specified by:
setAttribute in interface XMLTagWriter
Parameters:
ns - namespace
name - attribute name
value - attribute value

printAttributes

protected void printAttributes(int tagLength)

print

public void print(Node node)
Prints a DOM node, recursively. No support for a document node


normalize

public static String normalize(String s)
Normalizes the given string for an Attribute value


normalizeText

public static String normalizeText(String s)
Normalizes the given string for Text


checkNameValid

protected void checkNameValid(String s)


Copyright © 2000-2007 FreeHEP. All Rights Reserved.