[opencms-dev] Velocity

Anil Patel toanilpatel at hotmail.com
Tue Jul 9 09:06:50 CEST 2002


Alex,
I have extended work of Werner Punz  on velocity integration with OpenCMS
for use in our company.  Please have look at the work, If you like it then
you can make it available on the opencms.org.
Anil Patel


OpenCMS Velocity integration.




Reference Library needed

  1.. commons-collections.jar

  2.. logkit-1.0.1.jar

  3.. velocity-1.2.jar




Extend opencms.properties file, add following contents:






#---------------------------------------------------------------------------
-

      # Velocity T E M P L A T E L O A D E R S for OpenCMS


#---------------------------------------------------------------------------
-

      #

      #


#---------------------------------------------------------------------------
-

      resource.loader = file

      file.resource.loader.description = Velocity File Resource Loader

      file.resource.loader.class =
com.opencms.apache.velocity.OpenCMSResourceLoader





      #add your own access path here

      file.resource.loader.path =
.,/velocityTemplates/,/velocityTemplates/mail/,/velocityTemplates/newsletter
/





      #this is currently necessary to enable velocity internal caching

      resourcemanager.cache.class =
com.opencms.apache.velocity.SimpleHashtableCache

      resourcemanager.cache.global = false

      runtimeinstance.cache.class =
com.opencms.apache.velocity.SimpleHashtableCache

      runtimeinstance.cache.global = false






Download and compile files provided in opencms_velocity_03.zip file. Add
compiled files to OpenCMS occlasses(or oclib if jar). For compiling these
source files above mentioned library is required.





Similar to other java classes that provide bynamic content to OpenCMS XML
template. Define java class by extending
com.aditisoft.opencms.templates.VelocityTemplate. For conventions of
implementing extended class read java doc provided in class or refer to the
source.

Create default velocity template for the project in
"content/velocityTemplates/" folder of vfs. Name of the file should be
"default". This file is used for providing a default content in case
template file was not provided in ELEMENTDEF.

VELOCITYELEMENT template declaration for use in ELEMENTDEF declaration.

<?xml version="1.0"?>

<XMLTEMPLATE>

<VELOCITYELEMENT>

<PROCESS>velocity_code</PROCESS>

</VELOCITYELEMENT>

<TEMPLATE>

<PROCESS>VELOCITYELEMENT</PROCESS>

</TEMPLATE>

</XMLTEMPLATE>

Imp: You may not have to change any thing in this declaration. You should
not be modifing <PROCESS>velocity_code</PROCESS> element. velocity_code is
key value hard coded in Java class (VelocityTemplate).

ELEMENTDEF declartion:

<ELEMENTDEF name="elementvelocity">

<TEMPLATE>/content/elements/VelocityElement</TEMPLATE>

<CLASS>com.aditisoft.opencms.templates.VelocityTemplate</CLASS>

<PARAMETER name="TEMPLATEFILE">

/content/VelocityTemplates/hello

</PARAMETER>

</ELEMENTDEF>

ELEMENTDEF will be declared for almost every user action. Class element
takes name of the Java action class. The java action class should be
com.aditisoft.opencms.templates.VelocityTemplate or its sub-class. This
ELEMENTDEF also optionally includes parameter named " TEMPLATEFILE ". This
takes name of the Velocity template for generating the view. If this
parameter is not provided velocity template file name defaults to
"content/velocityTemplates/default".

If action class implements more then one user actions, add another parameter
declaration for name of the user action. The user action parameter value can
be used for identifying user action in the getContent method of action
class.

























-------------- next part --------------
A non-text attachment was scrubbed...
Name: VelocityTemplate.java
Type: application/octet-stream
Size: 3861 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20020709/5434c27c/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20020709/5434c27c/attachment.html>


More information about the opencms-dev mailing list