org.graphdrawing.graphml.writer
Class DomXmlWriter

java.lang.Object
  extended byorg.graphdrawing.graphml.writer.DomXmlWriter
All Implemented Interfaces:
XmlWriter

public class DomXmlWriter
extends Object
implements XmlWriter

Implementation of interface XmlWriter that used a DOM tree internally to build the serialized graphml representation.


Constructor Summary
DomXmlWriter(OutputStream ostr)
          Create a new instance that writes the content to the specified stream
DomXmlWriter(Result result)
          Create a new instance that writes the content to the specified Result instance
DomXmlWriter(Writer w)
          Create a new instance that writes the content to the specified Writer instance
 
Method Summary
 void addNamespace(String URI, String prefix)
          Add a namespace declaration to the root element of the output.
protected  void configureTransformer(Transformer transformer)
           
protected  Transformer createTransformer()
           
 void setDTD(String sysId)
          Add a DTD system ID to the root element.
 void setDTD(String sysId, String publicId)
          Add a DTD system ID and a DTD public ID to the root element.
 void setEncoding(String encoding)
          Set the document's encoding Calling this method after writeStartDocument(String, String, String) has undefined results.
 void setWriteXmlDeclaration(boolean writeDecl)
          Set if the XML declaration at the beginning of the document should be written.
 XmlWriter writeAttribute(String localName, boolean value)
          Overload of writeAttribute(String, String) for integer values
 XmlWriter writeAttribute(String localName, double value)
          Overload of writeAttribute(String, String) for double values
 XmlWriter writeAttribute(String localName, long value)
          Overload of writeAttribute(String, String) for integer values
 XmlWriter writeAttribute(String localName, String value)
          Write a Xml attribute node.
 XmlWriter writeAttribute(String prefix, String localName, String ns, String value)
          Write a Xml attribute node.
 XmlWriter writeCDATA(String s)
          Write a CDATA section.
 XmlWriter writeComment(String comment)
          Write a Xml comment node
 XmlWriter writeDocumentFragment(DocumentFragment frag)
          Write a document fragment.
 XmlWriter writeEndDocument()
          Close the output.
 XmlWriter writeEndElement()
          Close a XML element previously opened with writeStartElement(String,String) or writeStartElement(String,String,String).
 XmlWriter writeProcessingInstruction(String target, String pi)
          Write a processing instruction
 XmlWriter writeRaw(String s)
          Write a raw content to the result.
 XmlWriter writeStartDocument(String prefix, String docTag, String nsURI)
          Begin the output process
 XmlWriter writeStartElement(String localName, String ns)
          Begin a new XmlElement with given parameters.
 XmlWriter writeStartElement(String prefix, String localName, String nsURI)
          Begin a new Xml element with given parameters.
 XmlWriter writeText(String s)
          Write a text node.
 void writeToResult()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomXmlWriter

public DomXmlWriter(OutputStream ostr)
Create a new instance that writes the content to the specified stream

Parameters:
ostr - the stream target of the writer

DomXmlWriter

public DomXmlWriter(Writer w)
Create a new instance that writes the content to the specified Writer instance

Parameters:
w - the Writer target of this instance

DomXmlWriter

public DomXmlWriter(Result result)
Create a new instance that writes the content to the specified Result instance

Parameters:
result - the Result target of this instance
Method Detail

addNamespace

public void addNamespace(String URI,
                         String prefix)
Description copied from interface: XmlWriter
Add a namespace declaration to the root element of the output. Calling this method after XmlWriter.writeStartDocument(String, String, String) has undefined results

Specified by:
addNamespace in interface XmlWriter
Parameters:
URI - the namespace URI of the declaration
prefix - the namespace prefix of the declaration

setDTD

public void setDTD(String sysId)
Description copied from interface: XmlWriter
Add a DTD system ID to the root element. If this is set to null, no DTD reference will be inserted, otherwise, a declaration will be inserted Calling this method after XmlWriter.writeStartDocument(String, String, String) has undefined results.

Specified by:
setDTD in interface XmlWriter
Parameters:
sysId - the SYSTEM ID of the DTD

setDTD

public void setDTD(String sysId,
                   String publicId)
Description copied from interface: XmlWriter
Add a DTD system ID and a DTD public ID to the root element. If sysId is set to null, no DTD reference will be inserted. If sysId != null and publicId == null, only a system declaration will be inserted. Otherwise, both declarations will be inserted. Calling this method after XmlWriter.writeStartDocument(String, String, String) has undefined results.

Specified by:
setDTD in interface XmlWriter
Parameters:
sysId - the SYSTEM ID of the DTD
publicId - the PUBLIC ID of the DTD

setEncoding

public void setEncoding(String encoding)
Description copied from interface: XmlWriter
Set the document's encoding Calling this method after XmlWriter.writeStartDocument(String, String, String) has undefined results.

Specified by:
setEncoding in interface XmlWriter
Parameters:
encoding - A valid encoding scpecification

setWriteXmlDeclaration

public void setWriteXmlDeclaration(boolean writeDecl)
Description copied from interface: XmlWriter
Set if the XML declaration at the beginning of the document should be written.

Specified by:
setWriteXmlDeclaration in interface XmlWriter
Parameters:
writeDecl -

writeComment

public XmlWriter writeComment(String comment)
Description copied from interface: XmlWriter
Write a Xml comment node

Specified by:
writeComment in interface XmlWriter
Parameters:
comment - The content of the comment
Returns:
the writer instance, to allow for output chaining

writeProcessingInstruction

public XmlWriter writeProcessingInstruction(String target,
                                            String pi)
Description copied from interface: XmlWriter
Write a processing instruction

