geirm       01/02/11 11:14:15

  Modified:    docs     developer-guide.html
  Log:
  latest rendering of the .xml
  
  Revision  Changes    Path
  1.13      +218 -13   jakarta-velocity/docs/developer-guide.html
  
  Index: developer-guide.html
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/docs/developer-guide.html,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- developer-guide.html      2001/02/10 15:12:26     1.12
  +++ developer-guide.html      2001/02/11 19:14:14     1.13
  @@ -35,29 +35,59 @@
   </UL></BLOCKQUOTE>
   
   You will see that there is no real difference between these, other than we make 
servlet development with Velocity very easy
  -if you use our provided class VelocityServlet as a base class for your servlet.
  +if you use our provided class VelocityServlet as a base class for your servlet, and 
offer a utility class to help with application
  +development.
   </P>
  +<B>Getting Started</B>
  +<P align="justify">
  +While this information is found elsewhere on the Velocity site and in the 
documentation, it is included here for completeness.  Getting 
  +Velocity running on your computer is very easy.  Note that all directory references 
are relative the root of the Velocity
  +distribution tree.
  +<BLOCKQUOTE><OL>
  +<LI> Get the Velocity distribution.  This is available as a nightly snapshot or 
directly from the CVS code repository.  Either way is fine.  For more information, go 
<A href="index.html">here</A>.</LI>
  +<LI> Go to the <CODE><FONT face="courier, monospaced">build</FONT></CODE> directory 
in the distribution.</LI>
  +<LI> Type <CODE><FONT face="courier, monospaced">./build-velocity.sh 
jar</FONT></CODE> under Unix, or <CODE><FONT face="courier, 
monospaced">build-velocity.bat jar</FONT></CODE> under Windows.  The major build 
targets are :
  +<BLOCKQUOTE><UL>
  +<LI> <CODE><FONT face="courier, monospaced">jar</FONT></CODE> builds the complete 
Velocity jar in the <CODE><FONT face="courier, monospaced">bin</FONT></CODE> 
directory.  This jar will be called 'velocity-X.jar', where 'X' is the current version 
number.  Unless you have specific storage space considerations, use this jar for 
convenience, as it includes everything you need.</LI>
  +<LI> <CODE><FONT face="courier, monospaced">jar-core</FONT></CODE> builds a slimmer 
Velocity jar in the <CODE><FONT face="courier, monospaced">bin</FONT></CODE> 
directory, called 'velocity-core-X.jar'. This
  +jar contains the core Velocity functionality, and doesn't include example and 
utility things like Anakia, Texen or 
  +the VelocityServlet support baseclass.</LI>
  +<LI> <CODE><FONT face="courier, monospaced">jar-util</FONT></CODE> builds a utility 
Velocity jar in the <CODE><FONT face="courier, monospaced">bin</FONT></CODE> 
directory, called 'velocity-util-X.jar'. This
  +jar contains utility code, specifically Anakia, Texen, and the WebMacro template 
conversion utility.</LI>
  +<LI> <CODE><FONT face="courier, monospaced">jar-servlet</FONT></CODE> builds a 
utility Velocity jar in the <CODE><FONT face="courier, monospaced">bin</FONT></CODE> 
directory, called 'velocity-servlet-X.jar'. This
  +jar contains utility code for servlet programmers.</LI>
  +<LI> <CODE><FONT face="courier, monospaced">docs</FONT></CODE> builds these docs in 
the <CODE><FONT face="courier, monospaced">docs</FONT></CODE> directory</LI>
  +<LI> <CODE><FONT face="courier, monospaced">javadocs</FONT></CODE> builds the 
Javadoc class documentation in the <CODE><FONT face="courier, 
monospaced">docs/apidocs</FONT></CODE> directory</LI>
  +<LI> <CODE><FONT face="courier, monospaced">test</FONT></CODE> (after jar) will 
test Velocity against it's testbed suite of test routines </LI>
  +</UL></BLOCKQUOTE></LI>
  +<LI> While not required, testing the build is a good idea.  Use the <CODE><FONT 
face="courier, monospaced">test</FONT></CODE> target mentioned above.</LI>
  +<LI> That's it!  Velocity is ready to be used.  Put the jar into your classpath, or 
into other appropriate places (such as the lib directory of your webapp if using with 
servlets)</LI>
  +</OL></BLOCKQUOTE>
  +</P>
   </FONT></TD></TR></TABLE></DIV><BR>
   
   <DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="0" 
