aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-examples
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2019-12-14 12:20:11 +0000
committerClaude Brisson <cbrisson@apache.org>2019-12-14 12:20:11 +0000
commitf6204fa7640f9d6bb35555696197cd62fe59e828 (patch)
treec50903f511ee5b7657eb325b78633a35c233ffe6 /velocity-engine-examples
parentfab16d580f7fee1ce96fbd8a6dbc34d99dccf3d3 (diff)
downloadapache-velocity-engine-f6204fa7640f9d6bb35555696197cd62fe59e828.tar.gz
[engine] Refresh examples packaging
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1871468 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-examples')
-rw-r--r--velocity-engine-examples/README.md83
-rw-r--r--velocity-engine-examples/pom.xml77
-rw-r--r--velocity-engine-examples/src/assembly/examples.xml62
-rw-r--r--velocity-engine-examples/src/etc/README.txt81
-rw-r--r--velocity-engine-examples/src/etc/app_example1/README.txt31
-rw-r--r--velocity-engine-examples/src/etc/app_example1/appendVELCP.bat19
-rw-r--r--velocity-engine-examples/src/etc/app_example1/example.bat29
-rw-r--r--velocity-engine-examples/src/etc/app_example2/README.txt33
-rw-r--r--velocity-engine-examples/src/etc/app_example2/appendVELCP.bat19
-rw-r--r--velocity-engine-examples/src/etc/app_example2/example2.bat29
-rw-r--r--velocity-engine-examples/src/etc/build.sh40
-rw-r--r--velocity-engine-examples/src/etc/context_example/README.txt32
-rwxr-xr-xvelocity-engine-examples/src/etc/dbcontexttest.sh (renamed from velocity-engine-examples/src/etc/context_example/dbcontexttest.sh)28
-rw-r--r--velocity-engine-examples/src/etc/event_example/README.txt37
-rwxr-xr-xvelocity-engine-examples/src/etc/example1.sh (renamed from velocity-engine-examples/src/etc/app_example1/example.sh)28
-rwxr-xr-xvelocity-engine-examples/src/etc/example2.sh (renamed from velocity-engine-examples/src/etc/app_example2/example2.sh)26
-rwxr-xr-xvelocity-engine-examples/src/etc/xmlapp_example.sh (renamed from velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.sh)27
-rw-r--r--velocity-engine-examples/src/etc/xmlapp_example/README.txt28
-rw-r--r--velocity-engine-examples/src/etc/xmlapp_example/appendVELCP.bat19
-rw-r--r--velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.bat29
-rw-r--r--velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java45
-rw-r--r--velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java34
-rw-r--r--velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java2
-rw-r--r--velocity-engine-examples/src/main/resources/example1.vm (renamed from velocity-engine-examples/src/main/resources/example.vm)0
-rw-r--r--velocity-engine-examples/src/main/resources/velocity.properties5
25 files changed, 334 insertions, 509 deletions
diff --git a/velocity-engine-examples/README.md b/velocity-engine-examples/README.md
new file mode 100644
index 00000000..6ea1d51d
--- /dev/null
+++ b/velocity-engine-examples/README.md
@@ -0,0 +1,83 @@
+# Welcome to Velocity!
+
+This package contains a few examples to help get you started.
+
+As always, the if you have any questions :
+
+1. Make sure you followed any directions :-) (did you build
+ everything?)
+
+2. Review documentation included in this package, or online at
+ [https://velocity.apache.org/](https://velocity.apache.org/)
+
+3. Ask on the [velocity-user list](https://velocity.apache.org/contact.html#user).
+ This is a great source of support information. To join, read the
+ [contact page](https://velocity.apache.org/contact.html) and then follow the links to join the lists.
+
+## Building from sources
+
+To build these examples from Velocity sources, please refer to the [Velocity build page](https://velocity.apache.org/engine/${project.version}/build.html). The build will generate the zip archive target/${project.build.finalName}-pkg.zip containing all the examples.
+
+The archive contains a `build.sh` script which you can use to re-build the examples after tweaking the sources in the `src` directory.
+
+## 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.
+
+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.
+
+Finally, note that more examples of using Velocity can be found in the velocity-tools subject. Of special note is the VelocityViewServlet, a quick and easy way to build a web application that uses Velocity.
+
+ https://velocity.apache.org/tools/
+
+# Velocity Examples
+
+## Application Example #1
+
+This simple example shows how to use the Velocity Template Engine
+in a standalone program. It should be pre-compiled for you. Run it using the example
+template provided (`example.vm`):
+
+ ./example1.sh
+
+## Application Example #2
+
+Another simple example showing how to use Velocity in a standalone
+program. This examples uses the org.apache.velocity.util.Velocity application utility
+class, which provides a few convenient methods for application programmers. It also
+should be precompiled for you. To run:
+
+ ./example2.sh
+
+## Context Example
+
+This is a demonstration of 2 different context implementations:
+
+- a context implementation that uses a database as the storage. You will need to copy the appropriate JDBC driver jar file in the lib/ directory, and to adapt the JDBC driver and credentials accordingly in the `src/org/apache/velocity/example/DBContextTest.java` file.
+
+- a context implementation that uses a `TreeMap` for storage. Very simple.
+
+To run:
+
+ ./dbcontexttest.sh
+
+## Xml App example
+
+This is simple example that demonstrates direct access of XML data via
+Velocity templates, as well as Velocimacro recursion. To run:
+
+ ./xmlapp_example.sh
+
+## Event Example
+
+This is a simple yet more advanced example, and shows how to use the event handling
+features of Velocity. This is an advanced topic, so if you are just
+starting with Velocity, you can come back to it later. To run:
+
+ ./event_example.sh
+
+___
+
+Thanks for using Velocity!
+
+>the Velocity team
diff --git a/velocity-engine-examples/pom.xml b/velocity-engine-examples/pom.xml
index 8c5544e2..9f3dd7dc 100644
--- a/velocity-engine-examples/pom.xml
+++ b/velocity-engine-examples/pom.xml
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -26,7 +26,7 @@
<artifactId>velocity-engine-parent</artifactId>
<version>2.2-SNAPSHOT</version>
</parent>
-
+
<artifactId>velocity-engine-examples</artifactId>
<name>Apache Velocity Engine - Examples</name>
<description>Very simple examples to use Velocity</description>
@@ -37,7 +37,48 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <configuration>
+ <outputDirectory>${project.build.directory}/examples</outputDirectory>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/examples.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </plugin>
</plugins>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ <resource>
+ <directory>src/etc</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
</build>
<dependencies>
@@ -51,5 +92,11 @@
<artifactId>jdom</artifactId>
<version>1.1.3</version>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/velocity-engine-examples/src/assembly/examples.xml b/velocity-engine-examples/src/assembly/examples.xml
new file mode 100644
index 00000000..210fd420
--- /dev/null
+++ b/velocity-engine-examples/src/assembly/examples.xml
@@ -0,0 +1,62 @@
+<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+ <id>pkg</id>
+ <baseDirectory>${project.build.directory}</baseDirectory>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <fileSets>
+ <!-- copy dependencies to lib/ -->
+ <fileSet>
+ <directory>${project.build.directory}</directory>
+ <outputDirectory>${project.build.finalName}</outputDirectory>
+ <includes>
+ <include>lib/*.jar</include>
+ </includes>
+ </fileSet>
+ <!-- copy self jar to lib/ -->
+ <fileSet>
+ <directory>${project.build.directory}</directory>
+ <outputDirectory>${project.build.finalName}/lib</outputDirectory>
+ <includes>
+ <include>${project.build.finalName}.jar</include>
+ </includes>
+ </fileSet>
+ <!-- copy examples resources -->
+ <fileSet>
+ <directory>${project.build.directory}/examples</directory>
+ <outputDirectory>${project.build.finalName}</outputDirectory>
+ <includes>
+ <include>*.vm</include>
+ <include>*.xml</include>
+ <include>*.properties</include>
+ </includes>
+ </fileSet>
+ <!-- copy examples scripts -->
+ <fileSet>
+ <directory>${project.build.directory}/examples</directory>
+ <outputDirectory>${project.build.finalName}</outputDirectory>
+ <fileMode>0755</fileMode>
+ <includes>
+ <include>*.sh</include>
+ </includes>
+ </fileSet>
+ <!-- copy readme file -->
+ <fileSet>
+ <directory>${project.basedir}</directory>
+ <outputDirectory>${project.build.finalName}</outputDirectory>
+ <includes>
+ <include>README.md</include>
+ </includes>
+ </fileSet>
+ <!-- copy sources -->
+ <fileSet>
+ <directory>${project.basedir}/src/main/java</directory>
+ <outputDirectory>${project.build.finalName}/src</outputDirectory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</assembly>
diff --git a/velocity-engine-examples/src/etc/README.txt b/velocity-engine-examples/src/etc/README.txt
deleted file mode 100644
index a573ec34..00000000
--- a/velocity-engine-examples/src/etc/README.txt
+++ /dev/null
@@ -1,81 +0,0 @@
-Welcome to Velocity!
-
-This directory contains a few examples to help get you started.
-
-As always, the if you have any questions :
-
-1) Make sure you followed any directions :-) (did you build
- everything?)
-
-2) Review documentation included in this package, or online at
- http://velocity.apache.org/
-
-3) Ask on the velocity-user list. This is a great source of support
- information. To join, read http://velocity.apache.org/contact.html
- and then follow the links to join the lists.
-
-
-These examples are very easy to build, but there is a prerequisite for
-building any Velocity software, installing Apache ant, which can be
-downloaded from
-
- http://ant.apache.org/
-
-Change to the /build directory in the Velocity distribution and then type:
-
- ant examples
-
-This will invoke ant and tell it to build the examples for you.
-
-Finally, note that more examples of using Velocity can be found in the
-Velocity-Tools subject. Of special note is the VelocityViewServlet,
-a quick and easy way to build a web application that uses Velocity.
-
- http://velocity.apache.org/tools/
-
-
-Velocity Examples
-=================
-
-app_example1
-------------
-This simple example shows how to use the Velocity Template Engine
-in a standalone program. It should be pre-compiled for you. Run it using the example
-template provided (example.vm):
-
- ./example.sh
-
-app_example2
-------------
-Another simple example showing how to use Velocity in a standalone
-program. This examples uses the org.apache.velocity.util.Velocity application utility
-class, which provides a few convenient methods for application programmers. It also
-should be precompiled for you. To run :
-
- ./example2.sh
-
-context_example
---------------
-This is a demonstration of 2 different context implementations :
- - a context implementation that uses a database as the storage.
- Use the DBContextTest program to test. See the DBContextTest.java file for the
- db table info. Unsupported demonstration code. You may need to futz with
- it to get it to work in your environment. To run, use the dbcontexttest.sh
- script.
- - a context implementation that uses a TreeMap for storage. Very simple.
-
-xmlapp_example
---------------
-This is simple example that demonstrates direct access of XML data via
-Velocity templates, as well as Velocimacro recursion.
-
-event_example
--------------
-This is a more advanced example, and shows how to use the event handling
-features of Velocity. This is an advanced topic, so if you are just
-starting with Velocity, you can come back to it later.
-
-
-Thanks for using Velocity!
-
-- the Velocity team
diff --git a/velocity-engine-examples/src/etc/app_example1/README.txt b/velocity-engine-examples/src/etc/app_example1/README.txt
deleted file mode 100644
index a122aa69..00000000
--- a/velocity-engine-examples/src/etc/app_example1/README.txt
+++ /dev/null
@@ -1,31 +0,0 @@
-Welcome to Velocity!
-
-This directory contains a few examples to help get you started.
-
-As always, the if you have any questions :
-
-1) Make sure you followed any directions :-) (did you build
- everything?)
-
-2) Review documentation included in this package, or online at
- http://velocity.apache.org/
-
-3) Ask on the velocity-user list. This is a great source of support
- information. To join, read http://velocity.apache.org/contact.html
- and then follow the links to join the lists.
-
-
-app_example1
-------------
-
-This simple example shows how to use the Velocity Template Engine
-in a standalone program. To build this example, see the instructions
-in the examples/README.txt file.
-
-Run it using the example template provided (example.vm):
-
- ./example.sh
-
-or
-
- example.bat
diff --git a/velocity-engine-examples/src/etc/app_example1/appendVELCP.bat b/velocity-engine-examples/src/etc/app_example1/appendVELCP.bat
deleted file mode 100644
index 6fb3c6e2..00000000
--- a/velocity-engine-examples/src/etc/app_example1/appendVELCP.bat
+++ /dev/null
@@ -1,19 +0,0 @@
-@echo off
-rem Licensed to the Apache Software Foundation (ASF) under one
-rem or more contributor license agreements. See the NOTICE file
-rem distributed with this work for additional information
-rem regarding copyright ownership. The ASF licenses this file
-rem to you under the Apache License, Version 2.0 (the
-rem "License"); you may not use this file except in compliance
-rem with the License. You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing,
-rem software distributed under the License is distributed on an
-rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-rem KIND, either express or implied. See the License for the
-rem specific language governing permissions and limitations
-rem under the License.
-
-set VELCP=%VELCP%;%1
diff --git a/velocity-engine-examples/src/etc/app_example1/example.bat b/velocity-engine-examples/src/etc/app_example1/example.bat
deleted file mode 100644
index 5525a91f..00000000
--- a/velocity-engine-examples/src/etc/app_example1/example.bat
+++ /dev/null
@@ -1,29 +0,0 @@
-@echo off
-rem Licensed to the Apache Software Foundation (ASF) under one
-rem or more contributor license agreements. See the NOTICE file
-rem distributed with this work for additional information
-rem regarding copyright ownership. The ASF licenses this file
-rem to you under the Apache License, Version 2.0 (the
-rem "License"); you may not use this file except in compliance
-rem with the License. You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing,
-rem software distributed under the License is distributed on an
-rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-rem KIND, either express or implied. See the License for the
-rem specific language governing permissions and limitations
-rem under the License.
-
-set VELCP=.
-
-for %%i in (..\lib\*.jar) do call appendVELCP %%i
-for %%i in (..\*.jar) do call appendVELCP %%i
-for %%i in (..\..\lib\*.jar) do call appendVELCP %%i
-for %%i in (..\..\*.jar) do call appendVELCP %%i
-
-echo Using classpath: %VELCP%
-
-java -cp %VELCP% org.apache.velocity.example.Example example.vm
-
diff --git a/velocity-engine-examples/src/etc/app_example2/README.txt b/velocity-engine-examples/src/etc/app_example2/README.txt
deleted file mode 100644
index 1abd0e92..00000000
--- a/velocity-engine-examples/src/etc/app_example2/README.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-Welcome to Velocity!
-
-This directory contains a few examples to help get you started.
-
-As always, the if you have any questions :
-
-1) Make sure you followed any directions :-) (did you build
- everything?)
-
-2) Review documentation included in this package, or online at
- http://velocity.apache.org/
-
-3) Ask on the velocity-user list. This is a great source of support
- information. To join, read http://velocity.apache.org/contact.html
- and then follow the links to join the lists.
-
-
-app_example2
-------------
-
-Another simple example showing how to use Velocity in a standalone
-program. This examples uses the org.apache.velocity.util.Velocity application utility
-class, which provides a few convenient methods for application programmers.
-
-Please see the build instructions found in examples/README.txt
-
-To run :
-
- ./example2.sh
-
-or
-
- example2.bat
diff --git a/velocity-engine-examples/src/etc/app_example2/appendVELCP.bat b/velocity-engine-examples/src/etc/app_example2/appendVELCP.bat
deleted file mode 100644
index 6fb3c6e2..00000000
--- a/velocity-engine-examples/src/etc/app_example2/appendVELCP.bat
+++ /dev/null
@@ -1,19 +0,0 @@
-@echo off
-rem Licensed to the Apache Software Foundation (ASF) under one
-rem or more contributor license agreements. See the NOTICE file
-rem distributed with this work for additional information
-rem regarding copyright ownership. The ASF licenses this file
-rem to you under the Apache License, Version 2.0 (the
-rem "License"); you may not use this file except in compliance
-rem with the License. You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing,
-rem software distributed under the License is distributed on an
-rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-rem KIND, either express or implied. See the License for the
-rem specific language governing permissions and limitations
-rem under the License.
-
-set VELCP=%VELCP%;%1
diff --git a/velocity-engine-examples/src/etc/app_example2/example2.bat b/velocity-engine-examples/src/etc/app_example2/example2.bat
deleted file mode 100644
index 567d8cec..00000000
--- a/velocity-engine-examples/src/etc/app_example2/example2.bat
+++ /dev/null
@@ -1,29 +0,0 @@
-@echo off
-rem Licensed to the Apache Software Foundation (ASF) under one
-rem or more contributor license agreements. See the NOTICE file
-rem distributed with this work for additional information
-rem regarding copyright ownership. The ASF licenses this file
-rem to you under the Apache License, Version 2.0 (the
-rem "License"); you may not use this file except in compliance
-rem with the License. You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing,
-rem software distributed under the License is distributed on an
-rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-rem KIND, either express or implied. See the License for the
-rem specific language governing permissions and limitations
-rem under the License.
-
-set VELCP=.
-
-for %%i in (..\lib\*.jar) do call appendVELCP %%i
-for %%i in (..\*.jar) do call appendVELCP %%i
-for %%i in (..\..\lib\*.jar) do call appendVELCP %%i
-for %%i in (..\..\*.jar) do call appendVELCP %%i
-
-echo Using classpath: %VELCP%
-
-java -cp %VELCP% org.apache.velocity.example.Example2
-
diff --git a/velocity-engine-examples/src/etc/build.sh b/velocity-engine-examples/src/etc/build.sh
new file mode 100644
index 00000000..81652a4f
--- /dev/null
+++ b/velocity-engine-examples/src/etc/build.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+echo "Building examples..."
+
+echo rm lib/${project.build.finalName}.jar
+rm lib/${project.build.finalName}.jar
+
+_VELCP=.
+for i in lib/*.jar
+do
+ _VELCP="$_VELCP:$i"
+done
+
+# convert the unix path to windows
+if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then
+ _VELCP=`cygpath --path --windows "$_VELCP"`
+fi
+
+echo "Using classpath $_VELCP"
+
+find src -name "*.java" > sources.txt
+mkdir classes
+javac -cp $_VELCP -d classes @sources.txt && jar cf lib/${project.build.finalName}.jar -C classes . && echo "Build successful."
diff --git a/velocity-engine-examples/src/etc/context_example/README.txt b/velocity-engine-examples/src/etc/context_example/README.txt
deleted file mode 100644
index 082d3f18..00000000
--- a/velocity-engine-examples/src/etc/context_example/README.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-Welcome to Velocity!
-
-This directory contains a few examples to help get you started.
-
-As always, the if you have any questions :
-
-1) Make sure you followed any directions :-) (did you build
- everything?)
-
-2) Review documentation included in this package, or online at
- http://velocity.apache.org/
-
-3) Ask on the velocity-user list. This is a great source of support
- information. To join, read http://velocity.apache.org/contact.html
- and then follow the links to join the lists.
-
-
-context_example
----------------
-
-This is a demonstration of 2 different context implementations :
- - a context implementation that uses a database as the storage.
- Use the DBContextTest program to test. See the DBContextTest.java file for the
- db table info. Unsupported demonstration code. You may need to futz with
- it to get it to work in your environment. To run, use the dbcontexttest.sh
- script.
- - a context implementation that uses a TreeMap for storage. Very simple.
-
-
-Thanks for using Velocity!
-
-- the Velocity team
diff --git a/velocity-engine-examples/src/etc/context_example/dbcontexttest.sh b/velocity-engine-examples/src/etc/dbcontexttest.sh
index 1c402c76..26c56e21 100755
--- a/velocity-engine-examples/src/etc/context_example/dbcontexttest.sh
+++ b/velocity-engine-examples/src/etc/dbcontexttest.sh
@@ -1,4 +1,4 @@
-# !/bin/sh
+#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,30 +17,24 @@
# specific language governing permissions and limitations
# under the License.
-echo "DBContextTest : please ensure MySQL is set up and jdbc drivers are in classpath. See DBContextTest.java for clues"
+echo "DBContextTest : please ensure your DB engine is set up and jdbc drivers are in classpath. See DBContextTest.java for clues."
echo "This is an unsupported demo."
-_VELCP=.
+echo "Running DBContextTest with input file 'dbtest.vm'"
-for i in ../lib/*.jar
+_VELCP=.
+for i in lib/*.jar
do
- _VELCP=$_VELCP:"$i"
+ _VELCP="$_VELCP:$i"
done
-for i in ../*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
+# convert the unix path to windows
+if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then
+ _VELCP=`cygpath --path --windows "$_VELCP"`
+fi
-for i in ../../lib/*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
+echo "Using classpath $_VELCP"
-for i in ../../*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
java -cp $_VELCP org.apache.velocity.example.DBContextTest dbtest.vm
diff --git a/velocity-engine-examples/src/etc/event_example/README.txt b/velocity-engine-examples/src/etc/event_example/README.txt
deleted file mode 100644
index fe39e877..00000000
--- a/velocity-engine-examples/src/etc/event_example/README.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-Welcome to Velocity!
-
-As always, the if you have any questions :
-
-1) Make sure you followed any directions :) (did you build everything?)
-2) Review documentation included in this package, or online at
- http://jakarta.apache.org/velocity/
-3) Ask on the velocity-user list. This is a great source of support information.
- To join, read http://jakarta.apache.org/site/mail.html and then follow the
- link at the bottom to join the lists.
-
-event_example
--------------
-
-This simple example demonstrates the event handling features of
-the Velocity Template Engine.
-
-Note that this is considered a more advanced topic - you don't need
-to know this to use 99% of the features of Velocity, so if this
-seems like too much at first - ignore it!
-
-This is a standalone program. It is compiled by the 'examples' build
-target.
-
-To run, and assuming you have the Velocity and Commons-Collections jar
-in your CLASSPATH, simply do :
-
-java EventExample
-
-if the .jar's are not in your classpath, do :
-
-java -cp \
-../../bin/velocity-[VERSION].jar:../../build/lib/commons-collections.jar:. \
-org.apache.velocity.example.EventExample
-
-(NOTE: make sure that the jarname is correct - this document might get
-out of synch with the release version numbers.)
diff --git a/velocity-engine-examples/src/etc/app_example1/example.sh b/velocity-engine-examples/src/etc/example1.sh
index f9bd0c7b..acee004c 100755
--- a/velocity-engine-examples/src/etc/app_example1/example.sh
+++ b/velocity-engine-examples/src/etc/example1.sh
@@ -1,4 +1,4 @@
-# !/bin/sh
+#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,28 +17,12 @@
# specific language governing permissions and limitations
# under the License.
-echo "Running Example with input file 'example.vm'"
+echo "Running Example with input file 'example1.vm'"
_VELCP=.
-
-for i in ../lib/*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
-
-for i in ../*.jar
+for i in lib/*.jar
do
- _VELCP=$_VELCP:"$i"
-done
-
-for i in ../../lib/*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
-
-for i in ../../*.jar
-do
- _VELCP=$_VELCP:"$i"
+ _VELCP="$_VELCP:$i"
done
# convert the unix path to windows
@@ -46,5 +30,7 @@ if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then
_VELCP=`cygpath --path --windows "$_VELCP"`
fi
-java -cp $_VELCP org.apache.velocity.example.Example example.vm
+echo "Using classpath $_VELCP"
+
+java -cp $_VELCP org.apache.velocity.example.Example example1.vm
diff --git a/velocity-engine-examples/src/etc/app_example2/example2.sh b/velocity-engine-examples/src/etc/example2.sh
index 36ebac12..0016f77f 100755
--- a/velocity-engine-examples/src/etc/app_example2/example2.sh
+++ b/velocity-engine-examples/src/etc/example2.sh
@@ -1,4 +1,4 @@
-# !/bin/sh
+#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,26 +17,12 @@
# specific language governing permissions and limitations
# under the License.
-_VELCP=.
-
-for i in ../lib/*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
-
-for i in ../*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
-
-for i in ../../lib/*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
+echo "Running Example2"
-for i in ../../*.jar
+_VELCP=.
+for i in lib/*.jar
do
- _VELCP=$_VELCP:"$i"
+ _VELCP="$_VELCP:$i"
done
# convert the unix path to windows
@@ -44,5 +30,7 @@ if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then
_VELCP=`cygpath --path --windows "$_VELCP"`
fi
+echo "Using classpath $_VELCP"
+
java -cp $_VELCP org.apache.velocity.example.Example2
diff --git a/velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.sh b/velocity-engine-examples/src/etc/xmlapp_example.sh
index 12d1f730..fcd51527 100755
--- a/velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.sh
+++ b/velocity-engine-examples/src/etc/xmlapp_example.sh
@@ -1,4 +1,4 @@
-# !/bin/sh
+#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,26 +17,12 @@
# specific language governing permissions and limitations
# under the License.
-_VELCP=.
-
-for i in ../lib/*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
-
-for i in ../*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
+echo "Running XMLTest with input file 'xml.vm'"
-for i in ../../lib/*.jar
-do
- _VELCP=$_VELCP:"$i"
-done
-
-for i in ../../*.jar
+_VELCP=.
+for i in lib/*.jar
do
- _VELCP=$_VELCP:"$i"
+ _VELCP="$_VELCP:$i"
done
# convert the unix path to windows
@@ -44,5 +30,6 @@ if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then
_VELCP=`cygpath --path --windows "$_VELCP"`
fi
-java -cp $_VELCP org.apache.velocity.example.XMLTest xml.vm
+echo "Using classpath $_VELCP"
+java -cp $_VELCP org.apache.velocity.example.XMLTest xml.vm
diff --git a/velocity-engine-examples/src/etc/xmlapp_example/README.txt b/velocity-engine-examples/src/etc/xmlapp_example/README.txt
deleted file mode 100644
index cd7d7ac7..00000000
--- a/velocity-engine-examples/src/etc/xmlapp_example/README.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-Welcome to Velocity!
-
-This directory contains a few examples to help get you started.
-
-As always, the if you have any questions :
-
-1) Make sure you followed any directions :-) (did you build
- everything?)
-
-2) Review documentation included in this package, or online at
- http://velocity.apache.org/
-
-3) Ask on the velocity-user list. This is a great source of support
- information. To join, read http://velocity.apache.org/contact.html
- and then follow the links to join the lists.
-
-
-xmlapp_example
---------------
-
-Another simple example showing how to use Velocity in a standalone
-program. This example shows how to use Velocity to access XML data
-directly from an XML input file within the template. It also
-demonstrates velocimacro recursion.
-
- ./xmlapp_example.sh
-or
- xmlapp_example.bat
diff --git a/velocity-engine-examples/src/etc/xmlapp_example/appendVELCP.bat b/velocity-engine-examples/src/etc/xmlapp_example/appendVELCP.bat
deleted file mode 100644
index 6fb3c6e2..00000000
--- a/velocity-engine-examples/src/etc/xmlapp_example/appendVELCP.bat
+++ /dev/null
@@ -1,19 +0,0 @@
-@echo off
-rem Licensed to the Apache Software Foundation (ASF) under one
-rem or more contributor license agreements. See the NOTICE file
-rem distributed with this work for additional information
-rem regarding copyright ownership. The ASF licenses this file
-rem to you under the Apache License, Version 2.0 (the
-rem "License"); you may not use this file except in compliance
-rem with the License. You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing,
-rem software distributed under the License is distributed on an
-rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-rem KIND, either express or implied. See the License for the
-rem specific language governing permissions and limitations
-rem under the License.
-
-set VELCP=%VELCP%;%1
diff --git a/velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.bat b/velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.bat
deleted file mode 100644
index 9c864380..00000000
--- a/velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.bat
+++ /dev/null
@@ -1,29 +0,0 @@
-@echo off
-rem Licensed to the Apache Software Foundation (ASF) under one
-rem or more contributor license agreements. See the NOTICE file
-rem distributed with this work for additional information
-rem regarding copyright ownership. The ASF licenses this file
-rem to you under the Apache License, Version 2.0 (the
-rem "License"); you may not use this file except in compliance
-rem with the License. You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing,
-rem software distributed under the License is distributed on an
-rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-rem KIND, either express or implied. See the License for the
-rem specific language governing permissions and limitations
-rem under the License.
-
-set VELCP=.
-
-for %%i in (..\lib\*.jar) do call appendVELCP %%i
-for %%i in (..\*.jar) do call appendVELCP %%i
-for %%i in (..\..\lib\*.jar) do call appendVELCP %%i
-for %%i in (..\..\*.jar) do call appendVELCP %%i
-
-echo Using classpath: %VELCP%
-
-java -cp %VELCP% org.apache.velocity.example.XMLTest xml.vm
-
diff --git a/velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java b/velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java
index cd64e833..b7b409b4 100644
--- a/velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java
+++ b/velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java
@@ -27,6 +27,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
+import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
@@ -73,31 +74,29 @@ public class DBContext extends AbstractContext
{
try
{
- String data = null;
-
- String sql = "SELECT k, val FROM contextstore WHERE k ='"+key+"'";
-
+ String sql = "SELECT val FROM contextstore WHERE k ='"+key+"'";
Statement s = conn.createStatement();
-
ResultSet rs = s.executeQuery( sql );
+ Object o = null;
+ ObjectInputStream in = null;
+
if(rs.next())
- data = rs.getString("val");
+ {
+ in = new ObjectInputStream( rs.getBinaryStream(1) );
+ o = in.readObject();
+ in.close();
+ }
rs.close();
s.close();
- ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data.getBytes() ));
-
- Object o = in.readObject();
-
- in.close();
-
return o;
}
catch(Exception e)
{
System.out.println("internalGet() : " + e );
+ e.printStackTrace();
}
return null;
@@ -113,21 +112,23 @@ public class DBContext extends AbstractContext
{
try
{
+ Statement s = conn.createStatement();
+ s.executeUpdate( "DELETE FROM contextstore WHERE k = '" + key + "'" );
+ s.close();
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream( baos );
-
out.writeObject( value );
- String data = baos.toString();
-
+ byte buf[] = baos.toByteArray();
out.close();
baos.close();
- Statement s = conn.createStatement();
-
- s.executeUpdate( "DELETE FROM contextstore WHERE k = '" + key + "'" );
- s.executeUpdate( "INSERT INTO contextstore (k,val) values ('"+key+"','" + data + "')" );
+ ByteArrayInputStream bais = new ByteArrayInputStream(buf);
+ PreparedStatement ps = conn.prepareStatement( "INSERT INTO contextstore (k,val) values ('"+key+"', ?)");
+ ps.setBinaryStream(1, bais, buf.length);
+ ps.executeUpdate();
+ ps.close();
- s.close();
}
catch(Exception e)
{
@@ -172,8 +173,8 @@ public class DBContext extends AbstractContext
{
try
{
- Class.forName("org.gjt.mm.mysql.Driver").newInstance();
- conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root");
+ Class.forName("com.mysql.cj.jdbc.Driver");
+ conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=YOUR_DB_USER&password=YOUR_DB_PASSWORD");
}
catch (Exception e)
{
diff --git a/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java b/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java
index 45eb87ab..7013439e 100644
--- a/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java
+++ b/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java
@@ -21,6 +21,7 @@ package org.apache.velocity.example;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.event.EventCartridge;
+import org.apache.velocity.app.event.InvalidReferenceEventHandler;
import org.apache.velocity.app.event.MethodExceptionEventHandler;
import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
import org.apache.velocity.context.Context;
@@ -38,14 +39,14 @@ import java.io.StringWriter;
* This class is a simple demonstration of how the event handling
* features of the Velocity Servlet Engine are used. It uses a
* custom logger as well to check the log message stream
- * when testing the NullSetEventHandler
+ * when testing the InvalidReferenceEventHandler.
*
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
* @version $Id$
*/
public class EventExample extends MarkerIgnoringBase
- implements ReferenceInsertionEventHandler, MethodExceptionEventHandler
+ implements ReferenceInsertionEventHandler, MethodExceptionEventHandler, InvalidReferenceEventHandler
{
private boolean logOutput = false;
private boolean exceptionSwitch = false;
@@ -139,7 +140,7 @@ public class EventExample extends MarkerIgnoringBase
s = "#set($settest = $NotAReference)";
w = new StringWriter();
- System.out.println("NullSetEventHandler test : " );
+ System.out.println("invalidSetMethod test : " );
System.out.print(" There should be nothing between >");
Velocity.evaluate( context, w, "mystring", s );
System.out.println("< the brackets.");
@@ -153,7 +154,7 @@ public class EventExample extends MarkerIgnoringBase
s = "#set($logthis = $NotAReference)";
w = new StringWriter();
- System.out.println("NullSetEventHandler test : " );
+ System.out.println("invalidSetMethod test : " );
System.out.print(" There should be a log message between >");
Velocity.evaluate( context, w, "mystring", s );
System.out.println("< the brackets.");
@@ -269,16 +270,35 @@ public class EventExample extends MarkerIgnoringBase
}
/**
+ */
+
+ public Object invalidGetMethod(Context context, String reference, Object object, String property, Info info)
+ {
+ /* NOP */
+ return null;
+ }
+
+ public Object invalidMethod(Context context, String reference, Object object, String method, Info info)
+ {
+ /* NOP */
+ return null;
+ }
+
+ /**
* Event handler for when the right hand side of
* a #set() directive is null, which results in
* a log message. This method gives the application
* a chance to 'vote' on msg generation
*/
- public boolean shouldLogOnNullSet( String lhs, String rhs )
+ public boolean invalidSetMethod(Context context, String leftreference, String rightreference, Info info)
{
- return !lhs.equals("$settest");
+ if (leftreference.equals("logthis"))
+ {
+ System.out.print("Setting reference " + leftreference + " to null");
+ }
+ return false;
}
-
+
public Object methodException( Context context, Class claz, String method, Exception e, Info info ) {
/*
* only do processing if the switch is on
diff --git a/velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java b/velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java
index c06a9166..bf3546a6 100644
--- a/velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java
+++ b/velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java
@@ -58,7 +58,7 @@ public class Example2
VelocityContext context = new VelocityContext();
context.put("name", "Velocity");
- context.put("project", "Jakarta");
+ context.put("project", "Engine");
/* lets render a template */
diff --git a/velocity-engine-examples/src/main/resources/example.vm b/velocity-engine-examples/src/main/resources/example1.vm
index 7b17de21..7b17de21 100644
--- a/velocity-engine-examples/src/main/resources/example.vm
+++ b/velocity-engine-examples/src/main/resources/example1.vm
diff --git a/velocity-engine-examples/src/main/resources/velocity.properties b/velocity-engine-examples/src/main/resources/velocity.properties
index d4f683db..00a7ec66 100644
--- a/velocity-engine-examples/src/main/resources/velocity.properties
+++ b/velocity-engine-examples/src/main/resources/velocity.properties
@@ -14,4 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-runtime.log = velocity_example.log
+
+# Here you can configure Velocity behavior,
+# see http://velocity.apache.org/engine/${project.version}/configuration.html#configuring-velocity
+runtime.log.name = velocity