guix-more/java-velocity-dont-use-werken-xpath.patch

java-velocity-dont-use-werken-xpath.patch

1
This patch was taken from the Fedora source RPM of java-velocity. It removes the dependency
2
on werken-xpath which is unmaintained since 2001, and uses jdom instead.
3
4
From 8a9344f55d74a5b809051ae144b3c028499fec0d Mon Sep 17 00:00:00 2001
5
From: Mikolaj Izdebski <mizdebsk@redhat.com>
6
Date: Sat, 27 Sep 2013 10:53:46 +0200
7
Subject: [PATCH] Don't use Werken XPath
8
9
---
10
 src/java/org/apache/velocity/anakia/AnakiaElement.java |  7 +++++--
11
 src/java/org/apache/velocity/anakia/NodeList.java      |  6 ++++--
12
 src/java/org/apache/velocity/anakia/XPathCache.java    |  9 ++++++---
13
 src/java/org/apache/velocity/anakia/XPathTool.java     | 16 ++++++++++------
14
 4 files changed, 25 insertions(+), 13 deletions(-)
15
16
diff --git a/src/java/org/apache/velocity/anakia/AnakiaElement.java b/src/java/org/apache/velocity/anakia/AnakiaElement.java
17
index c72b653..df13153 100644
18
--- a/src/java/org/apache/velocity/anakia/AnakiaElement.java
19
+++ b/src/java/org/apache/velocity/anakia/AnakiaElement.java
20
@@ -20,8 +20,10 @@ package org.apache.velocity.anakia;
21
  */
22
 
23
 import org.jdom.Element;
24
+import org.jdom.JDOMException;
25
 import org.jdom.Namespace;
26
 import org.jdom.output.XMLOutputter;
27
+
28
 import java.util.List;
29
 
30
 /**
31
@@ -126,10 +128,11 @@ public class AnakiaElement extends Element
32
      * @param xpathExpression the XPath expression you wish to apply
33
      * @return a NodeList representing the nodes that are the result of
34
      * application of the XPath to the current element. It can be empty.
35
+     * @throws JDOMException
36
      */
37
-    public NodeList selectNodes(String xpathExpression)
38
+    public NodeList selectNodes(String xpathExpression) throws JDOMException
39
     {
40
-        return new NodeList(XPathCache.getXPath(xpathExpression).applyTo(this), false);
41
+        return new NodeList(XPathCache.getXPath(xpathExpression).selectNodes(this), false);
42
     }
43
 
44
     /**
45
diff --git a/src/java/org/apache/velocity/anakia/NodeList.java b/src/java/org/apache/velocity/anakia/NodeList.java
46
index daf611d..b303bda 100644
47
--- a/src/java/org/apache/velocity/anakia/NodeList.java
48
+++ b/src/java/org/apache/velocity/anakia/NodeList.java
49
@@ -35,6 +35,7 @@ import org.jdom.DocType;
50
 import org.jdom.Document;
51
 import org.jdom.Element;
52
 import org.jdom.EntityRef;
53
+import org.jdom.JDOMException;
54
 import org.jdom.ProcessingInstruction;
55
 import org.jdom.Text;
56
 import org.jdom.output.XMLOutputter;
57
@@ -289,10 +290,11 @@ public class NodeList implements List, Cloneable
58
      * @param xpathString the XPath expression you wish to apply
59
      * @return a NodeList representing the nodes that are the result of
60
      * application of the XPath to the current node list. It can be empty.
61
+     * @throws JDOMException
62
      */
63
-    public NodeList selectNodes(String xpathString)
64
+    public NodeList selectNodes(String xpathString) throws JDOMException
65
     {
66
-        return new NodeList(XPathCache.getXPath(xpathString).applyTo(nodes), false);
67
+        return new NodeList(XPathCache.getXPath(xpathString).selectNodes(nodes), false);
68
     }
69
 
70
 // List methods implemented hereafter
