com.googlecode.jinahya.elementlocator
Class ElementLocator<D>

java.lang.Object
  extended by com.googlecode.jinahya.elementlocator.ElementLocator<D>
Type Parameters:
D - document type parameter
Direct Known Subclasses:
DOM4JElementLocator, DOMElementLocator, JDOMElementLocator, KDOMElementLocator, XOMElementLocator

public abstract class ElementLocator<D>
extends Object

Abstract element locator.

Author:
Jin Kwon

Method Summary
 ElementLocator<D> addChild(String localName)
          Deprecated. Use child(java.lang.String)
 ElementLocator<D> addChild(String namespaceURI, String localName)
          Deprecated. Use child(java.lang.String, java.lang.String)
 String attribute(String namespaceURI, String localName)
          Finds an attribute and returns its value.
 ElementLocator<D> attribute(String namespaceURI, String localName, String value)
          Sets or removes attribute's value.
 ElementLocator<D> child(String localName)
          Adds a child element and locate it.
 ElementLocator<D> child(String localName, int index)
          Locates child element which has given localName in no name space at index.
 ElementLocator<D> child(String namespaceURI, String localName)
          Adds a child element and locate it.
 ElementLocator<D> child(String namespaceURI, String localName, int index)
          Locate a child element which has given localName in given namespaceURI at index.
 String getAttribute(String localName)
          Deprecated. Use attribute(java.lang.String, java.lang.String)
 String getAttribute(String namespaceURI, String localName)
          Deprecated. Use attribute(java.lang.String, java.lang.String)
 int getChildCount(String localName)
          Returns the number of child elements which each has given localName in no name space.
 int getChildCount(String namespaceURI, String localName)
          Returns the number of child elements which each has given localName in specified namespaceURI.
 String getText()
          Deprecated. Use text()
 ElementLocator<D> locateChild(String localName, int index)
          Deprecated. Use child(java.lang.String, int)
 ElementLocator<D> locateChild(String namespaceURI, String localName, int index)
          Deprecated. Use child(java.lang.String, java.lang.String, int)
 ElementLocator<D> locateParent()
          Deprecated. Use parent()
 ElementLocator<D> locateRoot()
          Deprecated. Use root()
 ElementLocator<D> parent()
          Locates to the parent element.
 ElementLocator<D> remove()
          Removes currently located element and locate parent.
 ElementLocator<D> removeAttribute(String localName)
          Deprecated. Use attribute(String, String, String) with null value.
 ElementLocator<D> removeAttribute(String namespaceURI, String localName)
          Deprecated. Use attribute(String, String, String) with null value.
 ElementLocator<D> removeCurrent()
          Removes current element and locate parent.
 ElementLocator<D> root()
          Locate to the root element.
 ElementLocator<D> setAttribute(String localName, String value)
          Deprecated. Use attribute(String, String, String)
 ElementLocator<D> setAttribute(String namespaceURI, String localName, String value)
          Deprecated. Use attribute(String, String, String)
 ElementLocator<D> setText(String text)
          Deprecated. Use text(java.lang.String)
 String text()
          Returns text value of currently located element.
 ElementLocator<D> text(String text)
          Sets the text value of currently located element.
abstract  D toDocument(D document)
          Prints contents to given document.
 String toJSON()
          Returns JSON representation of the contents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getChildCount

public final int getChildCount(String localName)
Returns the number of child elements which each has given localName in no name space.

Parameters:
localName - local name
Returns:
number of children

getChildCount

public final int getChildCount(String namespaceURI,
                               String localName)
Returns the number of child elements which each has given localName in specified namespaceURI. En empty string("") must be used for no(null) name space.

Parameters:
namespaceURI - The name space URI.
localName - The local name.
Returns:
child count
See Also:
#getCount(String)

locateRoot

public final ElementLocator<D> locateRoot()
Deprecated. Use root()

Locate the root element.

Returns:
self

root

public final ElementLocator<D> root()
Locate to the root element. Nothing happens if this locator is already locating the root element.

Returns:
self

locateParent

public final ElementLocator<D> locateParent()
Deprecated. Use parent()

Locate to the parent of the current element. An IllegalStateException will be thrown if this locator is already on the root.

Returns:
self

parent

public final ElementLocator<D> parent()
Locates to the parent element. An IllegalStateException will be thrown if there is no parent to locate (on the root).

Returns:
self

locateChild

public final ElementLocator<D> locateChild(String localName,
                                           int index)
Deprecated. Use child(java.lang.String, int)

Locates child element which has given localName with no name space at index.

Parameters:
localName - local name
index - index
Returns:
self

locateChild

public final ElementLocator<D> locateChild(String namespaceURI,
                                           String localName,
                                           int index)
Deprecated. Use child(java.lang.String, java.lang.String, int)

Locate a child with localName at index in namespaceURI.

Parameters:
namespaceURI - element's name space URI
localName - element's local name
index - target index to locate
Returns:
self
See Also:
locateChild(String, int)

