Clover Coverage Report - Implementation 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
14   86   8   2.8
4   40   0.57   5
5     1.6  
1    
 
  XStreamSafeSearchFunction       Line # 35 14 0% 8 23 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17    package org.kuali.rice.kew.xml.xstream;
18   
19    import java.util.List;
20   
21    import javax.xml.xpath.XPath;
22    import javax.xml.xpath.XPathExpressionException;
23    import javax.xml.xpath.XPathFunction;
24    import javax.xml.xpath.XPathFunctionException;
25   
26    import org.w3c.dom.Node;
27   
28    /**
29    * An XPathFunction which will run XStream safe XPath queries.
30    *
31    * @see XStreamSafeEvaluator
32    *
33    * @author Kuali Rice Team (rice.collab@kuali.org)
34    */
 
35    public class XStreamSafeSearchFunction implements XPathFunction {
36   
37    private final Node rootNode;
38    private XPath xpath;
39    private static XStreamSafeEvaluator evaluator = new XStreamSafeEvaluator();
40   
 
41  0 toggle public XStreamSafeSearchFunction(Node rootNode, XPath xpath) {
42  0 this.rootNode = rootNode;
43  0 this.xpath = xpath;
44    }
45   
 
46  0 toggle public Object evaluate(List parameters) throws XPathFunctionException {
47  0 String xPathExpression = getXPathExpressionParameter(parameters);
48  0 evaluator.setXpath(xpath);
49    //Node rootSearchNode = getRootSearchNodeParameter(parameters);
50  0 try {
51  0 return evaluator.evaluate(xPathExpression, rootNode);
52    } catch (XPathExpressionException e) {
53  0 throw new XPathFunctionException(e);
54    }
55    }
56   
 
57  0 toggle private String getXPathExpressionParameter(List parameters) throws XPathFunctionException {
58  0 if (parameters.size() < 1) {
59  0 throw new XPathFunctionException("First parameter must be an XPath expression.");
60    }
61  0 if (!(parameters.get(0) instanceof String)) {
62  0 throw new XPathFunctionException("First parameter must be an XPath expression String");
63    }
64  0 return (String)parameters.get(0);
65    }
66   
 
67  0 toggle public XPath getXpath() {
68  0 return xpath;
69    }
70   
 
71  0 toggle public void setXpath(XPath xpath) {
72  0 this.xpath = xpath;
73    }
74   
75    /*private Node getRootSearchNodeParameter(List parameters) throws XPathFunctionException {
76    if (parameters.size() < 2) {
77    throw new XPathFunctionException("Second parameter should be root node and is required");
78    }
79    System.out.println(parameters.get(1));
80    if (!(parameters.get(1) instanceof Node)) {
81    throw new XPathFunctionException("Second parameter should be an instance of Node (try using the root() XPath function).");
82    }
83    return (Node)parameters.get(1);
84    }*/
85   
86    }