daveb 01/03/02 15:39:50
Added: whiteboard/daveb/dajarred build.sh build.xml Example.class
Example.java test.jar velocity.log
velocity.properties
Log:
Example and test of the JarResourceLoader.
Revision Changes Path
1.1 jakarta-velocity/whiteboard/daveb/dajarred/build.sh
Index: build.sh
===================================================================
#!/bin/sh
#-------------------------------------------------------------------
#--------------------------------------------
# No need to edit anything past here
#--------------------------------------------
if test -z "${JAVA_HOME}" ; then
echo "ERROR: JAVA_HOME not found in your environment."
echo "Please, set the JAVA_HOME variable in your environment to match the"
echo "location of the Java Virtual Machine you want to use."
exit
fi
if test -f ${JAVA_HOME}/lib/tools.jar ; then
CLASSPATH="${CLASSPATH}:${JAVA_HOME}/lib/tools.jar"
fi
# convert the existing path to unix
if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
for i in ../../../build/lib/*.jar
do
CLASSPATH=$CLASSPATH:"$i"
done
for i in ../../../bin/*.jar
do
CLASSPATH=$CLASSPATH:"$i"
done
# convert the unix path to windows
if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi
BUILDFILE=build.xml
${JAVA_HOME}/bin/java -classpath ${CLASSPATH} \
org.apache.tools.ant.Main \
-buildfile ${BUILDFILE} "$@"
1.1 jakarta-velocity/whiteboard/daveb/dajarred/build.xml
Index: build.xml
===================================================================
<?xml version="1.0"?>
<project name="TestJar" default="test" basedir=".">
<property name="build.compiler" value="classic"/>
<property name="build.dir" value="."/>
<property name="build.src" value="."/>
<property name="build.dest" value="."/>
<property name="ant.home" value="."/>
<property name="debug" value="on"/>
<property name="optimize" value="on"/>
<property name="deprecation" value="on"/>
<!-- =================================================================== -->
<!-- prints the environment -->
<!-- =================================================================== -->
<target name="env">
<echo message="build.compiler = ${build.compiler}"/>
<echo message="java.home = ${java.home}"/>
<echo message="user.home = ${user.home}"/>
<echo message="java.class.path = ${java.class.path}"/>
<echo message=""/>
</target>
<!-- =================================================================== -->
<!-- Compiles the source directory w/o the j2ee dependent files -->
<!-- =================================================================== -->
<target name="compile">
<delete file="Example.class"/>
<javac srcdir="${build.src}"
destdir="${build.dest}"
debug="${debug}"
deprecation="${deprecation}"
optimize="${optimize}">
</javac>
</target>
<target name="test" depends="compile">
<echo message="Running JarResourceLoader test..."/>
<java classname="Example">
<classpath>
<pathelement path="${classpath}"/>
<pathelement location="${build.dest}"/>
</classpath>
</java>
</target>
</project>
1.1 jakarta-velocity/whiteboard/daveb/dajarred/Example.class
<<Binary file>>
1.1 jakarta-velocity/whiteboard/daveb/dajarred/Example.java
Index: Example.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import java.io.*;
import java.util.ArrayList;
/**
* This class is a simple demonstration of how the Velocity Template Engine
* can be used in a standalone application.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id: Example.java,v 1.1 2001/03/02 23:39:50 daveb Exp $
*/
public class Example
{
public Example( String templateFile)
{
try
{
/*
* setup
*/
Runtime.init("velocity.properties");
/*
* Make a context object and populate with the data. This
* is where the Velocity engine gets the data to resolve the
* references (ex. $list) in the template
*/
VelocityContext context = new VelocityContext();
context.put("list", getNames());
/*
* get the Template object. This is the parsed version of your
* template input file. Note that getTemplate() can throw
* ResourceNotFoundException : if it doesn't find the template
* ParseErrorException : if there is something wrong with the VTL
* Exception : if something else goes wrong (this is generally
* indicative of as serious problem...)
*/
Template template = null;
try
{
template = Runtime.getTemplate(templateFile);
}
catch( ResourceNotFoundException rnfe )
{
System.out.println("Example : error : cannot find template " +
templateFile );
}
catch( ParseErrorException pee )
{
System.out.println("Example : Syntax error in template " +
templateFile + ":" + pee );
}
/*
* Now have the template engine process your template using the
* data placed into the context. Think of it as a 'merge'
* of the template and the data to produce the output stream.
*/
BufferedWriter writer = writer = new BufferedWriter(
new OutputStreamWriter(System.out));
if ( template != null)
template.merge(context, writer);
/*
* flush and cleanup
*/
writer.flush();
writer.close();
}
catch( Exception e )
{
System.out.println(e);
e.printStackTrace();
}
}
public ArrayList getNames()
{
ArrayList list = new ArrayList();
list.add("ArrayList element 1");
list.add("ArrayList element 2");
list.add("ArrayList element 3");
list.add("ArrayList element 4");
return list;
}
public static void main(String[] args)
{
Example t = new Example("/example/test1.vm");
}
}
1.1 jakarta-velocity/whiteboard/daveb/dajarred/test.jar
<<Binary file>>
1.1 jakarta-velocity/whiteboard/daveb/dajarred/velocity.log
Index: velocity.log
===================================================================
Fri Mar 02 17:42:17 CST 2001 [info] Default Properties File:
org/apache/velocity/runtime/defaults/velocity.properties
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override : runtime.log =
velocity.log
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
resource.loader.1.description = Velocity Jar Resource Loader
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override : external.init = false
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
counter.initial.value = 1
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
resource.loader.1.modificationCheckInterval = 2
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override : counter.name =
velocityCount
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
include.output.errormsg.start = <!-- include error :
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
resource.loader.1.cache = false
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override : default.contentType
= text/html
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
resource.loader.1.public.name = Jar
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
resource.loader.1.class = org.apache.velocity.runtime.resource.loader.JarResourceLoader
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override : template.encoding =
8859_1
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
resource.loader.1.resource.path = jar:file:test.jar!/
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
include.output.errormsg.end = see error log -->
Fri Mar 02 17:42:17 CST 2001 [info] ** Property Override :
parse_directive.maxdepth = 10
Fri Mar 02 17:42:17 CST 2001 [info] Log file being used is:
/dave/JavaApache/jakarta-velocity/whiteboard/daveb/dajarred/velocity.log
Fri Mar 02 17:42:17 CST 2001 [info] Resource Loader Instantiated:
org.apache.velocity.runtime.resource.loader.JarResourceLoader
Fri Mar 02 17:42:17 CST 2001 [info] Resources Loaded From: jar:file:test.jar!/
Fri Mar 02 17:42:17 CST 2001 [info] JarResourceLoader Initialized.
Fri Mar 02 17:42:17 CST 2001 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Literal
Fri Mar 02 17:42:17 CST 2001 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Macro
Fri Mar 02 17:42:17 CST 2001 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Parse
Fri Mar 02 17:42:17 CST 2001 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Include
Fri Mar 02 17:42:17 CST 2001 [info] Loaded Pluggable Directive:
org.apache.velocity.runtime.directive.Foreach
Fri Mar 02 17:42:18 CST 2001 [info] Created: 20 parsers.
Fri Mar 02 17:42:18 CST 2001 [info] Velocimacro : initialization starting.
Fri Mar 02 17:42:18 CST 2001 [info] Velocimacro : adding VMs from global VM
library template : VM_global_library.vm
Fri Mar 02 17:42:18 CST 2001 [info] Attempting to find VM_global_library.vm with
org.apache.velocity.runtime.resource.loader.JarResourceLoader
Fri Mar 02 17:42:18 CST 2001 [error] Resource Not Found
Fri Mar 02 17:42:18 CST 2001 [error] ResourceManager.getResource() exception:
org.apache.velocity.exception.ResourceNotFoundException: Unknown resource error for
resource VM_global_library.vm
Fri Mar 02 17:42:18 CST 2001 [info] Velocimacro : error using global VM library
template VM_global_library.vm :
org.apache.velocity.exception.ResourceNotFoundException: Unknown resource error for
resource VM_global_library.vm
Fri Mar 02 17:42:18 CST 2001 [info] Velocimacro : no local VM library template
used.
Fri Mar 02 17:42:18 CST 2001 [info] Velocimacro : allowInline = true : VMs can be
defined inline in templates
Fri Mar 02 17:42:18 CST 2001 [info] Velocimacro : allowInlineToOverride = false :
VMs defined inline may NOT replace previous VM definitions
Fri Mar 02 17:42:18 CST 2001 [info] Velocimacro : allowInlineLocal = false : VMs
defined inline will be global in scope if allowed.
Fri Mar 02 17:42:18 CST 2001 [info] Velocimacro : messages on : VM system will
output logging messages
Fri Mar 02 17:42:18 CST 2001 [info] Velocimacro : initialization complete.
Fri Mar 02 17:42:18 CST 2001 [info] Velocity successfully started.
Fri Mar 02 17:42:18 CST 2001 [info] Attempting to find /example/test1.vm with
org.apache.velocity.runtime.resource.loader.JarResourceLoader
1.1 jakarta-velocity/whiteboard/daveb/dajarred/velocity.properties
Index: velocity.properties
===================================================================
#----------------------------------------------------------------------------
# These are the default properties for the
# Velocity Runtime. These values are used when
# Runtime.init() is called, and when Runtime.init(properties)
# fails to find the specificed properties file.
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
# R U N T I M E L O G
#----------------------------------------------------------------------------
# This is the location of the Velocity Runtime log.
#----------------------------------------------------------------------------
runtime.log = velocity.log
#----------------------------------------------------------------------------
# T E M P L A T E E N C O D I N G
#----------------------------------------------------------------------------
template.encoding=8859_1
#----------------------------------------------------------------------------
# C O N T E N T T Y P E
#----------------------------------------------------------------------------
# This is the default content type for the VelocityServlet.
#----------------------------------------------------------------------------
default.contentType=text/html
#----------------------------------------------------------------------------
# F O R E A C H P R O P E R T I E S
#----------------------------------------------------------------------------
# These properties control how the counter is accessed in the #foreach
# directive. By default the reference $velocityCount will be available
# in the body of the #foreach directive. The default starting value
# for this reference is 1.
#----------------------------------------------------------------------------
counter.name = velocityCount
counter.initial.value = 1
#----------------------------------------------------------------------------
# I N C L U D E P R O P E R T I E S
#----------------------------------------------------------------------------
# These are the properties that governed the way #include'd content
# is governed.
#----------------------------------------------------------------------------
include.output.errormsg.start = <!-- include error :
include.output.errormsg.end = see error log -->
#----------------------------------------------------------------------------
# P A R S E P R O P E R T I E S
#----------------------------------------------------------------------------
parse_directive.maxdepth = 10
#----------------------------------------------------------------------------
# T E M P L A T E L O A D E R S
#----------------------------------------------------------------------------
#
#
#----------------------------------------------------------------------------
resource.loader.1.public.name = Jar
resource.loader.1.description = Velocity Jar Resource Loader
resource.loader.1.class =
org.apache.velocity.runtime.resource.loader.JarResourceLoader
resource.loader.1.resource.path = jar:file:test.jar!/
resource.loader.1.cache = false
resource.loader.1.modificationCheckInterval = 2
#----------------------------------------------------------------------------
# E X T E R N A L S E R V I C E I N I T I A L I Z A T I O N
#----------------------------------------------------------------------------
# If this property is set to true then an external service will
# set certain system properties and initialize the Velocity
# Runtime. This method is used by Turbine to initialize the
# Velocity Runtime for the TurbineVelocityService.
#----------------------------------------------------------------------------
external.init = false
#----------------------------------------------------------------------------
# VELOCIMACRO GLOBAL LIBRARY
#----------------------------------------------------------------------------
# name of default global library. It is expected to be in the regular
# template path. You may remove it (either the file or this property) if
# you wish with no harm.
#----------------------------------------------------------------------------
#velocimacro.library.global=VM_global_library.vm