Package groovy.xml.slurpersupport
Class GPathResult
java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.xml.slurpersupport.GPathResult
- All Implemented Interfaces:
Buildable,GroovyObject,Writable,java.lang.Iterable
- Direct Known Subclasses:
Attribute,NoChildren,NodeChild,NodeChildren
public abstract class GPathResult extends GroovyObjectSupport implements Writable, Buildable, java.lang.Iterable
Base class for representing lazy evaluated GPath expressions.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Stringnameprotected java.util.MapnamespaceMapprotected java.lang.StringnamespacePrefixprotected java.util.Map<java.lang.String,java.lang.String>namespaceTagHintsprotected GPathResultparent -
Constructor Summary
Constructors Constructor 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 namednamewith the parentparent, the namespacePrefixnamespacePrefixand the namespaceTagHints specified in thenamespaceTagHintsMap. -
Method Summary
Modifier and Type Method Description protected abstract voidappendNode(java.lang.Object newValue)java.util.IteratorbreadthFirst()Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.abstract java.util.IteratorchildNodes()Returns an iterator over the child nodes of this GPathResult.GPathResultchildren()Returns the children of this GPathResult as a GPathResult object.protected java.util.IteratorcreateIterator(java.lang.Object obj)GPathResultdeclareNamespace(java.util.Map newNamespaceMapping)Adds the specified map of prefix to namespace mappings to this GPathResult.java.util.IteratordepthFirst()Provides an Iterator over all the nodes of this GPathResult using a depth-first traversal.booleanequals(java.lang.Object obj)abstract GPathResultfind(Closure closure)Returns the first child of this GPathResult matching the condition(s) specified in the passed closure.abstract GPathResultfindAll(Closure closure)Returns the children of this GPathResult matching the condition(s) specified in the passed closure.java.lang.ObjectgetAt(int index)Supports the subscript operator for a GPathResult.java.lang.ObjectgetAt(IntRange range)Supports the range subscript operator for a GPathResult.ClosuregetBody()Creates a Closure representing the body of this GPathResult.java.lang.ObjectgetProperty(java.lang.String property)Returns the specified Property of this GPathResult.inthashCode()booleanisEmpty()Returns true if the GPathResult is empty, i.e.abstract java.util.Iteratoriterator()java.lang.ObjectleftShift(java.lang.Object newValue)Overloads the left shift operator to provide an easy way to lazily append Objects to this GPathResult.java.util.Listlist()Creates a list of objects representing this GPathResult.java.lang.StringlookupNamespace(java.lang.String prefix)Returns the namespace mapped to the specified prefix.java.lang.Stringname()Returns the name of this GPathResult.abstract java.util.IteratornodeIterator()GPathResultparent()Returns as GPathResult with the parent nodes of the current GPathResultabstract GPathResultparents()Returns the parents of this GPathResult as aGPathResult.java.lang.Objectplus(java.lang.Object newValue)Lazily adds the specified Object to this GPathResult.GPathResultpop()Returns the parent of this GPathResult.voidputAt(int index, java.lang.Object newValue)A helper method to allow GPathResults to work with subscript operatorsprotected abstract voidreplaceBody(java.lang.Object newValue)protected abstract voidreplaceNode(Closure newValue)voidsetMetaClass(MetaClass metaClass)Replaces the MetaClass of this GPathResult.voidsetProperty(java.lang.String property, java.lang.Object newValue)Replaces the specified property of this GPathResult with a new value.abstract intsize()Returns the size of this GPathResult.abstract java.lang.Stringtext()Returns the text of this GPathResult as aString.java.math.BigDecimaltoBigDecimal()Converts the text of this GPathResult to a BigDecimal object.java.math.BigIntegertoBigInteger()Converts the text of this GPathResult to a BigInteger object.java.lang.BooleantoBoolean()Converts the text of this GPathResult to a Boolean object.java.lang.DoubletoDouble()Converts the text of this GPathResult to a Double object.java.lang.FloattoFloat()Converts the text of this GPathResult to a Float object.java.lang.IntegertoInteger()Converts the text of this GPathResult to a Integer object.java.lang.LongtoLong()Converts the text of this GPathResult to a Long object.java.lang.StringtoString()Returns the text of this GPathResult.java.net.URItoURI()Converts the text of this GPathResult to a URI object.java.net.URLtoURL()Converts the text of this GPathResult to a URL object.Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClassMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface groovy.lang.GroovyObject
invokeMethodMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
parent
-
name
protected final java.lang.String name -
namespacePrefix
protected final java.lang.String namespacePrefix -
namespaceMap
protected final java.util.Map namespaceMap -
namespaceTagHints
protected final java.util.Map<java.lang.String,java.lang.String> namespaceTagHints
-
-
Constructor Details
-
GPathResult
public 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 namednamewith the parentparent, the namespacePrefixnamespacePrefixand the namespaceTagHints specified in thenamespaceTagHintsMap.- Parameters:
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 mappings
-
-
Method Details
-
setMetaClass
Replaces the MetaClass of this GPathResult.- Specified by:
setMetaClassin interfaceGroovyObject- Overrides:
setMetaClassin classGroovyObjectSupport- Parameters:
metaClass- the new MetaClass
-
getProperty
public java.lang.Object getProperty(java.lang.String property)Returns the specified Property of this GPathResult.Realizes the follow shortcuts:
'..'forparent()'*'forchildren()'**'fordepthFirst()'@'for attribute access
- Specified by:
getPropertyin interfaceGroovyObject- Parameters:
property- the Property to fetch- Returns:
- the given property
-
setProperty
public void setProperty(java.lang.String property, java.lang.Object newValue)Replaces the specified property of this GPathResult with a new value.- Specified by:
setPropertyin interfaceGroovyObject- Parameters:
property- the property of this GPathResult to replacenewValue- the new value of the property
-
leftShift
public 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.- Parameters:
newValue- the Object to append- Returns:
this
-
plus
public java.lang.Object plus(java.lang.Object newValue)Lazily adds the specified Object to this GPathResult.- Parameters:
newValue- the Object to add- Returns:
this
-
replaceNode
-
replaceBody
protected abstract void replaceBody(java.lang.Object newValue) -
appendNode
protected abstract void appendNode(java.lang.Object newValue) -
name
public java.lang.String name()Returns the name of this GPathResult.- Returns:
- the name of this GPathResult
-
pop
Returns the parent of this GPathResult. If this GPathResult has no parent the GPathResult itself is returned. This is no navigation in the XML tree. It is backtracking on the GPath expression chain. It is the behavior of parent() prior to 2.2.0. Backtracking on '..' actually goes down one level in the tree again. find() and findAll() are popped along with the level they have been applied to.- Returns:
- the parent or
this
-
parent
Returns as GPathResult with the parent nodes of the current GPathResult- Returns:
- the parents GPathResult or
thisfor the root
-
children
Returns the children of this GPathResult as a GPathResult object.- Returns:
- the children of this GPathResult
-
lookupNamespace
public java.lang.String lookupNamespace(java.lang.String prefix)Returns the namespace mapped to the specified prefix.- Parameters:
prefix- the prefix lookup- Returns:
- the namespace of the prefix
-
toString
public java.lang.String toString()Returns the text of this GPathResult.- Overrides:
toStringin classjava.lang.Object- Returns:
- the GPathResult, converted to a
String
-
toInteger
public java.lang.Integer toInteger()Converts the text of this GPathResult to a Integer object.- Returns:
- the GPathResult, converted to a
Integer
-
toLong
public java.lang.Long toLong()Converts the text of this GPathResult to a Long object.- Returns:
- the GPathResult, converted to a
Long
-
toFloat
public java.lang.Float toFloat()Converts the text of this GPathResult to a Float object.- Returns:
- the GPathResult, converted to a
Float
-
toDouble
public java.lang.Double toDouble()Converts the text of this GPathResult to a Double object.- Returns:
- the GPathResult, converted to a
Double
-
toBigDecimal
public java.math.BigDecimal toBigDecimal()Converts the text of this GPathResult to a BigDecimal object.- Returns:
- the GPathResult, converted to a
BigDecimal
-
toBigInteger
public java.math.BigInteger toBigInteger()Converts the text of this GPathResult to a BigInteger object.- Returns:
- the GPathResult, converted to a
BigInteger
-
toURL
public java.net.URL toURL() throws java.net.MalformedURLExceptionConverts the text of this GPathResult to a URL object.- Returns:
- the GPathResult, converted to a
URL - Throws:
java.net.MalformedURLException
-
toURI
public java.net.URI toURI() throws java.net.URISyntaxExceptionConverts the text of this GPathResult to a URI object.- Returns:
- the GPathResult, converted to a
URI - Throws:
java.net.URISyntaxException
-
toBoolean
public java.lang.Boolean toBoolean()Converts the text of this GPathResult to a Boolean object.- Returns:
- the GPathResult, converted to a
Boolean
-
declareNamespace
Adds the specified map of prefix to namespace mappings to this GPathResult. Already existing prefixes are overwritten.- Parameters:
newNamespaceMapping- the mappings to add- Returns:
this
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
getAt
public java.lang.Object getAt(int index)Supports the subscript operator for a GPathResult.import groovy.xml.slurpersupport.* import groovy.xml.XmlSlurper def text = """ <characterList> <character/> <character> <name>Gromit</name> </character> </characterList>""" GPathResult characterList = new XmlSlurper().parseText(text) assert characterList.character[1].name == 'Gromit'- Parameters:
index- an index- Returns:
- the value at the given index
-
getAt
Supports the range subscript operator for a GPathResult.import groovy.xml.slurpersupport.* import groovy.xml.XmlSlurper 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'- Parameters:
range- a Range indicating the items to get- Returns:
- a new list based on range borders
-
putAt
public void putAt(int index, java.lang.Object newValue)A helper method to allow GPathResults to work with subscript operators- Parameters:
index- an indexnewValue- the value to put at the given index
-
depthFirst
public java.util.Iterator depthFirst()Provides an Iterator over all the nodes of this GPathResult using a depth-first traversal.- Returns:
- the
Iteratorof (depth-first) ordered GPathResults
-
breadthFirst
public java.util.Iterator breadthFirst()Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.- Returns:
- the
Iteratorof (breadth-first) ordered GPathResults
-
list
public java.util.List list()Creates a list of objects representing this GPathResult.- Returns:
- a list representing of this GPathResult
-
isEmpty
public boolean isEmpty()Returns true if the GPathResult is empty, i.e. if, and only if,size()is 0.- Returns:
- true if the GPathResult is empty
-
getBody
Creates a Closure representing the body of this GPathResult.- Returns:
- the body of this GPathResult, converted to a
Closure
-
size
public abstract int size()Returns the size of this GPathResult.- Returns:
- the size of this GPathResult
-
text
public abstract java.lang.String text()Returns the text of this GPathResult as aString.- Returns:
- the text of this GPathResult
-
parents
Returns the parents of this GPathResult as aGPathResult. Warning: The subclasses of this package do not implement this method yet.- Returns:
- the parents of this GPathResult
-
childNodes
public abstract java.util.Iterator childNodes()Returns an iterator over the child nodes of this GPathResult.- Returns:
- an iterator over the child nodes of this GPathResult
-
iterator
public abstract java.util.Iterator iterator()- Specified by:
iteratorin interfacejava.lang.Iterable
-
find
Returns the first child of this GPathResult matching the condition(s) specified in the passed closure.- Parameters:
closure- a closure to filters the children of this GPathResult- Returns:
- the first child matching the closure
-
findAll
Returns the children of this GPathResult matching the condition(s) specified in the passed closure.- Parameters:
closure- a closure to filters the children of this GPathResult- Returns:
- the children matching the closure
-
nodeIterator
public abstract java.util.Iterator nodeIterator() -
createIterator
protected java.util.Iterator createIterator(java.lang.Object obj)
-