width="98%"><TR><TD bgcolor="#023264" width="100%"><FONT color="#ffffff" 
face="arial,helvetica,sanserif" size="+1"><IMG border="0" height="5" hspace="0" 
src="resources/void.gif" vspace="0" 
width="5"><B>Resources</B></FONT></TD></TR><TR><TD><IMG border="0" height="5" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE><TABLE 
border="0" cellpadding="0" cellspacing="0" width="98%"><TR><TD><FONT color="#000000" 
face="arial,helvetica,sanserif">
   <P align="justify">
  -There are quite a few resources and examples available to the programmer, and we 
recommend that you look at our examples, documentation and even the source code.  They 
are found in 
  +There are quite a few resources and examples available to the programmer, and we 
recommend that you look at our examples, documentation and even the source code.  Some 
great sources are :
   
   <BLOCKQUOTE><UL>
  -<LI> source code : /src/java/...</LI>
  -<LI> general examples : /examples </LI>
  -<LI> Anakia application :  example application showing how to use Velocity for 
creating stylesheet renderings of xml data 
  -- /examples/anakia </LI>
  -<LI> Forumdemo web app : working example of a simple servlet-based forum 
application - /examples/forumdemo</LI>
  -<LI> documentation : /docs</LI>
  -<LI> templates : for the designer, we have a large collection of template examples 
in our testbed directory - /test/templates</LI>
  +<LI> source code : <CODE><FONT face="courier, 
monospaced">src/java/...</FONT></CODE> : all the source code to the Velocity 
project</LI>
  +<LI> general examples : <CODE><FONT face="courier, 
monospaced">examples</FONT></CODE> : a set of general examples, showing how Velocity 
is used in both a general application as well as in a servlet. </LI>
  +<LI> Anakia application : <CODE><FONT face="courier, 
monospaced">examples/anakia</FONT></CODE> :  example application showing how to use 
Velocity for creating 
  +stylesheet renderings of xml data </LI>
  +<LI> Forumdemo web app : <CODE><FONT face="courier, 
monospaced">examples/forumdemo</FONT></CODE> : working example of a simple 
servlet-based forum application </LI>
  +<LI> documentation : <CODE><FONT face="courier, monospaced">docs</FONT></CODE> : 
all the generated documentation for the Velocity project in html</LI>
  +<LI> API documentation : <CODE><FONT face="courier, 
monospaced">docs/apidocs</FONT></CODE> : the generated Javadoc documentation for the 
Velocity project</LI>
  +<LI> templates : <CODE><FONT face="courier, 
monospaced">test/templates</FONT></CODE> : a large collection of template examples in 
our testbed directory, these are a 
  +great source of useage examples of VTL, the Velocity Template Language </LI>
   </UL></BLOCKQUOTE>
   
   All directory references above are relative to the distribution root directory.
   </P>
   </FONT></TD></TR></TABLE></DIV><BR>
   
  -<DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="0" 
width="98%"><TR><TD bgcolor="#023264" width="100%"><FONT color="#ffffff" 
face="arial,helvetica,sanserif" size="+1"><IMG border="0" height="5" hspace="0" 
src="resources/void.gif" vspace="0" width="5"><B>The Fundamental Code 
Pattern</B></FONT></TD></TR><TR><TD><IMG border="0" height="5" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE><TABLE border="0" 
cellpadding="0" cellspacing="0" width="98%"><TR><TD><FONT color="#000000" 
face="arial,helvetica,sanserif">
  +<DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="0" 
width="98%"><TR><TD bgcolor="#023264" width="100%"><FONT color="#ffffff" 
face="arial,helvetica,sanserif" size="+1"><IMG border="0" height="5" hspace="0" 
src="resources/void.gif" vspace="0" width="5"><B>How Velocity 
Works</B></FONT></TD></TR><TR><TD><IMG border="0" height="5" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE><TABLE border="0" 
cellpadding="0" cellspacing="0" width="98%"><TR><TD><FONT color="#000000" 
face="arial,helvetica,sanserif">
  +<B>or 'The Fundamental Pattern'</B>
   <P align="justify">
   When using Velocity in an application program or in a servlet (or anywhere, 
actually), you will generally do the following :
   
  @@ -95,7 +125,11 @@
   </PRE></TD><TD bgcolor="#023264" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD><TD bgcolor="#023264" height="1"><IMG border="0" height="1" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD></TR></TABLE></DIV>
   </P>
   <P align="justify">
  -Thats the basic pattern.  It is very simple, isn't it?
  +That's the basic pattern.  It is very simple, isn't it?  This is generally what 
happens when you use Velocity to render a template.
  +You probably won't be writing code exactly like this - we provide a few tools to 
help make it even easier than this for 
  +both servlet and application programmers.  Later on in this guide, we will talk 