child

public final ElementLocator<D> child(String localName,
                                     int index)
Locates child element which has given localName in no name space at index. An IndexOutOfBoundsException will be thrown if there is no child at specified index.

Parameters:
localName - element's local name
index - child element index
Returns:
self
See Also:
child(java.lang.String, java.lang.String, int)

child

public final ElementLocator<D> child(String namespaceURI,
                                     String localName,
                                     int index)
Locate a child element which has given localName in given namespaceURI at index. An IndexOutOfBoundsException will be thrown if there is no child at specified index.

Parameters:
namespaceURI - element's name space URI
localName - element's local name
index - target index to locate
Returns:
self
See Also:
child(String, int)

addChild

public final ElementLocator<D> addChild(String localName)
Deprecated. Use child(java.lang.String)

Adds a child element whose name is localName with no name space and locate it.

Parameters:
localName - local name
Returns:
self

addChild

public final ElementLocator<D> addChild(String namespaceURI,
                                        String localName)
Deprecated. Use child(java.lang.String, java.lang.String)

Adds a child element whose name is localName with given namespaceURI and locate it.

Parameters:
namespaceURI -
localName -
Returns:

child

public final ElementLocator<D> child(String localName)
Adds a child element and locate it. The new child element will be named as localName in no name space.

Parameters:
localName - new child element's local name.
Returns:
self

child

public final ElementLocator<D> child(String namespaceURI,
                                     String localName)
Adds a child element and locate it. The new child element will be named as localName in given namespaceURI.

Parameters:
namespaceURI - child element's name space URI
localName - child element's local name
Returns:
self

getText

public final String getText()
Deprecated. Use text()

Returns text value of currently located element.

Returns:
text value; may be null

text

public final String text()
Returns text value of currently located element.

Returns:
text value; may be null

setText

public final ElementLocator<D> setText(String text)
Deprecated. Use text(java.lang.String)

Sets the text value.

Parameters:
text - text value
Returns:
self

text

public final ElementLocator<D> text(String text)
Sets the text value of currently located element.

Parameters:
text - new text value
Returns:
self

getAttribute

public final String getAttribute(String localName)
Deprecated. Use attribute(java.lang.String, java.lang.String)

Returns attribute value.

Parameters:
localName - attribute's local name
Returns:
attribute's value

getAttribute

public final String getAttribute(String namespaceURI,
                                 String localName)
Deprecated. Use attribute(java.lang.String, java.lang.String)

Returns the value of attribute which has name in space.

Parameters:
namespaceURI - attribute's name space URI
localName - attribute's local name
Returns:
attribute's value

attribute

public final String attribute(String namespaceURI,
                              String localName)
Finds an attribute and returns its value.

Parameters:
namespaceURI - attribute's name space URI
localName - attribute's local name
Returns:
attribute's value or null if not found

setAttribute

public final ElementLocator<D> setAttribute(String localName,
                                            String value)
Deprecated. Use attribute(String, String, String)

Sets attribute value.

Parameters:
localName - local name
value - attribute value
Returns:
self

setAttribute

public final ElementLocator<D> setAttribute(String namespaceURI,
                                            String localName,
                                            String value)
Deprecated. Use attribute(String, String, String)

Sets the value of attribute which has localName in namespaceURI.

Parameters:
namespaceURI - attribute's name space URI
localName - attribute's local name
value - attribute's value
Returns:
self

attribute

public final ElementLocator<D> attribute(String namespaceURI,
                                         String localName,
                                         String value)
Sets or removes attribute's value. If value is null mapped attribute will be removed.

Parameters:
namespaceURI - attribute's name space URI
localName - attribute's local name
value - attribute's value; null for removing attribute
Returns:
self

removeAttribute

public final ElementLocator<D> removeAttribute(String localName)
Deprecated. Use attribute(String, String, String) with null value.

Removes attribute whose name is localName with no namespaceURI.

Parameters:
localName - attribute's local name
Returns:
self.

removeAttribute

public final ElementLocator<D> removeAttribute(String namespaceURI,
                                               String localName)
Deprecated. Use attribute(String, String, String) with null value.

Sets the value of attribute which has localName in namespaceURI.

Parameters:
namespaceURI - attribute's name space URI
localName - attribute's local name
Returns:
self

toDocument

public abstract D toDocument(D document)
Prints contents to given document.

Parameters:
document - an empty document
Returns:
given document

removeCurrent

public final ElementLocator<D> removeCurrent()
Removes current element and locate parent. An IllegalStateException will be thrown if this element locator is already locating the root.

Returns:
self

remove

public final ElementLocator<D> remove()
Removes currently located element and locate parent. An IllegalStateException will be thrown if this locate is currently locating the root element.

Returns:
self

toJSON

public final String toJSON()
Returns JSON representation of the contents.

Returns:
a JSON string.


Copyright © 2010-2011. All Rights Reserved.