public abstract class GPathResult extends GroovyObjectSupport implements Writable, Buildable, java.lang.Iterable
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
name |
protected java.util.Map |
namespaceMap |
protected java.lang.String |
namespacePrefix |
protected java.util.Map<java.lang.String,java.lang.String> |
namespaceTagHints |
protected GPathResult |
parent |
Constructor and Description |
---|
GPathResult(GPathResult parent,
java.lang.String name,
java.lang.String namespacePrefix,
java.util.Map<java.lang.String,java.lang.String> namespaceTagHints)
Creates a new GPathResult named
name with the parent parent ,
the namespacePrefix namespacePrefix and the namespaceTagHints specified in
the namespaceTagHints Map. |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
appendNode(java.lang.Object newValue) |
java.util.Iterator |
breadthFirst()
Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.
|
abstract java.util.Iterator |
childNodes()
Returns an iterator over the child nodes of this GPathResult.
|
GPathResult |
children()
Returns the children of this GPathResult as a GPathResult object.
|
GPathResult |
declareNamespace(java.util.Map newNamespaceMapping)
Adds the specified map of prefix to namespace mappings to this GPathResult.
|
java.util.Iterator |
depthFirst()
Provides an Iterator over all the nodes of this GPathResult using a depth-first traversal.
|
boolean |
equals(java.lang.Object obj) |
abstract GPathResult |
find(Closure closure)
Returns the first child of this GPathResult matching the condition(s)
specified in the passed closure.
|
abstract GPathResult |
findAll(Closure closure)
Returns the children of this GPathResult matching the condition(s)
specified in the passed closure.
|
java.lang.Object |
getAt(int index)
Supports the subscript operator for a GPathResult.
|
java.lang.Object |
getAt(IntRange range)
Supports the range subscript operator for a GPathResult.
|
Closure |
getBody()
Creates a Closure representing the body of this GPathResult.
|
java.lang.Object |
getProperty(java.lang.String property)
Returns the specified Property of this GPathResult.
|
boolean |
isEmpty()
Returns true if the GPathResult is empty, i.e.
|
abstract java.util.Iterator |
iterator() |
java.lang.Object |
leftShift(java.lang.Object newValue)
Overloads the left shift operator to provide an easy way to
lazily append Objects to this GPathResult.
|
java.util.List |
list()
Creates a list of objects representing this GPathResult.
|
java.lang.String |
lookupNamespace(java.lang.String prefix)
Returns the namespace mapped to the specified prefix.
|
java.lang.String |
name()
Returns the name of this GPathResult.
|
abstract java.util.Iterator |
nodeIterator() |
GPathResult |
parent()
Returns as GPathResult with the parent nodes of the current GPathResult
|
abstract GPathResult |
parents()
Returns the parents of this GPathResult as a
GPathResult . |
java.lang.Object |
plus(java.lang.Object newValue)
Lazily adds the specified Object to this GPathResult.
|
GPathResult |
pop()
Returns the parent of this GPathResult.
|
void |
putAt(int index,
java.lang.Object newValue)
A helper method to allow GPathResults to work with subscript operators
|
protected abstract void |
replaceBody(java.lang.Object newValue) |
protected abstract void |
replaceNode(Closure newValue) |
void |
setMetaClass(MetaClass metaClass)
Replaces the MetaClass of this GPathResult.
|
void |
setProperty(java.lang.String property,
java.lang.Object newValue)
Replaces the specified property of this GPathResult with a new value.
|
abstract int |
size()
Returns the size of this GPathResult.
|
abstract java.lang.String |
text()
Returns the text of this GPathResult as a
String . |
java.math.BigDecimal |
toBigDecimal()
Converts the text of this GPathResult to a BigDecimal object.
|
java.math.BigInteger |
toBigInteger()
Converts the text of this GPathResult to a BigInteger object.
|
java.lang.Boolean |
toBoolean()
Converts the text of this GPathResult to a Boolean object.
|
java.lang.Double |
toDouble()
Converts the text of this GPathResult to a Double object.
|
java.lang.Float |
toFloat()
Converts the text of this GPathResult to a Float object.
|
java.lang.Integer |
toInteger()
Converts the text of this GPathResult to a Integer object.
|
java.lang.Long |
toLong()
Converts the text of this GPathResult to a Long object.
|
java.lang.String |
toString()
Returns the text of this GPathResult.
|
java.net.URI |
toURI()
Converts the text of this GPathResult to a URI object.
|
java.net.URL |
toURL()
Converts the text of this GPathResult to a URL object.
|
getMetaClass, invokeMethod
protected final GPathResult parent
protected final java.lang.String name
protected final java.lang.String namespacePrefix
protected final java.util.Map namespaceMap
protected final java.util.Map<java.lang.String,java.lang.String> namespaceTagHints
public GPathResult(GPathResult parent, java.lang.String name, java.lang.String namespacePrefix, java.util.Map<java.lang.String,java.lang.String> namespaceTagHints)
name
with the parent parent
,
the namespacePrefix namespacePrefix
and the namespaceTagHints specified in
the namespaceTagHints
Map.parent
- the GPathResult prior to the application of the expression creating this GPathResultname
- if the GPathResult corresponds to something with a name, e.g. a nodenamespacePrefix
- the namespace prefix if anynamespaceTagHints
- the known tag to namespace mappingspublic void setMetaClass(MetaClass metaClass)
setMetaClass
in interface GroovyObject
setMetaClass
in class GroovyObjectSupport
metaClass
- the new MetaClasspublic java.lang.Object getProperty(java.lang.String property)
Realizes the follow shortcuts:
'..'
for parent()
'*'
for children()
'**'
for depthFirst()
'@'
for attribute access
getProperty
in interface GroovyObject
getProperty
in class GroovyObjectSupport
property
- the Property to fetchpublic void setProperty(java.lang.String property, java.lang.Object newValue)
setProperty
in interface GroovyObject
setProperty
in class GroovyObjectSupport
property
- the property of this GPathResult to replacenewValue
- the new value of the propertypublic java.lang.Object leftShift(java.lang.Object newValue)
newValue
- the Object to appendthis
public java.lang.Object plus(java.lang.Object newValue)
newValue
- the Object to addthis
protected abstract void replaceNode(Closure newValue)
protected abstract void replaceBody(java.lang.Object newValue)
protected abstract void appendNode(java.lang.Object newValue)
public java.lang.String name()
public GPathResult pop()
this
public GPathResult parent()
this
for the rootpublic GPathResult children()
public java.lang.String lookupNamespace(java.lang.String prefix)
prefix
- the prefix lookuppublic java.lang.String toString()
toString
in class java.lang.Object
String
public java.lang.Integer toInteger()
Integer
public java.lang.Long toLong()
Long
public java.lang.Float toFloat()
Float
public java.lang.Double toDouble()
Double
public java.math.BigDecimal toBigDecimal()
BigDecimal
public java.math.BigInteger toBigInteger()
BigInteger
public java.net.URL toURL() throws java.net.MalformedURLException
URL
java.net.MalformedURLException
public java.net.URI toURI() throws java.net.URISyntaxException
URI
java.net.URISyntaxException
public java.lang.Boolean toBoolean()
Boolean
public GPathResult declareNamespace(java.util.Map newNamespaceMapping)
newNamespaceMapping
- the mappings to addthis
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.Object getAt(int index)
import groovy.util.slurpersupport.* def text = """ <characterList> <character/> <character> <name>Gromit</name> </character> </characterList>""" GPathResult characterList = new XmlSlurper().parseText(text) assert characterList.character[1].name == 'Gromit'
index
- an indexpublic java.lang.Object getAt(IntRange range)
import groovy.util.slurpersupport.* def text = """ <characterList> <character>Wallace</character> <character>Gromit</character> <character>Shaun</character> </characterList>""" GPathResult characterList = new XmlSlurper().parseText(text) assert characterList.character[1..2].join(',') == 'Gromit,Shaun'
range
- a Range indicating the items to getpublic void putAt(int index, java.lang.Object newValue)
index
- an indexnewValue
- the value to put at the given indexpublic java.util.Iterator depthFirst()
Iterator
of (depth-first) ordered GPathResultspublic java.util.Iterator breadthFirst()
Iterator
of (breadth-first) ordered GPathResultspublic java.util.List list()
public boolean isEmpty()
size()
is 0.public Closure getBody()
Closure
public abstract int size()
public abstract java.lang.String text()
String
.public abstract GPathResult parents()
GPathResult
.
Warning: The subclasses of this package do not implement this method yet.public abstract java.util.Iterator childNodes()
public abstract java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
public abstract GPathResult find(Closure closure)
closure
- a closure to filters the children of this GPathResultpublic abstract GPathResult findAll(Closure closure)
closure
- a closure to filters the children of this GPathResultpublic abstract java.util.Iterator nodeIterator()