org.staxnav
Class StaxNavigatorImpl<N>

java.lang.Object
  extended by org.staxnav.StaxNavigatorImpl<N>
All Implemented Interfaces:
StaxNavigator<N>

public class StaxNavigatorImpl<N>
extends java.lang.Object
implements StaxNavigator<N>

Version:
$Revision$
Author:
Julien Viet

Constructor Summary
StaxNavigatorImpl(Naming<N> naming, javax.xml.stream.XMLStreamReader stream)
           
 
Method Summary
 N _child(N name)
           
 N child()
          Attempts to navigate to the first child found and return its name.
 boolean child(N name)
          Attempts to navigate to the first child with the specified name.
 int descendant(N name)
          Attempts to navigate to the first descendant with the specified name.
 boolean find(N name)
          Attempts to navigate to an element following the current one when it has the specified name.
 StaxNavigator<N> fork()
          Creates a navigator scoped around the currently navigated element.
 java.lang.Iterable<StaxNavigator<N>> fork(N name)
          Returns an iterable of stax navigator that is built according to the rules: Each element is found by the StaxNavigator.find(Object). When an element is found, the StaxNavigator.sibling() method is invoked.
 java.lang.String getAttribute(javax.xml.namespace.QName name)
          Returns an attribute of the current element or null if such attribute does not exist.
 java.lang.String getAttribute(java.lang.String name)
          Returns an attribute of the current element or null if such attribute does not exist.
 java.lang.String getContent()
          Returns the current navigated element textual content.
 int getDepth()
          Returns the current navigated element depth.
 java.lang.String getLocalName()
          Returns the string representation of the local xml element.
 javax.xml.stream.Location getLocation()
          Returns the location of the start tag of the currently navigated element.
 N getName()
          Returns the current navigated element name.
 java.lang.String getNamespaceByPrefix(java.lang.String prefix)
          Returns a namespace URI by its prefix or return null if it is not bound.
 Naming<N> getNaming()
          Returns the naming used for this navigator.
 boolean getTrimContent()
          Returns the trim content configuration.
 N next()
          Navigates to the next element and returns its name or null if the end of the stream is reached.
 boolean next(N name)
          Attempt to navigate to the next element when it has the specified name.
 N next(java.util.Set<N> names)
          Attempts to navigate to the next element when it belongs to the set of specified names.
<V> V
parseContent(ValueType<V> valueType)
          Parses the content of the currently navigated element and return the parsed value.
 void setTrimContent(boolean trimContent)
          Configures the content trimming when StaxNavigator.getContent() method is invoked.
 N sibling()
          Attempt to navigate to the next sibling and return its name.
 boolean sibling(N name)
          Attempts to navigate to the next sibling with the specified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaxNavigatorImpl

public StaxNavigatorImpl(Naming<N> naming,
                         javax.xml.stream.XMLStreamReader stream)
                  throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException
Method Detail

getName

public N getName()
          throws StaxNavException
Description copied from interface: StaxNavigator
Returns the current navigated element name.

Specified by:
getName in interface StaxNavigator<N>
Returns:
the element name
Throws:
StaxNavException - any StaxNavException

getNaming

public Naming<N> getNaming()
Description copied from interface: StaxNavigator
Returns the naming used for this navigator.

Specified by:
getNaming in interface StaxNavigator<N>
Returns:
the naming object used for the navigator.

getLocalName

public java.lang.String getLocalName()
                              throws StaxNavException
Description copied from interface: StaxNavigator
Returns the string representation of the local xml element.

Specified by:
getLocalName in interface StaxNavigator<N>
Returns:
name of xml element
Throws:
StaxNavException - any StaxNavException

getLocation

public javax.xml.stream.Location getLocation()
                                      throws StaxNavException
Description copied from interface: StaxNavigator
Returns the location of the start tag of the currently navigated element.

Specified by:
getLocation in interface StaxNavigator<N>
Returns:
the element location
Throws:
StaxNavException - any StaxNavException

getDepth

public int getDepth()
             throws StaxNavException
