This is an automated email from the ASF dual-hosted git repository.
cbrisson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/velocity-engine.git
The following commit(s) were added to refs/heads/master by this push:
new 4d797017 Get rid of jdom usage in favor of dom4j in the xml example,
to avoid security alert
4d797017 is described below
commit 4d797017c8484eb9fa9b42a3b5cb78780ea2183d
Author: Claude Brisson <[email protected]>
AuthorDate: Sun Mar 26 16:21:03 2023 +0200
Get rid of jdom usage in favor of dom4j in the xml example, to avoid
security alert
---
velocity-engine-examples/README.md | 2 +-
velocity-engine-examples/pom.xml | 6 +++---
.../java/org/apache/velocity/example/XMLTest.java | 15 +++++++++------
velocity-engine-examples/src/main/resources/xml.vm | 20 ++++++++++----------
4 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/velocity-engine-examples/README.md
b/velocity-engine-examples/README.md
index 6ea1d51d..ad8ece8e 100644
--- a/velocity-engine-examples/README.md
+++ b/velocity-engine-examples/README.md
@@ -22,7 +22,7 @@ The archive contains a `build.sh` script which you can use to
re-build the examp
## Running the examples
-Once you have downloaded or sucessfully built the
${project.build.finalName}-pkg.zip downloaded package, unzip it in the location
of your choice and change to the ${project.build.finalName} directory.
+Once you have downloaded or successfully built the
${project.build.finalName}-pkg.zip downloaded package, unzip it in the location
of your choice and change to the ${project.build.finalName} directory.
Note for Windows users: the shell scripts used to running the examples are
meant for linux or BSD, but can easily be adapted as batch files. all they do
is build the classpath from the jars in the lib/ directory, then invoke Java on
the main class with the adequate arguments.
diff --git a/velocity-engine-examples/pom.xml b/velocity-engine-examples/pom.xml
index cff04136..028b0450 100644
--- a/velocity-engine-examples/pom.xml
+++ b/velocity-engine-examples/pom.xml
@@ -97,9 +97,9 @@ under the License.
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.jdom</groupId>
- <artifactId>jdom</artifactId>
- <version>1.1.3</version>
+ <groupId>org.dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
diff --git
a/velocity-engine-examples/src/main/java/org/apache/velocity/example/XMLTest.java
b/velocity-engine-examples/src/main/java/org/apache/velocity/example/XMLTest.java
index 78cba681..bbff36c3 100644
---
a/velocity-engine-examples/src/main/java/org/apache/velocity/example/XMLTest.java
+++
b/velocity-engine-examples/src/main/java/org/apache/velocity/example/XMLTest.java
@@ -21,13 +21,15 @@ package org.apache.velocity.example;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
-
-import org.jdom.Document;
-import org.jdom.input.SAXBuilder;
+import org.dom4j.Document;
+import org.dom4j.io.SAXReader;
import java.io.BufferedWriter;
+import java.io.FileInputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.file.Files;
+import java.nio.file.Paths;
/**
@@ -55,13 +57,14 @@ public class XMLTest
* build a Document from our xml
*/
- SAXBuilder builder;
+
+ SAXReader reader;
Document root = null;
try
{
- builder = new SAXBuilder();
- root = builder.build("test.xml");
+ reader = new SAXReader();
+ root =
reader.read(Files.newInputStream(Paths.get("test.xml")));
}
catch( Exception ee)
{
diff --git a/velocity-engine-examples/src/main/resources/xml.vm
b/velocity-engine-examples/src/main/resources/xml.vm
index 366b79b1..cb094d73 100644
--- a/velocity-engine-examples/src/main/resources/xml.vm
+++ b/velocity-engine-examples/src/main/resources/xml.vm
@@ -15,16 +15,16 @@
## specific language governing permissions and limitations
## under the License.
#macro ( recursive $e $indent )
-#if( $e.getChildren().size() > 0 )
-$indent <$e.getName()>
-#foreach ($child in $e.getChildren() )
+#if( $e.elements().size() > 0 )
+$indent <$e.name>
+#foreach ($child in $e.elements() )
#recursive( $child "$indent " )
#end
-$indent </$e.getName()>
+$indent </$e.name>
#else
-$indent <$e.getName()>
-$indent $e.getTextTrim()
-$indent </$e.getName()>
+$indent <$e.name>
+$indent $e.text.trim()
+$indent </$e.name>
#end
#end
@@ -33,10 +33,10 @@ $indent </$e.getName()>
First, we print out the document tree with a
recursive Velocimacro :
-#recursive( $root.getRootElement() $i )
+#recursive( $root.rootElement $i )
Next, we access pieces of data directly :
-email :
$root.getRootElement().getChild("properties").getChild("author").getChild("email").getText()
-last name :
$root.getRootElement().getChild("properties").getChild("author").getChild("name").getChild("last").getChild("full").getText()
+email :
$root.rootElement.element("properties").element("author").element("email").text
+last name :
$root.rootElement.element("properties").element("author").element("name").element("last").element("full").text