Specified by:
writeProcessingInstruction in interface XmlWriter
Parameters:
target - the target of the processing instruction
pi - the instruction itself
Returns:
the writer instance, to allow for output chaining

writeStartDocument

public XmlWriter writeStartDocument(String prefix,
                                    String docTag,
                                    String nsURI)
                             throws GraphMLWriteException
Description copied from interface: XmlWriter
Begin the output process

Specified by:
writeStartDocument in interface XmlWriter
Returns:
the writer instance, to allow for output chaining
Throws:
GraphMLWriteException

writeEndDocument

public XmlWriter writeEndDocument()
                           throws GraphMLWriteException
Description copied from interface: XmlWriter
Close the output.

Attemps to write to the same document after this method has been called will have undefined results.

Specified by:
writeEndDocument in interface XmlWriter
Returns:
the writer instance, to allow for output chaining
Throws:
GraphMLWriteException

writeToResult

public void writeToResult()
                   throws GraphMLWriteException
Throws:
GraphMLWriteException

configureTransformer

protected void configureTransformer(Transformer transformer)

createTransformer

protected Transformer createTransformer()
                                 throws GraphMLWriteException
Throws:
GraphMLWriteException

writeStartElement

public XmlWriter writeStartElement(String prefix,
                                   String localName,
                                   String nsURI)
Description copied from interface: XmlWriter
Begin a new Xml element with given parameters.

All subsequent output is attched to this element until XmlWriter.writeEndElement() has been called or a new element has been started.

Specified by:
writeStartElement in interface XmlWriter
Parameters:
prefix - The namespace prefix to use for this element
localName - The local name of this element
nsURI - The namespace URI of this element
Returns:
the writer instance, to allow for output chaining

writeStartElement

public XmlWriter writeStartElement(String localName,
                                   String ns)
Description copied from interface: XmlWriter
Begin a new XmlElement with given parameters.

All subsequent output is attched to this element until XmlWriter.writeEndElement() has been called or a new element has been started.
This acts like XmlWriter.writeStartElement(String,String,String), but uses the default prefix for the namespace.

Specified by:
writeStartElement in interface XmlWriter
Parameters:
localName - The local name of this element.
ns - The namespace URI of this element
Returns:
the writer instance, to allow for output chaining

writeEndElement

public XmlWriter writeEndElement()
Description copied from interface: XmlWriter
Close a XML element previously opened with XmlWriter.writeStartElement(String,String) or XmlWriter.writeStartElement(String,String,String).

Specified by:
writeEndElement in interface XmlWriter
Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String prefix,
                                String localName,
                                String ns,
                                String value)
Description copied from interface: XmlWriter
Write a Xml attribute node.

The attribute is attached to the closest open Xml element that has been started with XmlWriter.writeStartElement(String,String) or XmlWriter.writeStartElement(String,String,String)

Specified by:
writeAttribute in interface XmlWriter
Parameters:
prefix - The namespace prefix of the attribute
localName - The local name of the attribute
ns - The namespace URI of this attribute
value - The value of this attribute
Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String localName,
                                String value)
Description copied from interface: XmlWriter
Write a Xml attribute node.

The attribute is attached to the closest open Xml element that has been started with XmlWriter.writeStartElement(String,String) or XmlWriter.writeStartElement(String,String,String)
This method acts like XmlWriter.writeAttribute(String,String,String,String), but does not use namespaces or prefixes.

Specified by:
writeAttribute in interface XmlWriter
Parameters:
localName - The local name of the attribute
value - The value of this attribute
Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String localName,
                                double value)
Description copied from interface: XmlWriter
Overload of XmlWriter.writeAttribute(String, String) for double values

Specified by:
writeAttribute in interface XmlWriter
Parameters:
localName - the local name of the attribute
value -
Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String localName,
                                long value)
Description copied from interface: XmlWriter
Overload of XmlWriter.writeAttribute(String, String) for integer values

Specified by:
writeAttribute in interface XmlWriter
Parameters:
localName - the local name of the attribute
value -
Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String localName,
                                boolean value)
Description copied from interface: XmlWriter
Overload of XmlWriter.writeAttribute(String, String) for integer values

Specified by:
writeAttribute in interface XmlWriter
Parameters:
localName - the local name of the attribute
value -
Returns:
the writer instance, to allow for output chaining

writeText

public XmlWriter writeText(String s)
Description copied from interface: XmlWriter
Write a text node.

Specified by:
writeText in interface XmlWriter
Parameters:
s - The content of the text node
Returns:
the writer instance, to allow for output chaining

writeCDATA

public XmlWriter writeCDATA(String s)
Description copied from interface: XmlWriter
Write a CDATA section. Note: it is not possible to nest CDATA sections

Specified by:
writeCDATA in interface XmlWriter
Parameters:
s - The content of the text node
Returns:
the writer instance, to allow for output chaining

writeRaw

public XmlWriter writeRaw(String s)
                   throws GraphMLWriteException
Description copied from interface: XmlWriter
Write a raw content to the result. No output escaping will occur, however, an implementation is free to change the actual value written to the document as long as it is semantically equivalent. The content must be wellformed XML content

Specified by:
writeRaw in interface XmlWriter
Parameters:
s - raw XML content
Returns:
the writer instance, to allow for output chaining
Throws:
GraphMLWriteException - if s does not represent wellformed XML content.

writeDocumentFragment

public XmlWriter writeDocumentFragment(DocumentFragment frag)
Description copied from interface: XmlWriter
Write a document fragment.

Specified by:
writeDocumentFragment in interface XmlWriter
Parameters:
frag - the document fragment
Returns:
the writer instance, to allow for output chaining


Copyright ©2000-2008, yWorks GmbH. All rights reserved.