Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes

de.mfuchs.xmlstorage.stream.XMLStreamWriter Class Reference

XMLStreamWriter is used to write XML streams in XMLStorage. More...

Collaboration diagram for de.mfuchs.xmlstorage.stream.XMLStreamWriter:
Collaboration graph
[legend]

List of all members.

Classes

class  StackEntry
 StackEntry is used to hold state information when moving between nodes. More...

Public Member Functions

 XMLStreamWriter (Writer out) throws IOException
 XMLStreamWriter (final String path) throws IOException
 XMLStreamWriter (Writer out, int pretty, final XMLHeader header) throws IOException
 XMLStreamWriter (final String path, int pretty, final XMLHeader header) throws IOException
void close () throws IOException
void create (final String name) throws IOException
 create node and move to it
boolean back () throws IOException
 go back to previous position
void put (String attrName, Object value)
 attribute setting
void put (String attrName, String value)
 attribute setting
void setContent (final String s)
void setContent (final String s, boolean cdata)

Static Public Attributes

static final int PRETTY_PLAIN = 0
static final int PRETTY_LINEFEED = 1
static final int PRETTY_INDENT = 2

Protected Member Functions

void closePre (StackEntry entry) throws IOException
void writePre (StackEntry entry) throws IOException
void writeAttributes (StackEntry entry) throws IOException
void writePost (StackEntry entry) throws IOException

Protected Attributes

Writer _out
int _pretty
Stack< StackEntry_stack = new Stack<StackEntry>()

Static Protected Attributes

static final int NOTHING = 0
static final int ATTRIBUTES = 2
static final int PRE_CLOSED = 3
static final int POST = 5

Detailed Description

XMLStreamWriter is used to write XML streams in XMLStorage.

Definition at line 56 of file XMLStreamWriter.java.


Constructor & Destructor Documentation

de.mfuchs.xmlstorage.stream.XMLStreamWriter.XMLStreamWriter ( Writer  out ) throws IOException

Definition at line 64 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter.PRETTY_INDENT.

    {
        this(out, PRETTY_INDENT, new XMLHeader());
    }
de.mfuchs.xmlstorage.stream.XMLStreamWriter.XMLStreamWriter ( final String  path ) throws IOException

Definition at line 69 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter.PRETTY_INDENT.

    {
        this(path, PRETTY_INDENT, new XMLHeader());
    }
de.mfuchs.xmlstorage.stream.XMLStreamWriter.XMLStreamWriter ( Writer  out,
int  pretty,
final XMLHeader  header 
) throws IOException

Definition at line 74 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter._out, and de.mfuchs.xmlstorage.stream.XMLStreamWriter._pretty.

    {
        _out = out;
        _pretty = pretty;

        header.print(_out, false);
    }
de.mfuchs.xmlstorage.stream.XMLStreamWriter.XMLStreamWriter ( final String  path,
int  pretty,
final XMLHeader  header 
) throws IOException

Definition at line 82 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter._out, and de.mfuchs.xmlstorage.stream.XMLStreamWriter._pretty.

    {
         _out = new BufferedWriter(new FileWriter(path));
         _pretty = pretty;

        header.print(_out, false);
    }

Member Function Documentation

boolean de.mfuchs.xmlstorage.stream.XMLStreamWriter.back (  ) throws IOException

go back to previous position

Definition at line 117 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter._stack, and de.mfuchs.xmlstorage.stream.XMLStreamWriter.writePost().