71
diff --git a/src/java/org/apache/velocity/anakia/XPathCache.java b/src/java/org/apache/velocity/anakia/XPathCache.java
72
index cef43d9..0d633b0 100644
73
--- a/src/java/org/apache/velocity/anakia/XPathCache.java
74
+++ b/src/java/org/apache/velocity/anakia/XPathCache.java
75
@@ -19,7 +19,9 @@ package org.apache.velocity.anakia;
76
  * under the License.    
77
  */
78
 
79
-import com.werken.xpath.XPath;
80
+import org.jdom.JDOMException;
81
+import org.jdom.xpath.XPath;
82
+
83
 import java.util.Map;
84
 import java.util.WeakHashMap;
85
 
86
@@ -46,8 +48,9 @@ class XPathCache
87
      * A cached object is returned if it already exists for the requested expression.
88
      * @param xpathString the XPath expression to parse
89
      * @return the XPath object that represents the parsed XPath expression.
90
+     * @throws JDOMException
91
      */
92
-    static XPath getXPath(String xpathString)
93
+    static XPath getXPath(String xpathString) throws JDOMException
94
     {
95
         XPath xpath = null;
96
         synchronized(XPATH_CACHE)
97
@@ -55,7 +58,7 @@ class XPathCache
98
             xpath = (XPath)XPATH_CACHE.get(xpathString);
99
             if(xpath == null)
100
             {
101
-                xpath = new XPath(xpathString);
102
+                xpath = XPath.newInstance(xpathString);
103
                 XPATH_CACHE.put(xpathString, xpath);
104
             }
105
         }
106
diff --git a/src/java/org/apache/velocity/anakia/XPathTool.java b/src/java/org/apache/velocity/anakia/XPathTool.java
107
index c9e6178..f85d2c1 100644
108
--- a/src/java/org/apache/velocity/anakia/XPathTool.java
109
+++ b/src/java/org/apache/velocity/anakia/XPathTool.java
110
@@ -23,6 +23,7 @@ import java.util.List;
111
 
112
 import org.jdom.Document;
113
 import org.jdom.Element;
114
+import org.jdom.JDOMException;
115
 
116
 /**
117
  * This class adds an entrypoint into XPath functionality,
118
@@ -88,12 +89,13 @@ public class XPathTool
119
      * @param doc The Document context
120
      *
121
      * @return A list of selected nodes
122
+     * @throws JDOMException
123
      */
124
     public NodeList applyTo(String xpathSpec,
125
-                        Document doc)
126
+                        Document doc) throws JDOMException
127
     {
128
         //RuntimeSingleton.info("XPathTool::applyTo(String, Document)");
129
-        return new NodeList(XPathCache.getXPath(xpathSpec).applyTo( doc ), false);
130
+        return new NodeList(XPathCache.getXPath(xpathSpec).selectNodes( doc ), false);
131
     }
132
 
133
     /**
134
@@ -103,12 +105,13 @@ public class XPathTool
135
      * @param elem The Element context
136
      *
137
      * @return A list of selected nodes
138
+     * @throws JDOMException
139
      */
140
     public NodeList applyTo(String xpathSpec,
141
-                        Element elem)
142
+                        Element elem) throws JDOMException
143
     {
144
         //RuntimeSingleton.info("XPathTool::applyTo(String, Element)");
145
-        return new NodeList(XPathCache.getXPath(xpathSpec).applyTo( elem ), false);
146
+        return new NodeList(XPathCache.getXPath(xpathSpec).selectNodes( elem ), false);
147
     }
148
 
149
     /**
150
@@ -118,12 +121,13 @@ public class XPathTool
151
      * @param nodeSet The nodeset context
152
      *
153
      * @return A list of selected nodes
154
+     * @throws JDOMException
155
      */
156
     public NodeList applyTo(String xpathSpec,
157
-                        List nodeSet)
158
+                        List nodeSet) throws JDOMException
159
     {
160
         //RuntimeSingleton.info("XPathTool::applyTo(String, List)");
161
-        return new NodeList(XPathCache.getXPath(xpathSpec).applyTo( nodeSet ), false);
162
+        return new NodeList(XPathCache.getXPath(xpathSpec).selectNodes( nodeSet ), false);
163
     }
164
 }
165
 
166
-- 
167
1.8.3.1
168
169