Description copied from interface: StaxNavigator
Returns the current navigated element depth.

Specified by:
getDepth in interface StaxNavigator<N>
Returns:
the element level
Throws:
StaxNavException - any StaxNavException

setTrimContent

public void setTrimContent(boolean trimContent)
Description copied from interface: StaxNavigator
Configures the content trimming when StaxNavigator.getContent() method is invoked.

Specified by:
setTrimContent in interface StaxNavigator<N>
Parameters:
trimContent - true to trim content

getTrimContent

public boolean getTrimContent()
Description copied from interface: StaxNavigator
Returns the trim content configuration.

Specified by:
getTrimContent in interface StaxNavigator<N>
Returns:
the trim content value

getContent

public java.lang.String getContent()
                            throws StaxNavException
Description copied from interface: StaxNavigator
Returns the current navigated element textual content. Note that this method is only valid when an element content is not mixed, if an element has a mixed content then this method will return null instead.

Specified by:
getContent in interface StaxNavigator<N>
Returns:
the element text content
Throws:
StaxNavException - any StaxNavException

parseContent

public <V> V parseContent(ValueType<V> valueType)
               throws java.lang.IllegalStateException,
                      java.lang.NullPointerException,
                      StaxNavException
Description copied from interface: StaxNavigator
Parses the content of the currently navigated element and return the parsed value.

Specified by:
parseContent in interface StaxNavigator<N>
Type Parameters:
V - the generic type of the value
Parameters:
valueType - the content value type
Returns:
the parsed content value
Throws:
java.lang.IllegalStateException - if the current element does not point to a content
java.lang.NullPointerException - if the value type argument is null
StaxNavException - any StaxNavException
TypeConversionException - when the a type conversion error occured

getAttribute

public java.lang.String getAttribute(java.lang.String name)
                              throws java.lang.NullPointerException,
                                     java.lang.IllegalStateException,
                                     StaxNavException
Description copied from interface: StaxNavigator
Returns an attribute of the current element or null if such attribute does not exist.

Specified by:
getAttribute in interface StaxNavigator<N>
Parameters:
name - the attribute name
Returns:
the attribute value
Throws:
java.lang.NullPointerException - if the name argument is null
java.lang.IllegalStateException - if no element is currently navigated
StaxNavException - any StaxNavException

fork

public StaxNavigator<N> fork()
                      throws StaxNavException
Description copied from interface: StaxNavigator
Creates a navigator scoped around the currently navigated element. The returned navigator will uses the current element as navigation root and the navigation scope is the set of descendants of its root. The forked navigator will use the same configuration than the navigator from which it was forked. The current navigation will be moved to the next sibling of the current node.

Specified by:
fork in interface StaxNavigator<N>
Returns:
a forked navigator
Throws:
StaxNavException - any StaxNavException

fork

public java.lang.Iterable<StaxNavigator<N>> fork(N name)
Description copied from interface: StaxNavigator
Returns an iterable of stax navigator that is built according to the rules:

Specified by:
fork in interface StaxNavigator<N>
Parameters:
name - the name of the root elements of the forked navigator
Returns:
an iterable of the forks

getAttribute

public java.lang.String getAttribute(javax.xml.namespace.QName name)
                              throws java.lang.NullPointerException,
                                     java.lang.IllegalStateException,
                                     StaxNavException
Description copied from interface: StaxNavigator
Returns an attribute of the current element or null if such attribute does not exist.

Specified by:
getAttribute in interface StaxNavigator<N>
Parameters:
name - the attribute name
Returns:
the attribute value
Throws:
java.lang.NullPointerException - if the name argument is null
java.lang.IllegalStateException - if no element is currently navigated
StaxNavException - any StaxNavException

getNamespaceByPrefix

public java.lang.String getNamespaceByPrefix(java.lang.String prefix)
                                      throws java.lang.NullPointerException,
                                             StaxNavException
Description copied from interface: StaxNavigator
Returns a namespace URI by its prefix or return null if it is not bound.

