Classes | Public Member Functions | Protected Attributes | Package Functions | Package Attributes | Private Member Functions | Private Attributes

de.mfuchs.xmlstorage.stream.XMLStreamReader Class Reference

XMLStreamReader is the streaming XML file reader of XMLStorage. More...

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

List of all members.

Classes

class  XMLStreamIterator
 XMLStreamIterator iterates over the immediate children of the current XML node. More...

Public Member Functions

 XMLStreamReader (String path) throws FileNotFoundException, XMLStreamException
 XMLStreamReader (Source source) throws XMLStreamException
void close () throws XMLStreamException, IOException
XMLStreamNode getNode ()
Object getNodeName ()
boolean isAtNode (String nodeName)
Iterator< XMLStreamNodeiterator ()
String get (final String attrName)
 Return the value of an attribute in the current node or "".
String get (final String attrName, final String def)
 Return the value of an attribute in the current node or a default value.
boolean goDown () throws XMLStreamException
 Go down to first child.
boolean goDown (final String name) throws XMLStreamException
 Search for child and go down.
boolean go (XPath xpath) throws XMLStreamException
 move X-Path like to position in XML tree
boolean back () throws XMLStreamException
 Move back to the next higher nesting level.
String getContent ()
String toString ()
String getInstructions ()
boolean firstChild () throws XMLStreamException
 Move to the first child node.
boolean firstChild (String nodeName) throws XMLStreamException
 Move to the first child node with the specified name.
boolean next () throws XMLStreamException
 Move to the next sibling node independent from its name.
boolean nextSkipOthers (String nodeName) throws XMLStreamException
 Move to the next sibling node with the specified name.
boolean nextStopOnOthers (String nodeName) throws XMLStreamException
 Move to the next sibling node with the specified name.
boolean find (final String nodeName) throws XMLStreamException
 Find a children node by name.
boolean find (final String nodeName, int n) throws XMLStreamException
 Find the n'th children node with tag nodeName.
boolean find (final String nodeName, final String attrName, final String attrValue) throws XMLStreamException
 Search matching child node identified by key name and an attribute value.
boolean find (final String nodeName, final String attrName, final String attrValue, int n) throws XMLStreamException
 Search matching child node identified by key name and an attribute value.

Protected Attributes

javax.xml.stream.XMLStreamReader _reader
XMLStreamNode _node
String _content = ""
StringBuffer _instructions = new StringBuffer()

Package Functions

boolean findRelative (final XPath xpath) throws XMLStreamException
 XPath find function.
boolean find (XPathElement xelem) throws XMLStreamException
 Search matching child node identified by key name and an attribute value.

Package Attributes

int _level = 0

Private Member Functions

void init (Source source) throws XMLStreamException
void startElement (String nodeName)
void endElement (String nodeName)
void characters ()
void processingInstruction ()
boolean findNode (String targetTag, int targetLevel, int minLevel, boolean stopOnOthers) throws XMLStreamException

Private Attributes

InputStream _istream

Detailed Description

XMLStreamReader is the streaming XML file reader of XMLStorage.

XMLStreamReader requires Java 1.6.

Definition at line 64 of file XMLStreamReader.java.


Constructor & Destructor Documentation

de.mfuchs.xmlstorage.stream.XMLStreamReader.XMLStreamReader ( String  path ) throws FileNotFoundException, XMLStreamException

Definition at line 76 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._istream, and de.mfuchs.xmlstorage.stream.XMLStreamReader.init().

    {
        _istream = new FileInputStream(path);

        StreamSource source = new StreamSource(_istream);
        source.setSystemId(path);

        init(source);
    }

Here is the call graph for this function:

de.mfuchs.xmlstorage.stream.XMLStreamReader.XMLStreamReader ( Source  source ) throws XMLStreamException

Definition at line 86 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader.init().

    {
        init(source);
    }

Here is the call graph for this function:


Member Function Documentation

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.back (  ) throws XMLStreamException

Move back to the next higher nesting level.

Remark: This implementation does _not_ jump more than one level up like XMLPos.node() when using go() to move down more than one level at a time.

Returns:
true if successfull
Exceptions:
XMLStreamException

Definition at line 246 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._level, and de.mfuchs.xmlstorage.stream.XMLStreamReader.findNode().

