[opencms-dev] On how to integrate OpenCMS and velocity:

Michael Emmerich emmerich at german-navy.de
Sat Mar 30 10:49:47 CET 2002


Hello Werner,

after reading your ideas and example how to integrate Velocity into
OpenCms, it appears to me that there might be a simpler way to add
Velocity support into OpenCms.
Please note that I have not tested your implemetation on a running
system so far, but I think i got your idea right :)

Your idea is the following:
1) Write a OpenCms template that contains a <process> tag where the
generated Velocity output is generated.
2) Write a Template Class which will read the Velocity template,
generate the output from it and insert it into the <process> tag of the
OpenCms template.

So we need two template mechanisms to be started to generate the final
output of the page we want to see. Since the OpenCms template could
contain some HTML code as well, it might be nescessary to modify two
templates (the OpenCms one and the Velocity one) to modify the pages.
Not to forget that more templates involved alsways stand for more places
whare you can make errors :)

So my suggestion for a simpler integration would require a bit more
inital Java programming by adding a new resource type (Velocity
template) and a new launcher to the system.

When you request a resource form the OpenCms system, the resource is
first read form the OpenCms database. Depending on the type of this
resource (plain, xml, page, binary) a special launcher is started that
will initiate the production of the output of this resource. In the
simplest way, the resource content is taken and send back to the client
browser (this is done for text and binary resources, using the plain
launcher). For XML-Files and page resources, the OpenCms temlate
mechanism is started at that point, creating the HTML-output.

Now, the idea would be to write a Velocity launcher. Your resource
inside of OpenCms would only contain the Velocity template (like the
file you read from the getContent method in your example). The Velocity
launcher then would do the same as your getContent method now - get the
content of your Velocity Template and create the HTML output similar to
the

  parseResult = (String)
LC_Velocity_OpenCMS.getInstance().parseTemplate(VELOCITY_TEMPLATE,
theParameters, cms);

call.

The advantage of this implementation is that the OpenCms template
mechanism is not involved in creating the output anymore, and this would
have no negative effects on the system performance.

If you take a look at the exisiting launcher currently in the system,
its would be not that difficult to modifiy the current plain launcher to
directly access Velocity this way. 

The new resource type could be hooked in the system by writing a
resource type module. The other advantage woould be that the Velocity
templates would have the complete access control of resources in OpenCms
and would be part of the project mechanism of course.

Besides this, it would still be possbile to use your implementation to
mix the output of both worlds, Velocity and OpenCms templates.

Another intersting question is, how will it be possible that you can
access user and acces data of the OpenCms from within Velocity? Since
you have a complte user and right management in OpenCms already, it
would be good if this information could be used in the Velocity
templates as well.

So far my thoughts based on your ideas,

Regards and Happy Easter,

	Michael Emmerich

-- 
Home   : emmerich at german-navy.de
Work   : michael.emmerich at framfab.de
ICQ    : 18897063
WWW    : German Naval History http://www.german-navy.de




More information about the opencms-dev mailing list