org.kuali.rice.kew.xml.xstream
Class XStreamSafeEvaluator

java.lang.Object
  extended by org.kuali.rice.kew.xml.xstream.XStreamSafeEvaluator

public class XStreamSafeEvaluator
extends Object

Evaluates simple XPath expressions to follow paths through a document generated by XStream which uses "reference" elements to handle circular and duplicate references. For example, an XML document generated from XStream might look like the following:


   hello
   
     
   
 

In the above case, the XPath expression /test/a would result in the "hello" text but the XPath expression /test/b/a would result in the empty string. However, if the evaluator below is mapped as an XPath function, than it could be used as follows on the second expression to produce the desired result of "hello": xstreamsafe('/test/b/a', root())

Author:
Kuali Rice Team (rice.collab@kuali.org)

Nested Class Summary
private  class XStreamSafeEvaluator.SimpleNodeList
          A simple NodeList implementation, as simple as it gets.
private  class XStreamSafeEvaluator.XPathSegment
          A single segment of an XPath expression.
 
Field Summary
private static String MATCH_ANY
           
private static String MATCH_CURRENT
           
private static String MATCH_ROOT
           
private  XPath xpath
           
private static String XSTREAM_REFERENCE_ATTRIBUTE
           
 
Constructor Summary
XStreamSafeEvaluator()
           
XStreamSafeEvaluator(XPath xpath)
           
 
Method Summary
 NodeList evaluate(String xPathExpression, Node rootSearchNode)
          Evaluates the given XPath expression against the given Node while following reference attributes on Nodes in a way which is compatible with the XStream library.
 XPath getXpath()
           
private  void parseExpression(List segments, String xPathExpression, boolean isInitialSegment)
          Parses the given XPath expression into a List of segments which can be evaluated in order.
private  XStreamSafeEvaluator.XPathSegment parseInitialSegment(String xPathExpression)
          Parses the next segment of the given XPath expression by grabbing the first segment off of the given xpath expression.
private  XStreamSafeEvaluator.XPathSegment parseNextSegment(String xPathExpression)
          Parses the next segment of the given XPath expression by grabbing the first segment off of the given xpath expression.
private  Node resolveNodeReference(XPath xpath, Node node)
          Resolves the reference to a Node by checking for a "reference" attribute and returning the resolved node if it's there.
 void setXpath(XPath xpath)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MATCH_ANY

private static final String MATCH_ANY
See Also:
Constant Field Values

MATCH_ROOT

private static final String MATCH_ROOT
See Also:
Constant Field Values

MATCH_CURRENT

private static final String MATCH_CURRENT
See Also:
Constant Field Values

XSTREAM_REFERENCE_ATTRIBUTE

private static final String XSTREAM_REFERENCE_ATTRIBUTE
See Also:
Constant Field Values

xpath

private XPath xpath
Constructor Detail

XStreamSafeEvaluator

public XStreamSafeEvaluator()

XStreamSafeEvaluator

public XStreamSafeEvaluator(XPath xpath)
Method Detail

evaluate

public NodeList evaluate(String xPathExpression,
                         Node rootSearchNode)
                  throws XPathExpressionException
Evaluates the given XPath expression against the given Node while following reference attributes on Nodes in a way which is compatible with the XStream library.

Throws:
XPathExpressionException - if there was a problem evaluation the XPath expression.

parseExpression

private void parseExpression(List segments,
                             String xPathExpression,
                             boolean isInitialSegment)
                      throws XPathExpressionException
Parses the given XPath expression into a List of segments which can be evaluated in order.

Throws:
XPathExpressionException

parseInitialSegment

private XStreamSafeEvaluator.XPathSegment parseInitialSegment(String xPathExpression)
                                                       throws XPathExpressionException
Parses the next segment of the given XPath expression by grabbing the first segment off of the given xpath expression. The given xpath expression must start with either ./, /, or // otherwise an XPathExpressionException is thrown.

Throws:
XPathExpressionException

parseNextSegment

private XStreamSafeEvaluator.XPathSegment parseNextSegment(String xPathExpression)
                                                    throws XPathExpressionException
Parses the next segment of the given XPath expression by grabbing the first segment off of the given xpath expression. The given xpath expression must start with / otherwise an XPathExpressionException is thrown. This is because the "next" segments represent the internal pieces in an XPath expression.

Throws:
XPathExpressionException

resolveNodeReference

private Node resolveNodeReference(XPath xpath,
                                  Node node)
                           throws XPathExpressionException
Resolves the reference to a Node by checking for a "reference" attribute and returning the resolved node if it's there. The resolution happens by grabbing the value of the reference and evaluation it as an XPath expression against the given Node. If there is no reference attribute, the node passed in is returned. The method is recursive in the fact that it will continue to follow XStream "reference" attributes until it reaches a resolved node.

Throws:
XPathExpressionException

getXpath

public XPath getXpath()

setXpath

public void setXpath(XPath xpath)


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.