about using Velocity in both servlets 
  +as well as general applications, and we discuss the tools we provide to make things 
easier.  In each case, though,
  + the above sequence is what is happening either explicitly, or behind the scenes.
   </P>
   </FONT></TD></TR></TABLE></DIV><BR>
   
  @@ -108,8 +142,8 @@
   gather objects of various types, whatever your application calls for, and place 
them in the context.  To the designer, these 
   objects, and their methods and properties, will become accessable via template 
elements called 
   <A href="vtl-reference-guide.html"> references</A>.  Generally, you will work with 
the designer to determine the data 
  -needs for the application, and the 'API' that you are in a way creating as you 
produce a data set for the designer to access
  -in the template.
  +needs for the application.  In a sense, this will become an 'API'  as you produce a 
data set for the designer to access
  +in the template.   Therefore, in this phase of  the development process it is worth 
devoting some time and careful analysis.
   </P>
   
   <P align="justify">
  @@ -266,6 +300,177 @@
   </P>
   <P align="justify">
   This deployment method will ensure that different web applications will not be 
subject to Velocity configuration conflicts.
  +</P>
  +</FONT></TD></TR></TABLE></DIV><BR>
  +
  +<DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="0" 
width="98%"><TR><TD bgcolor="#023264" width="100%"><FONT color="#ffffff" 
face="arial,helvetica,sanserif" size="+1"><IMG border="0" height="5" hspace="0" 
src="resources/void.gif" vspace="0" width="5"><B>Using Velocity In General 
Applications</B></FONT></TD></TR><TR><TD><IMG border="0" height="5" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE><TABLE border="0" 
cellpadding="0" cellspacing="0" width="98%"><TR><TD><FONT color="#000000" 
face="arial,helvetica,sanserif">
  +<P align="justify">
  +As Velocity was designed to be a general-use tool, it is just as useful in general 
application programs as it is servlets.
  +In general, you can use the same programming pattern discussed at the beginning of 
this guide, but there are a few utility methods
  +provided for application use, just like we provide the VelocityServlet base class 
for ease of use in servlet programming.
  +The only new responsibility you have as the application programmer is to initialize 
the Velocity runtime engine, but that is easy.
  +</P>
  +<B>The Velocity Class</B>
  +<P align="justify">
  +Velocity contains an application utility class called Velocity (imagine!).  The 
purpose of this class is to provide the 
  +necessary methods required to initialize Velocity, as well as useful utility 
routines to make life easier in using Velocity.
  +This class is documented in the project's javadoc, so please look there for 
definitive details.
  +This documentation is intended to be of a tutorial nature; therefore for compete 
API information, the Javadoc is the definitive source.
  +</P>
  +<P align="justify">
  +The Velocity runtime engine is a singleton instance that provides resource and 
logging services to all Velocity users running
  +in the same JVM.  Therefore, the runtime engine is initialized only once.  You can 
attempt to initialize Velocity more than once, but only the first initialization will 
apply.  The rest of the attempts will be ignored.  The Velocity utility class provides 
3
  +methods to initialize the runtime engine.  Note that in each case, the default 
properties will be used as a base configuration, 
  +and any additional properties specified by the application will replace individual 
defaults.  Any default properties not 
  +overwritten will remain in effect.  This has the benefit that only the properties 
you are interested in changing need to be 
  +specified, rather than a complete set.  The three initialization methods are :
  +
  +<BLOCKQUOTE><UL>
  +<LI> <CODE><FONT face="courier, monospaced">init()</FONT></CODE><BR> initializes 
the runtime with the default properties provided in the distribution. 
  +(These are listed below in the section pertaining to properties.)</LI>
  +<LI> <CODE><FONT face="courier, monospaced">init( Properties p )</FONT></CODE><BR> 
initialized the runtime with the properties contained in the 
  +java.util.Properties object passed as an argument. </LI>
  +<LI> <CODE><FONT face="courier, monospaced">init( String filename 
)</FONT></CODE><BR> initilizes the runtime using the properties found in the
  +properties file filename</LI>
  +</UL></BLOCKQUOTE>
  +</P>
  +<P align="justify">
  +Once the runtime is initialized, you can do with it what you wish.. This mostly 
revolves around rendering templates into an output
  +stream, and the Velocity utility class allows you to do this easily.  Currently, 
here are the methods and a brief description
  +of what they do :
  +
  +<BLOCKQUOTE><UL>
  +<LI> <CODE><FONT face="courier, monospaced"> evaluate( Context context,  Writer 
out, String logTag, String instring )</FONT></CODE><BR>
  +<CODE><FONT face="courier, monospaced">evaluate( Context context, Writer writer, 
String logTag, InputStream instream )</FONT></CODE><BR>
  +These methods will render the input, in either the form of String or InputStream to 
