|
|
61c284 |
From 8a9344f55d74a5b809051ae144b3c028499fec0d Mon Sep 17 00:00:00 2001
|
|
|
61c284 |
From: Mikolaj Izdebski <mizdebsk@redhat.com>
|
|
|
61c284 |
Date: Sat, 27 Sep 2013 10:53:46 +0200
|
|
|
61c284 |
Subject: [PATCH] Don't use Werken XPath
|
|
|
61c284 |
|
|
|
61c284 |
---
|
|
|
61c284 |
src/java/org/apache/velocity/anakia/AnakiaElement.java | 7 +++++--
|
|
|
61c284 |
src/java/org/apache/velocity/anakia/NodeList.java | 6 ++++--
|
|
|
61c284 |
src/java/org/apache/velocity/anakia/XPathCache.java | 9 ++++++---
|
|
|
61c284 |
src/java/org/apache/velocity/anakia/XPathTool.java | 16 ++++++++++------
|
|
|
61c284 |
4 files changed, 25 insertions(+), 13 deletions(-)
|
|
|
61c284 |
|
|
|
61c284 |
diff --git a/src/java/org/apache/velocity/anakia/AnakiaElement.java b/src/java/org/apache/velocity/anakia/AnakiaElement.java
|
|
|
61c284 |
index c72b653..df13153 100644
|
|
|
61c284 |
--- a/src/java/org/apache/velocity/anakia/AnakiaElement.java
|
|
|
61c284 |
+++ b/src/java/org/apache/velocity/anakia/AnakiaElement.java
|
|
|
61c284 |
@@ -20,8 +20,10 @@ package org.apache.velocity.anakia;
|
|
|
61c284 |
*/
|
|
|
61c284 |
|
|
|
61c284 |
import org.jdom.Element;
|
|
|
61c284 |
+import org.jdom.JDOMException;
|
|
|
61c284 |
import org.jdom.Namespace;
|
|
|
61c284 |
import org.jdom.output.XMLOutputter;
|
|
|
61c284 |
+
|
|
|
61c284 |
import java.util.List;
|
|
|
61c284 |
|
|
|
61c284 |
/**
|
|
|
61c284 |
@@ -126,10 +128,11 @@ public class AnakiaElement extends Element
|
|
|
61c284 |
* @param xpathExpression the XPath expression you wish to apply
|
|
|
61c284 |
* @return a NodeList representing the nodes that are the result of
|
|
|
61c284 |
* application of the XPath to the current element. It can be empty.
|
|
|
61c284 |
+ * @throws JDOMException
|
|
|
61c284 |
*/
|
|
|
61c284 |
- public NodeList selectNodes(String xpathExpression)
|
|
|
61c284 |
+ public NodeList selectNodes(String xpathExpression) throws JDOMException
|
|
|
61c284 |
{
|
|
|
61c284 |
- return new NodeList(XPathCache.getXPath(xpathExpression).applyTo(this), false);
|
|
|
61c284 |
+ return new NodeList(XPathCache.getXPath(xpathExpression).selectNodes(this), false);
|
|
|
61c284 |
}
|
|
|
61c284 |
|
|
|
61c284 |
/**
|
|
|
61c284 |
diff --git a/src/java/org/apache/velocity/anakia/NodeList.java b/src/java/org/apache/velocity/anakia/NodeList.java
|
|
|
61c284 |
index daf611d..b303bda 100644
|
|
|
61c284 |
--- a/src/java/org/apache/velocity/anakia/NodeList.java
|
|
|
61c284 |
+++ b/src/java/org/apache/velocity/anakia/NodeList.java
|
|
|
61c284 |
@@ -35,6 +35,7 @@ import org.jdom.DocType;
|
|
|
61c284 |
import org.jdom.Document;
|
|
|
61c284 |
import org.jdom.Element;
|
|
|
61c284 |
import org.jdom.EntityRef;
|
|
|
61c284 |
+import org.jdom.JDOMException;
|
|
|
61c284 |
import org.jdom.ProcessingInstruction;
|
|
|
61c284 |
import org.jdom.Text;
|
|
|
61c284 |
import org.jdom.output.XMLOutputter;
|
|
|
61c284 |
@@ -289,10 +290,11 @@ public class NodeList implements List, Cloneable
|
|
|
61c284 |
* @param xpathString the XPath expression you wish to apply
|
|
|
61c284 |
* @return a NodeList representing the nodes that are the result of
|
|
|
61c284 |
* application of the XPath to the current node list. It can be empty.
|
|
|
61c284 |
+ * @throws JDOMException
|
|
|
61c284 |
*/
|
|
|
61c284 |
- public NodeList selectNodes(String xpathString)
|
|
|
61c284 |
+ public NodeList selectNodes(String xpathString) throws JDOMException
|
|
|
61c284 |
{
|
|
|
61c284 |
- return new NodeList(XPathCache.getXPath(xpathString).applyTo(nodes), false);
|
|
|
61c284 |
+ return new NodeList(XPathCache.getXPath(xpathString).selectNodes(nodes), false);
|
|
|
61c284 |
}
|
|
|
61c284 |
|
|
|
61c284 |
// List methods implemented hereafter
|
|
|
61c284 |
diff --git a/src/java/org/apache/velocity/anakia/XPathCache.java b/src/java/org/apache/velocity/anakia/XPathCache.java
|
|
|
61c284 |
index cef43d9..0d633b0 100644
|
|
|
61c284 |
--- a/src/java/org/apache/velocity/anakia/XPathCache.java
|
|
|
61c284 |
+++ b/src/java/org/apache/velocity/anakia/XPathCache.java
|
|
|
61c284 |
@@ -19,7 +19,9 @@ package org.apache.velocity.anakia;
|
|
|
61c284 |
* under the License.
|
|
|
61c284 |
*/
|
|
|
61c284 |
|
|
|
61c284 |
-import com.werken.xpath.XPath;
|
|
|
61c284 |
+import org.jdom.JDOMException;
|
|
|
61c284 |
+import org.jdom.xpath.XPath;
|
|
|
61c284 |
+
|
|
|
61c284 |
import java.util.Map;
|
|
|
61c284 |
import java.util.WeakHashMap;
|
|
|
61c284 |
|
|
|
61c284 |
@@ -46,8 +48,9 @@ class XPathCache
|
|
|
61c284 |
* A cached object is returned if it already exists for the requested expression.
|
|
|
61c284 |
* @param xpathString the XPath expression to parse
|
|
|
61c284 |
* @return the XPath object that represents the parsed XPath expression.
|
|
|
61c284 |
+ * @throws JDOMException
|
|
|
61c284 |
*/
|
|
|
61c284 |
- static XPath getXPath(String xpathString)
|
|
|
61c284 |
+ static XPath getXPath(String xpathString) throws JDOMException
|
|
|
61c284 |
{
|
|
|
61c284 |
XPath xpath = null;
|
|
|
61c284 |
synchronized(XPATH_CACHE)
|
|
|
61c284 |
@@ -55,7 +58,7 @@ class XPathCache
|
|
|
61c284 |
xpath = (XPath)XPATH_CACHE.get(xpathString);
|
|
|
61c284 |
if(xpath == null)
|
|
|
61c284 |
{
|
|
|
61c284 |
- xpath = new XPath(xpathString);
|
|
|
61c284 |
+ xpath = XPath.newInstance(xpathString);
|
|
|
61c284 |
XPATH_CACHE.put(xpathString, xpath);
|
|
|
61c284 |
}
|
|
|
61c284 |
}
|
|
|
61c284 |
diff --git a/src/java/org/apache/velocity/anakia/XPathTool.java b/src/java/org/apache/velocity/anakia/XPathTool.java
|
|
|
61c284 |
index c9e6178..f85d2c1 100644
|
|
|
61c284 |
--- a/src/java/org/apache/velocity/anakia/XPathTool.java
|
|
|
61c284 |
+++ b/src/java/org/apache/velocity/anakia/XPathTool.java
|
|
|
61c284 |
@@ -23,6 +23,7 @@ import java.util.List;
|
|
|
61c284 |
|
|
|
61c284 |
import org.jdom.Document;
|
|
|
61c284 |
import org.jdom.Element;
|
|
|
61c284 |
+import org.jdom.JDOMException;
|
|
|
61c284 |
|
|
|
61c284 |
/**
|
|
|
61c284 |
* This class adds an entrypoint into XPath functionality,
|
|
|
61c284 |
@@ -88,12 +89,13 @@ public class XPathTool
|
|
|
61c284 |
* @param doc The Document context
|
|
|
61c284 |
*
|
|
|
61c284 |
* @return A list of selected nodes
|
|
|
61c284 |
+ * @throws JDOMException
|
|
|
61c284 |
*/
|
|
|
61c284 |
public NodeList applyTo(String xpathSpec,
|
|
|
61c284 |
- Document doc)
|
|
|
61c284 |
+ Document doc) throws JDOMException
|
|
|
61c284 |
{
|
|
|
61c284 |
//RuntimeSingleton.info("XPathTool::applyTo(String, Document)");
|
|
|
61c284 |
- return new NodeList(XPathCache.getXPath(xpathSpec).applyTo( doc ), false);
|
|
|
61c284 |
+ return new NodeList(XPathCache.getXPath(xpathSpec).selectNodes( doc ), false);
|
|
|
61c284 |
}
|
|
|
61c284 |
|
|
|
61c284 |
/**
|
|
|
61c284 |
@@ -103,12 +105,13 @@ public class XPathTool
|
|
|
61c284 |
* @param elem The Element context
|
|
|
61c284 |
*
|
|
|
61c284 |
* @return A list of selected nodes
|
|
|
61c284 |
+ * @throws JDOMException
|
|
|
61c284 |
*/
|
|
|
61c284 |
public NodeList applyTo(String xpathSpec,
|
|
|
61c284 |
- Element elem)
|
|
|
61c284 |
+ Element elem) throws JDOMException
|
|
|
61c284 |
{
|
|
|
61c284 |
//RuntimeSingleton.info("XPathTool::applyTo(String, Element)");
|
|
|
61c284 |
- return new NodeList(XPathCache.getXPath(xpathSpec).applyTo( elem ), false);
|
|
|
61c284 |
+ return new NodeList(XPathCache.getXPath(xpathSpec).selectNodes( elem ), false);
|
|
|
61c284 |
}
|
|
|
61c284 |
|
|
|
61c284 |
/**
|
|
|
61c284 |
@@ -118,12 +121,13 @@ public class XPathTool
|
|
|
61c284 |
* @param nodeSet The nodeset context
|
|
|
61c284 |
*
|
|
|
61c284 |
* @return A list of selected nodes
|
|
|
61c284 |
+ * @throws JDOMException
|
|
|
61c284 |
*/
|
|
|
61c284 |
public NodeList applyTo(String xpathSpec,
|
|
|
61c284 |
- List nodeSet)
|
|
|
61c284 |
+ List nodeSet) throws JDOMException
|
|
|
61c284 |
{
|
|
|
61c284 |
//RuntimeSingleton.info("XPathTool::applyTo(String, List)");
|
|
|
61c284 |
- return new NodeList(XPathCache.getXPath(xpathSpec).applyTo( nodeSet ), false);
|
|
|
61c284 |
+ return new NodeList(XPathCache.getXPath(xpathSpec).selectNodes( nodeSet ), false);
|
|
|
61c284 |
}
|
|
|
61c284 |
}
|
|
|
61c284 |
|
|
|
61c284 |
--
|
|
|
61c284 |
1.8.3.1
|
|
|
61c284 |
|