org.rubato.xml
Class XMLWriter

java.lang.Object
  extended by org.rubato.xml.XMLWriter

public class XMLWriter
extends java.lang.Object

A writer for the XML-based Rubato file format.

Author:
Gérard Milmeister

Constructor Summary
XMLWriter(java.io.File file)
          Creates a non-compressing writer to the specified file.
XMLWriter(java.io.File file, boolean compressed)
          Creates a writer to the specified file.
XMLWriter(java.io.PrintStream out)
          Creates a writer to the specified PrintStream with the initial indent 0.
XMLWriter(java.io.PrintStream out, int indent)
          Creates a writer to the specified PrintStream with the given initial indent.
 
Method Summary
 void close()
          Ends the XML file.
 void closeBlock()
          Closes the XML block opened with openBlock.
 void closeInline()
          Closes the XML element opened with openInline.
 void empty(java.lang.String element)
          Creates an empty XML element "<.../>" with the given tag name.
 void empty(java.lang.String element, java.lang.Object... attrs)
          Creates an empty XML element "<.../>" with the given tag name and the given attributes.
 void emptyWithType(java.lang.String element, java.lang.String type, java.lang.Object... attrs)
          Creates an empty XML element "<.../>" with the given tag name and the given attributes.
 void open()
          Starts the XML file.
 void openBlock(java.lang.String element)
          Opens an XML block with the given tag name.
 void openBlock(java.lang.String element, java.lang.Object... attrs)
          Opens an XML block with the given tag name and the specified attributes which are given as alternating name/value pairs.
 void openBlockWithType(java.lang.String element, java.lang.String type, java.lang.Object... attrs)
          Opens an XML block with the given tag name and the specified attributes which are given as alternating name/value pairs.
 void openInline(java.lang.String element)
          Creates an inline XML element with the given tag.
 void openInline(java.lang.String element, java.lang.Object... attrs)
          Creates an inline XML element with the given tag and attributes.
 void setIndentSize(int size)
          Sets the number of spaces for each indent level.
 void text(java.lang.String string)
          Adds the specified text to the XML file, with no conversion done on special characters.
 java.lang.String toRelativePath(java.lang.String path)
          Strips the directory name of the current file from path if possible to make path relative to the current file.
 java.lang.String toXMLText(java.lang.String text)
          Converts the specified string for use with XML.
 void writeDenotator(Denotator denotator)
          Writes the XML representation of the specified denotator.
 void writeDenotatorRef(Denotator d)
          Writes a reference to the specified denotator.
 void writeDenotators(java.util.List<Denotator> denotators)
          Writes the XML representations of the specified list of denotators.
 void writeForm(Form form)
          Writes the XML representation of the specified form.
 void writeFormRef(Form form)
          Writes a reference to the specified form.
 void writeForms(java.util.List<Form> forms)
          Writes the XML representations of the specified list of forms.
 void writeModule(java.lang.String name, Module module)
          Writes the XML representation of the given module under the given name.
 void writeModuleElement(java.lang.String name, ModuleElement moduleElement)
          Writes the XML representation of the given module element under the given name.
 void writeModuleMorphism(java.lang.String name, ModuleMorphism morphism)
          Writes the XML representation of the given module morphism under the given name.
 void writeTextNode(java.lang.String text)
          Adds the specified text to the XML file, with & and < converted to XML entities.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLWriter

public XMLWriter(java.io.File file)
          throws java.io.IOException
Creates a non-compressing writer to the specified file.

Throws:
java.io.IOException

XMLWriter

public XMLWriter(java.io.File file,
                 boolean compressed)
          throws java.io.IOException
Creates a writer to the specified file.

Parameters:
file - the file to save to
compressed - if true the output is compressed with GZIP
Throws:
java.io.IOException - iff the file cannot be opened for writing

XMLWriter

public XMLWriter(java.io.PrintStream out,
                 int indent)
Creates a writer to the specified PrintStream with the given initial indent.


XMLWriter

public XMLWriter(java.io.PrintStream out)
Creates a writer to the specified PrintStream with the initial indent 0.

Method Detail

open

public void open()
Starts the XML file. This must be called before anything else is done.


close

public void close()
Ends the XML file. This must be called at the end.


setIndentSize

public void setIndentSize(int size)
Sets the number of spaces for each indent level.


openBlock

public void openBlock(java.lang.String element)
Opens an XML block with the given tag name.


openBlock

public void openBlock(java.lang.String element,
                      java.lang.Object... attrs)
Opens an XML block with the given tag name and the specified attributes which are given as alternating name/value pairs.


openBlockWithType

public void openBlockWithType(java.lang.String element,
                              java.lang.String type,
                              java.lang.Object... attrs)
Opens an XML block with the given tag name and the specified attributes which are given as alternating name/value pairs. An additional attribute "type" is added with the specified value.


openInline

public void openInline(java.lang.String element)
Creates an inline XML element with the given tag. Inline means, that there is no newline after the start tag and before the end tag.


openInline

public void openInline(java.lang.String element,
                       java.lang.Object... attrs)
Creates an inline XML element with the given tag and attributes.


closeBlock

public void closeBlock()
Closes the XML block opened with openBlock.


closeInline

public void closeInline()
Closes the XML element opened with openInline.


empty

public void empty(java.lang.String element)
Creates an empty XML element "<.../>" with the given tag name.


empty

public void empty(java.lang.String element,
                  java.lang.Object... attrs)
Creates an empty XML element "<.../>" with the given tag name and the given attributes.


emptyWithType

public void emptyWithType(java.lang.String element,
                          java.lang.String type,
                          java.lang.Object... attrs)
Creates an empty XML element "<.../>" with the given tag name and the given attributes. An additional attribute "type" with the given value is added.


writeTextNode

public void writeTextNode(java.lang.String text)
Adds the specified text to the XML file, with & and < converted to XML entities.


toXMLText

public java.lang.String toXMLText(java.lang.String text)
Converts the specified string for use with XML.


text

public void text(java.lang.String string)
Adds the specified text to the XML file, with no conversion done on special characters. This is only to be used, if it is certain that the text does contain & or <.


writeModule

public void writeModule(java.lang.String name,
                        Module module)
Writes the XML representation of the given module under the given name.


writeModuleElement

public void writeModuleElement(java.lang.String name,
                               ModuleElement moduleElement)
Writes the XML representation of the given module element under the given name.


writeModuleMorphism

public void writeModuleMorphism(java.lang.String name,
                                ModuleMorphism morphism)
Writes the XML representation of the given module morphism under the given name.


writeForm

public void writeForm(Form form)
Writes the XML representation of the specified form.


writeFormRef

public void writeFormRef(Form form)
Writes a reference to the specified form.


writeForms

public void writeForms(java.util.List<Form> forms)
Writes the XML representations of the specified list of forms.


writeDenotator

public void writeDenotator(Denotator denotator)
Writes the XML representation of the specified denotator.


writeDenotators

public void writeDenotators(java.util.List<Denotator> denotators)
Writes the XML representations of the specified list of denotators.


writeDenotatorRef

public void writeDenotatorRef(Denotator d)
Writes a reference to the specified denotator.


toRelativePath

public java.lang.String toRelativePath(java.lang.String path)
Strips the directory name of the current file from path if possible to make path relative to the current file.