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

Alexander Kandzior alex at opencms.com
Mon Apr 1 21:46:11 CEST 2002


Michael, 

> 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.

> 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). 

Or said otherwise, with the launcher, you can call the Velocity
Template, but you can not even output a String like 'new String("Hello
World")' without a  "Velocity Servlet class" that first sets this value
and passes the context to the VTL. 

Again, it's not writing the launcher that causes the issues. Writing
"just" a launcher is trivial. It is the synchronization issue that must
be solved and then we must think up a way to include the "Velocity
Servlet class" in the picture.

Regards,
Alex.

Alexander Kandzior
OpenCms Group

Regards,
Alex.





More information about the opencms-dev mailing list