[ 
https://issues.apache.org/jira/browse/OFBIZ-2397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12704851#action_12704851
 ] 

Scott Gray commented on OFBIZ-2397:
-----------------------------------

I was pleasantly surprised by how easy it was to write a new resolver it must 
have taken about an hour or two to get from never having looked at how JUEL 
works before to having a working POC.

Anyway if you're happy with the implementation let me know and I'll go ahead 
and commit it.  The main reason I posted it to jira was so that you could take 
a look before it went in since you're our resident JUEL expert :-)

> Implement a custom JUEL resolver for performing XPath queries on DOM Nodes
> --------------------------------------------------------------------------
>
>                 Key: OFBIZ-2397
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2397
>             Project: OFBiz
>          Issue Type: New Feature
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Scott Gray
>            Assignee: Scott Gray
>         Attachments: XPath.patch
>
>
> In order to make XML easy to read using simple methods I've implemented a 
> custom JUEL ELResolver that handles string properties for objects 
> implementing org.w3c.dom.Node and org.apache.xerces.dom.NodeImpl.  It takes 
> the String and compiles it into an XPathExpression which is then evaluated 
> against the base Node.  The JUEL evaluation returns either null, a single 
> Node or a NodeList depending on the result of the XPath evaluation.
> Type conversion is handled using the set operation like so:
> {code}
> // Get the key attribute node from the first property element, note no type 
> is specified so no conversion takes place
> <set field="attributeNode" 
> from-field="document['resource/property[1]/@key']"/>
> // ObjectType.simpleTypeConvert calls getTextContent on the node, if the 
> target type is anything other than a string it calls simpleTypeConvert again 
> using the string
> // Get the value of the attribute key from the first property element
> <set field="attributeValue" 
> from-field="document['resource/property[1]/@key']" type="String"/>
> // If the key value were an Integer you could do this, the conversion would 
> be node.getTextContent -> String -> Integer
> <set field="attributeValue" 
> from-field="document['resource/property[1]/@key']" type="Integer"/>
> {code}
> I've also added support for NodeList to the iterate tag so that you can do 
> this:
> {code:xml}
> <iterate entry="node" list="parameters.document['resource/property']">
>     <log level="always" message="Property Key: ${node['@key']}"/>
>     <log level="always" message="First Value: ${node['value[1]']}"/>
> </iterate>
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to