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

Werner Punz werpu at gmx.at
Tue Apr 2 11:21:11 CEST 2002


Actually the OpenCMSResourceLoader is called from the Velocity engine
internally,
somehwere in the Velocity code there is a factory pattern which calls the
resource loaders.
(ResourceLoaderFactory as far as I can remember). The glue between this
class and the
ResourceLoaderFactory is done in the properties file where the standard file
loader is replaced
with the OpenCMSResourceLoader (I have sent to Alex a corrected version of
my explanation with a new section describing the necessary property entries,
which now can be found in the readme. It should go online later today).

The resource Loader then loads the Velocity page which later has to be
parsed and merged.
Therefore the CmsObject has to be passed down to that class before the
Velocity engine
calls the loading method of the resource loader, otherwise no access to the
VFS is possible.

You have to see the resource loader as some kind of low level driver to
access different file systems. Theoretically you could hook every file based
infrastructure into Velocity this way, like HTTP access or XMLRPC even ftp
connections would be possible. The problem I had to do it that way was
because there currently is no way to pass down special parameters into the
resource loader so I had to access it outside of the Velocity code before I
called the Velocity engine afterwards to do the rest of the work (therefore
also the synchronized to make the whole thing thread safe).

The Velocity object itself is the standard access object to the Velocity
engine suggested by
the Velocity people in their programmers doc. You can see the
LC_VelocityOpencms as a simplification of access
and a standard access point towards the Velocity classes (I prefer tiny apis
or interfaces between different parts of a system it makes the handling and
changing of the underlying infrastructure much easier)

This way I think I can alter the underlying access infrastructure without
breaking existing code in future versions. If you have further questions
feel free to ask.


Werner Punz Labor_C
http://www.labor-c.net


-----Ursprüngliche Nachricht-----
Von: owner-opencms-dev at www.opencms.com
[mailto:owner-opencms-dev at www.opencms.com]Im Auftrag von Michael
Emmerich
Gesendet: Dienstag, 2. April 2002 10:45
An: 'opencms-dev at www.opencms.com'
Betreff: AW: [opencms-dev] On how to integrate OpenCMS and velocity:


Alex,

>> Sure, the ResourceLoader cannot be accessed directly from
>> outside of Velocity. But you do not need that, and you do not
>> need to inititalize it form within an OpenCms Launcher since
>> the ResourceLoader is some kind of driver to access the
>> normal filesystem or to hook into something else (like
>> Werners OpenCMSResourceLoader accesses the OpenCms VFS).
>
>Sorry, but this is wrong. Currently, you need to pass the CmsObject to
>the resource launcher. Otherwise the ResouceLoader can not access the
>VFS. Again, look at the code.

I have looked at the code - you can be sure about that - and the only place
where the ResourceLoader is accessed is the LC_Velocity_OpenCMS class where
you pass the CmsObject to it, OpenCMSResourceLoader.setCmsObject(cms). Since
I count the LC_Velocity_OpenCMS as the mediator between OpenCms and
Velocity, I said that you do not need to access the OpenCMSResourceLoader
>from the outside.





>> 1) Read the requested file header, its a Velocity recource,
>> so use the Velocity Launcher
>> 2) Get an instance of the LC_Velocity_OpenCMS class
>> 3) call the parseTemplate method of the LC_Velocity_OpenCMS
>> class and forward the requested URI, the current parameters
>> and the current CmsObject to it (similar to Werners code,
>> except the template name would be the URI)
>> 4) the parseTemplate method will update the CmsObject in the
>> OpenCMSResourceLoader, load the requested template via the
>> OpenCMSResourceLoader and parse it (see Werners code).
>> 5) fetch the created output and send it to the response stream.
>
>There's something missing here between 2) and 3). If I have the VTL
>resource and even an instance of the LC_Velocity_OpenCMS, I could start
>a VTL. But what for? Velocity requires a VTL _and_ a class belonging to
>this Template. This is not the LC_Velocity_OpenCMS class, since this
>just handles the synchronization issue right now. This "Velocity Servlet
>class" must be initialized and called before 3).

I was a bit wondering about this as well, since you mentioned it in your
mail from Saturday evening and I did not find the connection to the
"Velocity Servlet class" in the the code example.
So please tell me where this tell me if this "Velocity Servlet class" is
used in the code example. We have four elements, the LC_Velocity_OpenCMS
class, the OpenCMSResourceLoader, the Velocity sample template and the Cms
Template class. The only component that gets not totaly clear by the example
is the "Velocity" object in the LC_Velocity_OpenCMS class - is this the
"Velocity Servlet class" to be used?

Bye,
	Michael

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20020402/0aec6806/attachment.htm>


More information about the opencms-dev mailing list