an output Writer, using a Context that you
  +provide.  This is a very convenienient method to use for token replacement of 
strings, or if you keep 'templates' of VTL-containing
  +content in a place like a database or other non-file storage, or simply generate 
such dynamically.</LI>
  +<LI><CODE><FONT face="courier, monospaced">invokeVelocimacro( String vmName, String 
namespace, String params[], Context context, Writer writer )</FONT></CODE><BR>
  +Allows direct access to Velocimacros.  This can also be accomplished via the 
<CODE><FONT face="courier, monospaced">evaluate()</FONT></CODE> method above if you 
wish.  Here
  +you simply name the vm you wish to be called, create an array of args to the VM, a 
Context of data, and Writer for the output. 
  +Note that the VM args must be the 'keys' of the data objects in the Context, rather 
than literal data to be used as the arg.  This
  +will probably change.</LI>
  +<LI><CODE><FONT face="courier, monospaced">mergeTemplate( String templateName, 
Context context, Writer writer )</FONT></CODE><BR>
  +Convenient access to the normal template handling and rendering services of 
Velocity.  This method will take care of getting and
  +rendering the template.  It will take advantage of loading the template according 
to the properties setting for the file resource 
  +loader, and therefore provides the advantage of file and parsed template caching 
that Velocity offers.  This is the most efficient
  +way to access templates, and is recommended unless you have special needs.</LI>
  +</UL></BLOCKQUOTE>
  +</P>
  +
  +<P align="justify">
  +Once we know about these basic helpers, it is easy to write Java program that uses 
Velocity.  Here it is :
  +
  +<DIV align="center"><TABLE border="0" cellpadding="0" cellspacing="4"><TR><TD 
bgcolor="#023264" height="1" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#023264" 
height="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" 
width="1"></TD><TD bgcolor="#023264" height="1" width="1"><IMG border="0" height="1" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD 
bgcolor="#023264" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#ffffff"><PRE>
  +import java.io.StringWriter;
  +import org.apache.velocity.util.Velocity;
  +import org.apache.velocity.VelocityContext;
  +
  +public class Example2
  +{
  +    public static void main( String args[] )
  +    {
  +        /* first, we init the runtime engine.  Defaults are fine. */
  +
  +        Velocity.init();
  +
  +        /* lets make a Context and put data into it */
  +
  +        VelocityContext context = new VelocityContext();
  +
  +        context.put(&quot;name&quot;, &quot;Velocity&quot;);
  +        context.put(&quot;project&quot;, &quot;Jakarta&quot;);
  +        
  +        /* lets render a template */
  +
  +        StringWriter w = new StringWriter();
  +
  +        Velocity.mergeTemplate(&quot;testtemplate.vm&quot;, context, w );
  +        System.out.println(&quot; template : &quot; + w );
  +
  +        /* lets make our own string to render */
  +
  +        String s = &quot;We are using $project $name to render this.&quot;;
  +        w = new StringWriter();
  +        Velocity.evaluate( context, w, &quot;mystring&quot;, s );
  +        System.out.println(&quot; string : &quot; + w );
  +
  +    }
  +}
  +</PRE></TD><TD bgcolor="#023264" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD><TD bgcolor="#023264" height="1"><IMG border="0" height="1" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD></TR></TABLE></DIV>
  +</P>
  +<P align="justify">
  +When we run this program, and have the template <CODE><FONT face="courier, 
monospaced"> testtemplate.vm</FONT></CODE> in the same directory as our program 
(because we 
  +used the default configuration properties, and the defaul place to load templates 
from is the current directory...), our output
  +should be :
  +<DIV align="center"><TABLE border="0" cellpadding="0" cellspacing="4"><TR><TD 
bgcolor="#023264" height="1" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#023264" 
height="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" 
width="1"></TD><TD bgcolor="#023264" height="1" width="1"><IMG border="0" height="1" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD 
bgcolor="#023264" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#ffffff"><PRE>
  + template : Hi!  This Velocity from the Jakarta project.
  +
  + string : We are using Jakarta Velocity to render this.
  +</PRE></TD><TD bgcolor="#023264" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD><TD bgcolor="#023264" height="1"><IMG border="0" height="1" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD></TR></TABLE></DIV>
  +</P>
  +<P align="justify">
  +where the template we used, testtemplate.vm, is 
  +<DIV align="center"><TABLE border="0" cellpadding="0" cellspacing="4"><TR><TD 
