Package groovy.xml.slurpersupport
Class GPathResult
- java.lang.Object
- 
- groovy.lang.GroovyObjectSupport
- 
- groovy.xml.slurpersupport.GPathResult
 
 
- 
- All Implemented Interfaces:
- Buildable,- GroovyObject,- Writable,- Iterable
 - Direct Known Subclasses:
- Attribute,- NoChildren,- NodeChild,- NodeChildren
 
 public abstract class GPathResult extends GroovyObjectSupport implements Writable, Buildable, Iterable Base class for representing lazy evaluated GPath expressions.
- 
- 
Field SummaryFields Modifier and Type Field Description protected Stringnameprotected MapnamespaceMapprotected StringnamespacePrefixprotected Map<String,String>namespaceTagHintsprotected GPathResultparent
 - 
Constructor SummaryConstructors Constructor Description GPathResult(GPathResult parent, String name, String namespacePrefix, Map<String,String> namespaceTagHints)Creates a new GPathResult namednamewith the parentparent, the namespacePrefixnamespacePrefixand the namespaceTagHints specified in thenamespaceTagHintsMap.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidappendNode(Object newValue)IteratorbreadthFirst()Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.abstract IteratorchildNodes()Returns an iterator over the child nodes of this GPathResult.GPathResultchildren()Returns the children of this GPathResult as a GPathResult object.protected IteratorcreateIterator(Object obj)GPathResultdeclareNamespace(Map newNamespaceMapping)Adds the specified map of prefix to namespace mappings to this GPathResult.IteratordepthFirst()Provides an Iterator over all the nodes of this GPathResult using a depth-first traversal.booleanequals(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.ObjectgetAt(int index)Supports the subscript operator for a GPathResult.ObjectgetAt(IntRange range)Supports the range subscript operator for a GPathResult.ClosuregetBody()Creates a Closure representing the body of this GPathResult.ObjectgetProperty(String property)Returns the specified Property of this GPathResult.inthashCode()booleanisEmpty()Returns true if the GPathResult is empty, i.e.abstract Iteratoriterator()ObjectleftShift(Object newValue)Overloads the left shift operator to provide an easy way to lazily append Objects to this GPathResult.Listlist()Creates a list of objects representing this GPathResult.StringlookupNamespace(String prefix)Returns the namespace mapped to the specified prefix.Stringname()Returns the name of this GPathResult.abstract IteratornodeIterator()GPathResultparent()Returns as GPathResult with the parent nodes of the current GPathResultabstract GPathResultparents()Returns the parents of this GPathResult as aGPathResult.Objectplus(Object newValue)Lazily adds the specified Object to this GPathResult.GPathResultpop()Returns the parent of this GPathResult.voidputAt(int index, Object newValue)A helper method to allow GPathResults to work with subscript operatorsprotected abstract voidreplaceBody(Object newValue)protected abstract voidreplaceNode(Closure newValue)voidsetMetaClass(MetaClass metaClass)Replaces the MetaClass of this GPathResult.voidsetProperty(String property, Object newValue)Replaces the specified property of this GPathResult with a new value.abstract intsize()Returns the size of this GPathResult.abstract Stringtext()Returns the text of this GPathResult as aString.BigDecimaltoBigDecimal()Converts the text of this GPathResult to a BigDecimal object.BigIntegertoBigInteger()Converts the text of this GPathResult to a BigInteger object.BooleantoBoolean()Converts the text of this GPathResult to a Boolean object.DoubletoDouble()Converts the text of this GPathResult to a Double object.FloattoFloat()Converts the text of this GPathResult to a Float object.IntegertoInteger()Converts the text of this GPathResult to a Integer object.LongtoLong()Converts the text of this GPathResult to a Long object.StringtoString()Returns the text of this GPathResult.URItoURI()Converts the text of this GPathResult to a URI object.URLtoURL()Converts the text of this GPathResult to a URL object.- 
Methods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass
 - 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface groovy.lang.GroovyObjectinvokeMethod
 - 
Methods inherited from interface java.lang.IterableforEach, spliterator
 
- 
 
- 
- 
- 
Constructor Detail- 
GPathResultpublic GPathResult(GPathResult parent, String name, String namespacePrefix, Map<String,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 GPathResult
- name- if the GPathResult corresponds to something with a name, e.g. a node
- namespacePrefix- the namespace prefix if any
- namespaceTagHints- the known tag to namespace mappings
 
 
- 
 - 
Method Detail- 
setMetaClasspublic void setMetaClass(MetaClass metaClass) Replaces the MetaClass of this GPathResult.- Specified by:
- setMetaClassin interface- GroovyObject
- Overrides:
- setMetaClassin class- GroovyObjectSupport
- Parameters:
- metaClass- the new MetaClass
 
 - 
getPropertypublic Object getProperty(String property) Returns the specified Property of this GPathResult.Realizes the follow shortcuts: - '..'for- parent()
- '*'for- children()
- '**'for- depthFirst()
- '@'for attribute access
 - Specified by:
- getPropertyin interface- GroovyObject
- Parameters:
- property- the Property to fetch
- Returns:
- the given property
 
 - 
setPropertypublic void setProperty(String property, Object newValue) Replaces the specified property of this GPathResult with a new value.- Specified by:
- setPropertyin interface- GroovyObject
- Parameters:
- property- the property of this GPathResult to replace
- newValue- the new value of the property
 
 - 
leftShiftpublic Object leftShift(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
 
 - 
pluspublic Object plus(Object newValue) Lazily adds the specified Object to this GPathResult.- Parameters:
- newValue- the Object to add
- Returns:
- this
 
 - 
replaceNodeprotected abstract void replaceNode(Closure newValue) 
 - 
replaceBodyprotected abstract void replaceBody(Object newValue) 
 - 
appendNodeprotected abstract void appendNode(Object newValue) 
 - 
namepublic String name() Returns the name of this GPathResult.- Returns:
- the name of this GPathResult
 
 - 
poppublic 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
 
 - 
parentpublic GPathResult parent() Returns as GPathResult with the parent nodes of the current GPathResult- Returns:
- the parents GPathResult or thisfor the root
 
 - 
childrenpublic GPathResult children() Returns the children of this GPathResult as a GPathResult object.- Returns:
- the children of this GPathResult
 
 - 
lookupNamespacepublic String lookupNamespace(String prefix) Returns the namespace mapped to the specified prefix.- Parameters:
- prefix- the prefix lookup
- Returns:
- the namespace of the prefix
 
 - 
toStringpublic String toString() Returns the text of this GPathResult.
 - 
toIntegerpublic Integer toInteger() Converts the text of this GPathResult to a Integer object.- Returns:
- the GPathResult, converted to a Integer
 
 - 
toLongpublic Long toLong() Converts the text of this GPathResult to a Long object.- Returns:
- the GPathResult, converted to a Long
 
 - 
toFloatpublic Float toFloat() Converts the text of this GPathResult to a Float object.- Returns:
- the GPathResult, converted to a Float
 
 - 
toDoublepublic Double toDouble() Converts the text of this GPathResult to a Double object.- Returns:
- the GPathResult, converted to a Double
 
 - 
toBigDecimalpublic BigDecimal toBigDecimal() Converts the text of this GPathResult to a BigDecimal object.- Returns:
- the GPathResult, converted to a BigDecimal
 
 - 
toBigIntegerpublic BigInteger toBigInteger() Converts the text of this GPathResult to a BigInteger object.- Returns:
- the GPathResult, converted to a BigInteger
 
 - 
toURLpublic URL toURL() throws MalformedURLException Converts the text of this GPathResult to a URL object.- Returns:
- the GPathResult, converted to a URL
- Throws:
- MalformedURLException
 
 - 
toURIpublic URI toURI() throws URISyntaxException Converts the text of this GPathResult to a URI object.- Returns:
- the GPathResult, converted to a URI
- Throws:
- URISyntaxException
 
 - 
toBooleanpublic Boolean toBoolean() Converts the text of this GPathResult to a Boolean object.- Returns:
- the GPathResult, converted to a Boolean
 
 - 
declareNamespacepublic GPathResult declareNamespace(Map newNamespaceMapping) 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
 
 - 
getAtpublic 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
 
 - 
getAtpublic Object getAt(IntRange range) 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
 
 - 
putAtpublic void putAt(int index, Object newValue)A helper method to allow GPathResults to work with subscript operators- Parameters:
- index- an index
- newValue- the value to put at the given index
 
 - 
depthFirstpublic Iterator depthFirst() Provides an Iterator over all the nodes of this GPathResult using a depth-first traversal.- Returns:
- the Iteratorof (depth-first) ordered GPathResults
 
 - 
breadthFirstpublic Iterator breadthFirst() Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.- Returns:
- the Iteratorof (breadth-first) ordered GPathResults
 
 - 
listpublic List list() Creates a list of objects representing this GPathResult.- Returns:
- a list representing of this GPathResult
 
 - 
isEmptypublic 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
 
 - 
getBodypublic Closure getBody() Creates a Closure representing the body of this GPathResult.- Returns:
- the body of this GPathResult, converted to a Closure
 
 - 
sizepublic abstract int size() Returns the size of this GPathResult.- Returns:
- the size of this GPathResult
 
 - 
textpublic abstract String text() Returns the text of this GPathResult as aString.- Returns:
- the text of this GPathResult
 
 - 
parentspublic abstract 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
 
 - 
childNodespublic abstract Iterator childNodes() Returns an iterator over the child nodes of this GPathResult.- Returns:
- an iterator over the child nodes of this GPathResult
 
 - 
findpublic abstract GPathResult find(Closure closure) 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
 
 - 
findAllpublic abstract GPathResult findAll(Closure closure) 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
 
 - 
nodeIteratorpublic abstract Iterator nodeIterator() 
 
- 
 
-