Specified by:
getNamespaceByPrefix in interface StaxNavigator<N>
Parameters:
prefix - the prefix
Returns:
the corresponding namespace URI
Throws:
java.lang.NullPointerException - if the prefix is null
StaxNavException - any StaxNavException

next

public N next()
       throws StaxNavException
Description copied from interface: StaxNavigator
Navigates to the next element and returns its name or null if the end of the stream is reached.

Specified by:
next in interface StaxNavigator<N>
Returns:
the element name
Throws:
StaxNavException - any StaxNavException

next

public boolean next(N name)
             throws StaxNavException
Description copied from interface: StaxNavigator
Attempt to navigate to the next element when it has the specified name. If the navigation occurs, the navigator now points to that element and the method returns true. Otherwise no navigation happens and the method returns false.

Specified by:
next in interface StaxNavigator<N>
Parameters:
name - the desired element name
Returns:
true if the desired element is reached
Throws:
StaxNavException - any StaxNavException

next

public N next(java.util.Set<N> names)
       throws StaxNavException
Description copied from interface: StaxNavigator
Attempts to navigate to the next element when it belongs to the set of specified names. If the navigation occurs, the navigator now points to that element and the method returns the element that was navigated to. Otherwise no navigation happens and the method return null.

Specified by:
next in interface StaxNavigator<N>
Parameters:
names - the set of desired element names
Returns:
the matched name
Throws:
StaxNavException - any StaxNavException

find

public boolean find(N name)
             throws StaxNavException
Description copied from interface: StaxNavigator
Attempts to navigate to an element following the current one when it has the specified name. If the navigation occurs, the navigator now points to that element and the method returns true. Otherwise no navigation happens and the method returns false.

Specified by:
find in interface StaxNavigator<N>
Parameters:
name - the element name to find
Returns:
true if the desired element is reached
Throws:
StaxNavException - any StaxNavException

child

public N child()
        throws StaxNavException
Description copied from interface: StaxNavigator
Attempts to navigate to the first child found and return its name. If no such child exists then null is returned.

Specified by:
child in interface StaxNavigator<N>
Returns:
the child name
Throws:
StaxNavException - any StaxNavException

child

public boolean child(N name)
              throws java.lang.NullPointerException,
                     StaxNavException
Description copied from interface: StaxNavigator
Attempts to navigate to the first child with the specified name. If the navigation occurs, the navigator now points to that element and the method returns true. Otherwise no navigation happens and the method returns false.

Specified by:
child in interface StaxNavigator<N>
Parameters:
name - the child name
Returns:
true if the desired element is reached
Throws:
java.lang.NullPointerException - if the name argument is null
StaxNavException - any StaxNavException

_child

public N _child(N name)
         throws StaxNavException
Throws:
StaxNavException

sibling

public N sibling()
          throws StaxNavException
Description copied from interface: StaxNavigator
Attempt to navigate to the next sibling and return its name. If no such sibling exists then null is returned.

Specified by:
sibling in interface StaxNavigator<N>
Returns:
the next sibling name
Throws:
StaxNavException - any StaxNavException

sibling

public boolean sibling(N name)
                throws java.lang.NullPointerException,
                       StaxNavException
Description copied from interface: StaxNavigator
Attempts to navigate to the next sibling with the specified name. If the navigation occurs, the navigator now points to that element and the method returns true. Otherwise no navigation happens and the method returns false.

Specified by:
sibling in interface StaxNavigator<N>
Parameters:
name - the next sibling name
Returns:
true if the desired element is reached
Throws:
java.lang.NullPointerException - if the name argument is null
StaxNavException - any StaxNavException

descendant

public int descendant(N name)
               throws java.lang.NullPointerException,
                      StaxNavException
Description copied from interface: StaxNavigator
Attempts to navigate to the first descendant with the specified name. The returned value should be interpreted as:

Specified by:
descendant in interface StaxNavigator<N>
Parameters:
name - the descendant name
Returns:
the
Throws:
java.lang.NullPointerException - if the name is null
StaxNavException - any StaxNavException


Copyright © 2011 eXo Platform SAS. All Rights Reserved.