From commits-return-3883-archive-asf-public=cust-asf.ponee.io@velocity.apache.org Sat Dec 14 12:20:13 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id B0B5D180629 for ; Sat, 14 Dec 2019 13:20:12 +0100 (CET) Received: (qmail 59459 invoked by uid 500); 14 Dec 2019 12:20:12 -0000 Mailing-List: contact commits-help@velocity.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@velocity.apache.org Delivered-To: mailing list commits@velocity.apache.org Received: (qmail 59432 invoked by uid 99); 14 Dec 2019 12:20:12 -0000 Received: from Unknown (HELO svn01-us-east.apache.org) (13.90.137.153) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Dec 2019 12:20:12 +0000 Received: from svn01-us-east.apache.org (svn01-us-east.apache.org [127.0.0.1]) by svn01-us-east.apache.org (ASF Mail Server at svn01-us-east.apache.org) with ESMTP id DA68517BB9F for ; Sat, 14 Dec 2019 12:20:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1871468 - in /velocity/engine/trunk: ./ velocity-engine-examples/ velocity-engine-examples/src/assembly/ velocity-engine-examples/src/etc/ velocity-engine-examples/src/etc/app_example1/ velocity-engine-examples/src/etc/app_example2/ veloci... Date: Sat, 14 Dec 2019 12:20:11 -0000 To: commits@velocity.apache.org From: cbrisson@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20191214122011.DA68517BB9F@svn01-us-east.apache.org> Author: cbrisson Date: Sat Dec 14 12:20:11 2019 New Revision: 1871468 URL: http://svn.apache.org/viewvc?rev=1871468&view=rev Log: [engine] Refresh examples packaging Added: velocity/engine/trunk/velocity-engine-examples/README.md velocity/engine/trunk/velocity-engine-examples/src/assembly/ velocity/engine/trunk/velocity-engine-examples/src/assembly/examples.xml velocity/engine/trunk/velocity-engine-examples/src/etc/build.sh velocity/engine/trunk/velocity-engine-examples/src/etc/dbcontexttest.sh - copied, changed from r1871467, velocity/engine/trunk/velocity-engine-examples/src/etc/context_example/dbcontexttest.sh velocity/engine/trunk/velocity-engine-examples/src/etc/example1.sh - copied, changed from r1871467, velocity/engine/trunk/velocity-engine-examples/src/etc/app_example1/example.sh velocity/engine/trunk/velocity-engine-examples/src/etc/example2.sh - copied, changed from r1871467, velocity/engine/trunk/velocity-engine-examples/src/etc/app_example2/example2.sh velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example.sh - copied, changed from r1871467, velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.sh velocity/engine/trunk/velocity-engine-examples/src/main/resources/example1.vm - copied unchanged from r1871467, velocity/engine/trunk/velocity-engine-examples/src/main/resources/example.vm Removed: velocity/engine/trunk/velocity-engine-examples/src/etc/README.txt velocity/engine/trunk/velocity-engine-examples/src/etc/app_example1/ velocity/engine/trunk/velocity-engine-examples/src/etc/app_example2/ velocity/engine/trunk/velocity-engine-examples/src/etc/context_example/ velocity/engine/trunk/velocity-engine-examples/src/etc/event_example/ velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example/ velocity/engine/trunk/velocity-engine-examples/src/main/resources/example.vm Modified: velocity/engine/trunk/pom.xml velocity/engine/trunk/velocity-engine-examples/pom.xml velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java velocity/engine/trunk/velocity-engine-examples/src/main/resources/velocity.properties Modified: velocity/engine/trunk/pom.xml URL: http://svn.apache.org/viewvc/velocity/engine/trunk/pom.xml?rev=1871468&r1=1871467&r2=1871468&view=diff ============================================================================== --- velocity/engine/trunk/pom.xml (original) +++ velocity/engine/trunk/pom.xml Sat Dec 14 12:20:11 2019 @@ -127,6 +127,11 @@ extra-enforcer-rules 1.2 + + org.apache.maven.plugins + maven-assembly-plugin + 3.2.0 + Added: velocity/engine/trunk/velocity-engine-examples/README.md URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/README.md?rev=1871468&view=auto ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/README.md (added) +++ velocity/engine/trunk/velocity-engine-examples/README.md Sat Dec 14 12:20:11 2019 @@ -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 Modified: velocity/engine/trunk/velocity-engine-examples/pom.xml URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/pom.xml?rev=1871468&r1=1871467&r2=1871468&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/pom.xml (original) +++ velocity/engine/trunk/velocity-engine-examples/pom.xml Sat Dec 14 12:20:11 2019 @@ -1,22 +1,22 @@ @@ -26,7 +26,7 @@ velocity-engine-parent 2.2-SNAPSHOT - + velocity-engine-examples Apache Velocity Engine - Examples Very simple examples to use Velocity @@ -37,7 +37,48 @@ org.apache.felix maven-bundle-plugin + + org.apache.maven.plugins + maven-dependency-plugin + + + prepare-package + + copy-dependencies + + + ${project.build.directory}/lib + + + + + + org.apache.maven.plugins + maven-resources-plugin + + ${project.build.directory}/examples + + + + org.apache.maven.plugins + maven-assembly-plugin + + + src/assembly/examples.xml + + + + + + src/main/resources + true + + + src/etc + true + + @@ -51,5 +92,11 @@ jdom 1.1.3 + + org.slf4j + slf4j-simple + ${slf4j.version} + test + Added: velocity/engine/trunk/velocity-engine-examples/src/assembly/examples.xml URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/assembly/examples.xml?rev=1871468&view=auto ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/assembly/examples.xml (added) +++ velocity/engine/trunk/velocity-engine-examples/src/assembly/examples.xml Sat Dec 14 12:20:11 2019 @@ -0,0 +1,62 @@ + + pkg + ${project.build.directory} + false + + zip + + + + + ${project.build.directory} + ${project.build.finalName} + + lib/*.jar + + + + + ${project.build.directory} + ${project.build.finalName}/lib + + ${project.build.finalName}.jar + + + + + ${project.build.directory}/examples + ${project.build.finalName} + + *.vm + *.xml + *.properties + + + + + ${project.build.directory}/examples + ${project.build.finalName} + 0755 + + *.sh + + + + + ${project.basedir} + ${project.build.finalName} + + README.md + + + + + ${project.basedir}/src/main/java + ${project.build.finalName}/src + + **/*.java + + + + Added: velocity/engine/trunk/velocity-engine-examples/src/etc/build.sh URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/etc/build.sh?rev=1871468&view=auto ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/etc/build.sh (added) +++ velocity/engine/trunk/velocity-engine-examples/src/etc/build.sh Sat Dec 14 12:20:11 2019 @@ -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." Copied: velocity/engine/trunk/velocity-engine-examples/src/etc/dbcontexttest.sh (from r1871467, velocity/engine/trunk/velocity-engine-examples/src/etc/context_example/dbcontexttest.sh) URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/etc/dbcontexttest.sh?p2=velocity/engine/trunk/velocity-engine-examples/src/etc/dbcontexttest.sh&p1=velocity/engine/trunk/velocity-engine-examples/src/etc/context_example/dbcontexttest.sh&r1=1871467&r2=1871468&rev=1871468&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/etc/context_example/dbcontexttest.sh (original) +++ velocity/engine/trunk/velocity-engine-examples/src/etc/dbcontexttest.sh Sat Dec 14 12:20:11 2019 @@ -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 Copied: velocity/engine/trunk/velocity-engine-examples/src/etc/example1.sh (from r1871467, velocity/engine/trunk/velocity-engine-examples/src/etc/app_example1/example.sh) URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/etc/example1.sh?p2=velocity/engine/trunk/velocity-engine-examples/src/etc/example1.sh&p1=velocity/engine/trunk/velocity-engine-examples/src/etc/app_example1/example.sh&r1=1871467&r2=1871468&rev=1871468&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/etc/app_example1/example.sh (original) +++ velocity/engine/trunk/velocity-engine-examples/src/etc/example1.sh Sat Dec 14 12:20:11 2019 @@ -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" ] || [ "$OST _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 Copied: velocity/engine/trunk/velocity-engine-examples/src/etc/example2.sh (from r1871467, velocity/engine/trunk/velocity-engine-examples/src/etc/app_example2/example2.sh) URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/etc/example2.sh?p2=velocity/engine/trunk/velocity-engine-examples/src/etc/example2.sh&p1=velocity/engine/trunk/velocity-engine-examples/src/etc/app_example2/example2.sh&r1=1871467&r2=1871468&rev=1871468&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/etc/app_example2/example2.sh (original) +++ velocity/engine/trunk/velocity-engine-examples/src/etc/example2.sh Sat Dec 14 12:20:11 2019 @@ -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" ] || [ "$OST _VELCP=`cygpath --path --windows "$_VELCP"` fi +echo "Using classpath $_VELCP" + java -cp $_VELCP org.apache.velocity.example.Example2 Copied: velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example.sh (from r1871467, velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.sh) URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example.sh?p2=velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example.sh&p1=velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.sh&r1=1871467&r2=1871468&rev=1871468&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example/xmlapp_example.sh (original) +++ velocity/engine/trunk/velocity-engine-examples/src/etc/xmlapp_example.sh Sat Dec 14 12:20:11 2019 @@ -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" ] || [ "$OST _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 Modified: velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java?rev=1871468&r1=1871467&r2=1871468&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java (original) +++ velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/DBContext.java Sat Dec 14 12:20:11 2019 @@ -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 AbstractC { 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 AbstractC { 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 AbstractC { 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) { Modified: velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java?rev=1871468&r1=1871467&r2=1871468&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java (original) +++ velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java Sat Dec 14 12:20:11 2019 @@ -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 Geir Magnusson Jr. * @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 Marker 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 Marker 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 Marker } /** + */ + + 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 Modified: velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java?rev=1871468&r1=1871467&r2=1871468&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java (original) +++ velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/Example2.java Sat Dec 14 12:20:11 2019 @@ -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 */ Modified: velocity/engine/trunk/velocity-engine-examples/src/main/resources/velocity.properties URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/main/resources/velocity.properties?rev=1871468&r1=1871467&r2=1871468&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-examples/src/main/resources/velocity.properties (original) +++ velocity/engine/trunk/velocity-engine-examples/src/main/resources/velocity.properties Sat Dec 14 12:20:11 2019 @@ -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