bgcolor="#023264" height="1" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#023264" 
height="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" 
width="1"></TD><TD bgcolor="#023264" height="1" width="1"><IMG border="0" height="1" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD 
bgcolor="#023264" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#ffffff"><PRE>
  +Hi!  This $name from the $project project.
  +</PRE></TD><TD bgcolor="#023264" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD><TD bgcolor="#023264" height="1"><IMG border="0" height="1" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD></TR></TABLE></DIV>
  +</P>
  +<P align="justify">
  +That's all there is to it!  Note that we didn't have to use both <CODE><FONT 
face="courier, monospaced">mergeTemplate()</FONT></CODE> and <CODE><FONT 
face="courier, monospaced">evaluate()</FONT></CODE> in our 
  +program.  They are both included there for demonstration purposes.  You will 
probably use only one of the methods, but depending
  +on you application requirements,  you are free to do what you wish.  
  +</P>
  +<P align="justify">  This appears to be a little different from the 'fundamental 
pattern' that was mentioned at the beginning
  +of this guide, but it really is the same thing.  First, you are making a context 
and filling it with the data needed.  Where this 
  +examples differs is that in the part of the above example where <CODE><FONT 
face="courier, monospaced">mergeTemplate()</FONT></CODE> is used, <CODE><FONT 
face="courier, monospaced">mergeTemplate()</FONT></CODE>
  +is doing the work of getting the template and merging it for you, using the 
lower-level calls in the Runtime class.  In the second 
  +example, you are making your template dynamically via the String, so that is 
analgous to the 'choose template' part of the process,
  +and the <CODE><FONT face="courier, monospaced">evaluate()</FONT></CODE> method does 
the merging for you using lower level calls.
  +</P>
  +<P align="justify">
  +So the example above sticks to the same simply pattern of using the Velocity 
template engine, but the utility functions do some of
  +the repeated drudge work, or allow you other options for your template content 
other than template files.
  +</P>
  +
  +<B>Miscellaneous Details</B>
  +<P align="justify">
  +While the above example used the default properties, setting your own properties is 
very simple.  
  +All you have to do is make a properties file somewhere and pass the name of that 
file
  +to the <CODE><FONT face="courier, monospaced">init(String)</FONT></CODE> method of 
the Velocity utility class, or make a <CODE><FONT face="courier, 
monospaced">java.util.Properties</FONT></CODE> object, 
  +add the desired properties and values, and pass that to the <CODE><FONT 
face="courier, monospaced">init(Properties)</FONT></CODE> method.  
  +The latter method is convenient, because you can either fill it directly from a 
separate properties file via the 
  +<CODE><FONT face="courier, monospaced">load()</FONT></CODE>  method, or even 
better, you can fill it dynamically from your own application / framework's property 
set at
  +runtime.  This gives you the freedom to combine all of the properties for your app 
into one properties file.
  +</P>
  +<P align="justify"> If we wanted to use a different directory than the current 
directory to load our template from, we could do
  +something like this :
  +
  +
  +<DIV align="center"><TABLE border="0" cellpadding="0" cellspacing="4"><TR><TD 
bgcolor="#023264" height="1" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#023264" 
height="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" 
width="1"></TD><TD bgcolor="#023264" height="1" width="1"><IMG border="0" height="1" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD 
bgcolor="#023264" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#ffffff"><PRE>
  +
  + ...
  +
  +import java.util.Properties;
  + ...
  +
  + public static void main( String args[] )
  +    {
  +        /* first, we init the runtime engine.  */
  +
  +        Properties p = new Properties();
  +        p.setProperty(&quot;resource.loader.1.resource.path&quot;, 
&quot;/opt/templates&quot;);
  +        Velocity.init( p );
  +
  +        /* lets make a Context and put data into it */
  +
  + ...
  +
  +</PRE></TD><TD bgcolor="#023264" width="1"><IMG border="0" height="1" hspace="0" 
src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD><TD bgcolor="#023264" height="1"><IMG border="0" height="1" 
hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#023264" 
height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" 
vspace="0" width="1"></TD></TR></TABLE></DIV>
  +</P>
  +<P align="justify">
  +And, assuming you have a directory <CODE><FONT face="courier, 
monospaced">/opt/templates</FONT></CODE> and the template <CODE><FONT face="courier, 
monospaced">testtemplate.vm</FONT></CODE> is in there, 
  +then things would work just fine.  If you try this and have a problem, be sure to 
look at the velocity.log for 
  +information - the error messages are pretty good for figuring out what is wrong.
   </P>
   </FONT></TD></TR></TABLE></DIV><BR>
   
  
  
  

Reply via email to