Referenced by de.mfuchs.XMLTest.testStreamingReader1(), and de.mfuchs.XMLTest.testStreamingReader2().

    {
        return findNode(null, -1, _level+1, false);
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.stream.XMLStreamReader.characters (  ) [private]
void de.mfuchs.xmlstorage.stream.XMLStreamReader.close (  ) throws XMLStreamException, IOException
void de.mfuchs.xmlstorage.stream.XMLStreamReader.endElement ( String  nodeName ) [private]
boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.find ( final String  nodeName ) throws XMLStreamException

Find a children node by name.

Parameters:
nodeName
Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 428 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild().

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamReader.findRelative().

    {
        return firstChild(nodeName);
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.find ( final String  nodeName,
int  n 
) throws XMLStreamException

Find the n'th children node with tag nodeName.

Parameters:
nodeName
n
Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 440 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild(), and de.mfuchs.xmlstorage.stream.XMLStreamReader.nextSkipOthers().

    {
        if (!firstChild(nodeName))
            return false;

        for(int i=1; i<n; ++i)
            if (!nextSkipOthers(nodeName))
                return false;

        return true;
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.find ( final String  nodeName,
final String  attrName,
final String  attrValue 
) throws XMLStreamException

Search matching child node identified by key name and an attribute value.

Parameters:
nodeName
attrName
attrValue
Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 460 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild(), de.mfuchs.xmlstorage.stream.XMLStreamNode.get(), de.mfuchs.xmlstorage.stream.XMLStreamNode.getName(), and de.mfuchs.xmlstorage.stream.XMLStreamReader.nextSkipOthers().

    {
        if (firstChild(nodeName)) {
            if (_node.getName().equals(nodeName) && _node.get(attrName).equals(attrValue))
                return true;

            while(nextSkipOthers(nodeName))
                if (_node.getName().equals(nodeName) && _node.get(attrName).equals(attrValue))
                    return true;
        }

        return false;
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.find ( final String  nodeName,
final String  attrName,
final String  attrValue,
int  n 
) throws XMLStreamException

Search matching child node identified by key name and an attribute value.

Parameters:
nodeName
attrName
attrValue
n
Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 483 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild(), de.mfuchs.xmlstorage.stream.XMLStreamNode.get(), de.mfuchs.xmlstorage.stream.XMLStreamNode.getName(), and de.mfuchs.xmlstorage.stream.XMLStreamReader.nextSkipOthers().

    {
        if (firstChild(nodeName)) {
            if (_node.getName().equals(nodeName) && _node.get(attrName).equals(attrValue))
                if (n-- == 0)
                    return true;

            while(nextSkipOthers(nodeName))
                if (_node.getName().equals(nodeName) && _node.get(attrName).equals(attrValue))
                    if (n-- == 0)
                        return true;
        }

        return false;
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.find ( XPathElement  xelem ) throws XMLStreamException [package]

Search matching child node identified by key name and an attribute value.

Parameters:
xelem
Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 521 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild(), and de.mfuchs.xmlstorage.stream.XMLStreamReader.nextSkipOthers().

    {
        int[] n = new int[] {0};    // index in array for call-by-reference matches()

        if (firstChild(xelem._childName)) {
            if (xelem.matches(_node, n))
                return true;

            while(nextSkipOthers(xelem._childName))
                if (xelem.matches(_node, n))
                    return true;
        }

        return false;
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.findNode ( String  targetTag,
int  targetLevel,
int  minLevel,
boolean  stopOnOthers 
) throws XMLStreamException [private]

Definition at line 354 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._content, de.mfuchs.xmlstorage.stream.XMLStreamReader._level, de.mfuchs.xmlstorage.stream.XMLStreamReader._node, de.mfuchs.xmlstorage.stream.XMLStreamReader._reader, de.mfuchs.xmlstorage.stream.XMLStreamReader.characters(), de.mfuchs.xmlstorage.stream.XMLStreamReader.endElement(), de.mfuchs.xmlstorage.stream.XMLStreamReader.next(), de.mfuchs.xmlstorage.stream.XMLStreamReader.processingInstruction(), de.mfuchs.xmlstorage.stream.XMLStreamNode.setContent(), and de.mfuchs.xmlstorage.stream.XMLStreamReader.startElement().

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamReader.back(), de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild(), de.mfuchs.xmlstorage.stream.XMLStreamReader.next(), de.mfuchs.xmlstorage.stream.XMLStreamReader.nextSkipOthers(), and de.mfuchs.xmlstorage.stream.XMLStreamReader.nextStopOnOthers().

    {
        boolean found = false;

        parsingLoop: for(; _reader.hasNext(); _reader.next()) {
            switch(_reader.getEventType()) {
                case XMLEvent.START_ELEMENT: {
                     // stop parsing if we found the target node and its content is already processed.
                    if (found)
                        break parsingLoop;

                    String nodeName = _reader.getLocalName();

                     // check for match in target level and eventually node name
                    if (_level+1 == targetLevel) {
                        if (targetTag==null || nodeName.equals(targetTag))
                            found = true;
                        else if (stopOnOthers)
                            return false;
                    }

//                  System.out.print("<"+nodeName+">");
                    startElement(nodeName);
                    break;}

                case XMLEvent.END_ELEMENT: {
                     // stop parsing if we found the target node and its content is already processed.
                    if (found)
                        break parsingLoop;

                     // stop before leaving the targeted level range; used by nextStopOnOthers()
                    if (_level == minLevel)
                        return false;

                    String nodeName = _reader.getLocalName();
                    endElement(nodeName);
//                  System.out.print("</"+nodeName+">");

                     // stop searching if the current level leaves the target range; used by back()
                    if (_level < minLevel) {
                        _reader.next();
                        return false;
                    }
                    break;}

                case XMLEvent.CHARACTERS:
                case XMLEvent.COMMENT:
                case XMLEvent.SPACE:
                case XMLEvent.CDATA:
                    characters();
//                  System.out.print(_reader.getText());
                    break;

                case XMLEvent.PROCESSING_INSTRUCTION:
                    processingInstruction();
                    break;
            }
        }

        if (found) {
            _node.setContent(_content);
            _content = "";
            return true;
        } else
            return false;
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.findRelative ( final XPath  xpath ) throws XMLStreamException [package]

XPath find function.

Parameters:
xpath
Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 505 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader.find().

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamReader.go().

    {
        for(XPathElement xelem : xpath) {
            if (!find(xelem))
                return false;
        }

        return true;
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild (  ) throws XMLStreamException
boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild ( String  nodeName ) throws XMLStreamException

Move to the first child node with the specified name.

Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 317 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._level, and de.mfuchs.xmlstorage.stream.XMLStreamReader.findNode().

    {
        return findNode(nodeName, _level+1, _level, false);
    }

Here is the call graph for this function:

String de.mfuchs.xmlstorage.stream.XMLStreamReader.get ( final String  attrName,
final String  def 
)

Return the value of an attribute in the current node or a default value.

Parameters:
attrName
defdefault value
Returns:

Definition at line 203 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, and de.mfuchs.xmlstorage.stream.XMLStreamNode.get().

    {
        return _node.get(attrName, def);
    }

Here is the call graph for this function:

String de.mfuchs.xmlstorage.stream.XMLStreamReader.get ( final String  attrName )

Return the value of an attribute in the current node or "".

Parameters:
attrName
Returns:

Definition at line 192 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, and de.mfuchs.xmlstorage.stream.XMLStreamNode.get().

Referenced by de.mfuchs.XMLTest.testStreamingReader1(), and de.mfuchs.XMLTest.testStreamingReader2().

    {
        return _node.get(attrName);
    }

Here is the call graph for this function:

String de.mfuchs.xmlstorage.stream.XMLStreamReader.getContent (  )
Returns:
content string

Definition at line 254 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, and de.mfuchs.xmlstorage.stream.XMLStreamNode.getContent().

Referenced by de.mfuchs.XMLTest.testStreamingReader2().

    {
        return _node.getContent();
    }

Here is the call graph for this function:

String de.mfuchs.xmlstorage.stream.XMLStreamReader.getInstructions (  )

Definition at line 296 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._instructions.

    {
        return _instructions.toString();
    }
XMLStreamNode de.mfuchs.xmlstorage.stream.XMLStreamReader.getNode (  )
Object de.mfuchs.xmlstorage.stream.XMLStreamReader.getNodeName (  )

Definition at line 117 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, and de.mfuchs.xmlstorage.stream.XMLStreamNode.getName().

    {
        return _node.getName();
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.go ( XPath  xpath ) throws XMLStreamException

move X-Path like to position in XML tree

Definition at line 230 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader.findRelative().

    {
         // Absolute paths are not supported.
        if (xpath._absolute)
            return false;

        return findRelative(xpath);
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.goDown (  ) throws XMLStreamException

Go down to first child.

Returns:
true if successfull
Exceptions:
XMLStreamException

Definition at line 213 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild().

Referenced by de.mfuchs.XMLTest.testStreamingReader1(), and de.mfuchs.XMLTest.testStreamingReader2().

    {
        return firstChild(null);
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.goDown ( final String  name ) throws XMLStreamException

Search for child and go down.

Parameters:
name
Returns:
Exceptions:
XMLStreamException

Definition at line 224 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild().

    {
        return firstChild(name);
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.stream.XMLStreamReader.init ( Source  source ) throws XMLStreamException [private]

Definition at line 91 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, and de.mfuchs.xmlstorage.stream.XMLStreamReader._reader.

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamReader.XMLStreamReader().

    {
        _node = new XMLStreamNode();

        XMLInputFactory factory = XMLInputFactory.newInstance();

        _reader = factory.createXMLStreamReader(source);
    }
boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.isAtNode ( String  nodeName )

Definition at line 122 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, and de.mfuchs.xmlstorage.stream.XMLStreamNode.getName().

    {
        return _node.getName().equals(nodeName);
    }

Here is the call graph for this function:

Iterator<XMLStreamNode> de.mfuchs.xmlstorage.stream.XMLStreamReader.iterator (  )

Definition at line 181 of file XMLStreamReader.java.

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamFilter.XMLStreamFilter().

    {
        return new XMLStreamIterator(this);
    }
boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.next (  ) throws XMLStreamException

Move to the next sibling node independent from its name.

Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 328 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._level, and de.mfuchs.xmlstorage.stream.XMLStreamReader.findNode().

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamReader.findNode(), and de.mfuchs.xmlstorage.stream.XMLStreamReader.XMLStreamIterator.moveToNext().

    {
        return findNode(null, _level, _level-1, false);
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.nextSkipOthers ( String  nodeName ) throws XMLStreamException

Move to the next sibling node with the specified name.

Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 338 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._level, and de.mfuchs.xmlstorage.stream.XMLStreamReader.findNode().

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamReader.find(), and de.mfuchs.XMLTest.testStreamingReader1().

    {
        return findNode(nodeName, _level, _level-1, false);
    }

Here is the call graph for this function:

boolean de.mfuchs.xmlstorage.stream.XMLStreamReader.nextStopOnOthers ( String  nodeName ) throws XMLStreamException

Move to the next sibling node with the specified name.

Returns:
true on success
Exceptions:
XMLStreamException

Definition at line 348 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._level, and de.mfuchs.xmlstorage.stream.XMLStreamReader.findNode().

    {
        return findNode(nodeName, _level, _level-1, true);
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.stream.XMLStreamReader.processingInstruction (  ) [private]

Definition at line 290 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._instructions, and de.mfuchs.xmlstorage.stream.XMLStreamReader._reader.

Referenced by de.mfuchs.xmlstorage.stream.XMLStreamReader.findNode().

    {
        _instructions.append("<?").append(_reader.getPITarget())
            .append(" ").append(_reader.getPIData()).append("?>");
    }
void de.mfuchs.xmlstorage.stream.XMLStreamReader.startElement ( String  nodeName ) [private]
String de.mfuchs.xmlstorage.stream.XMLStreamReader.toString (  )

Definition at line 259 of file XMLStreamReader.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader._node, and de.mfuchs.xmlstorage.stream.XMLStreamNode.toString().

    {
        return _node.toString();
    }

Here is the call graph for this function:


Member Data Documentation

StringBuffer de.mfuchs.xmlstorage.stream.XMLStreamReader._instructions = new StringBuffer() [protected]
javax.xml.stream.XMLStreamReader de.mfuchs.xmlstorage.stream.XMLStreamReader._reader [protected]

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