Referenced by de.mfuchs.XMLTest.testStreamingWriter(), and de.mfuchs.WriterTest.testWriter().

    {
        if (!_stack.empty()) {
            writePost((StackEntry)_stack.peek());

            _stack.pop();

            return true;
        } else
            return false;
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.stream.XMLStreamWriter.close (  ) throws IOException
void de.mfuchs.xmlstorage.stream.XMLStreamWriter.closePre ( StackEntry  entry ) throws IOException [protected]
void de.mfuchs.xmlstorage.stream.XMLStreamWriter.create ( final String  name ) throws IOException
void de.mfuchs.xmlstorage.stream.XMLStreamWriter.put ( String  attrName,
Object  value 
)

attribute setting

Definition at line 130 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter._stack, and de.mfuchs.xmlstorage.XMLNode.put().

Referenced by de.mfuchs.XMLTest.testStreamingWriter(), and de.mfuchs.WriterTest.testWriter().

    {
        if (!_stack.empty()) {
            XMLNode.AttributeMap attributes = ((StackEntry)_stack.peek())._attributes;

            if (value != null)
                attributes.put(attrName, value.toString());
            else
                attributes.remove(attrName);
        }
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.stream.XMLStreamWriter.put ( String  attrName,
String  value 
)

attribute setting

Definition at line 143 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter._stack, and de.mfuchs.xmlstorage.XMLNode.put().

    {
        if (!_stack.empty()) {
            XMLNode.AttributeMap attributes = ((StackEntry)_stack.peek())._attributes;

            if (value != null)
                attributes.put(attrName, value);
            else
                attributes.remove(attrName);
        }
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.stream.XMLStreamWriter.setContent ( final String  s,
boolean  cdata 
)

Definition at line 160 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter._stack, and de.mfuchs.xmlstorage.XMLHelper.encodeXMLString().

    {
        if (!_stack.empty())
            ((StackEntry)_stack.peek())._content = s!=null? XMLHelper.encodeXMLString(s, cdata): "";
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.stream.XMLStreamWriter.setContent ( final String  s )
void de.mfuchs.xmlstorage.stream.XMLStreamWriter.writeAttributes ( StackEntry  entry ) throws IOException [protected]

Definition at line 219 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter._out, de.mfuchs.xmlstorage.stream.XMLStreamWriter.ATTRIBUTES, and de.mfuchs.xmlstorage.XMLHelper.encodeXMLString().

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamWriter.create(), and de.mfuchs.xmlstorage.stream.XMLStreamWriter.writePost().

    {
        for(Map.Entry<String,String> it: entry._attributes.entrySet())
            _out.write(" " + XMLHelper.encodeXMLString(it.getKey()) +
                       "=\"" + XMLHelper.encodeXMLString(it.getValue()) + "\"");

        entry._state = ATTRIBUTES;
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.stream.XMLStreamWriter.writePost ( StackEntry  entry ) throws IOException [protected]

Definition at line 228 of file XMLStreamWriter.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter._out, de.mfuchs.xmlstorage.stream.XMLStreamWriter._pretty, de.mfuchs.xmlstorage.stream.XMLStreamWriter._stack, de.mfuchs.xmlstorage.stream.XMLStreamWriter.ATTRIBUTES, de.mfuchs.xmlstorage.stream.XMLStreamWriter.closePre(), de.mfuchs.xmlstorage.XMLHelper.encodeXMLString(), de.mfuchs.xmlstorage.stream.XMLStreamWriter.POST, de.mfuchs.xmlstorage.stream.XMLStreamWriter.PRE_CLOSED, de.mfuchs.xmlstorage.stream.XMLStreamWriter.PRETTY_INDENT, de.mfuchs.xmlstorage.stream.XMLStreamWriter.PRETTY_LINEFEED, de.mfuchs.xmlstorage.stream.XMLStreamWriter.writeAttributes(), and de.mfuchs.xmlstorage.XMLNode.XML_INDENT_SPACE.

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamWriter.back().

    {
        if (entry._state < ATTRIBUTES)
            writeAttributes(entry);

        if (entry._children || entry._content.length()>0) {
            if (entry._state < PRE_CLOSED)
                closePre(entry);

            _out.write(entry._content);
            //entry._state = CONTENT;

            if (_pretty>=PRETTY_LINEFEED && entry._content.length()==0)
                _out.write('\n');

            if (_pretty==PRETTY_INDENT && entry._content.length()==0)
                for(int i=_stack.size(); --i>0; )
                    _out.write(XMLNode.XML_INDENT_SPACE);

            _out.write("</" + XMLHelper.encodeXMLString(entry._nodeName) + ">");
        } else {
            _out.write("/>");
        }

        entry._state = POST;
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.stream.XMLStreamWriter.writePre ( StackEntry  entry ) throws IOException [protected]

Member Data Documentation

final int de.mfuchs.xmlstorage.stream.XMLStreamWriter.ATTRIBUTES = 2 [static, protected]
final int de.mfuchs.xmlstorage.stream.XMLStreamWriter.NOTHING = 0 [static, protected]
final int de.mfuchs.xmlstorage.stream.XMLStreamWriter.POST = 5 [static, protected]
final int de.mfuchs.xmlstorage.stream.XMLStreamWriter.PRE_CLOSED = 3 [static, protected]

Definition at line 59 of file XMLStreamWriter.java.


The documentation for this class was generated from the following file: