velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph.R...@dlr.de
Subject Re: Theming with velocity
Date Thu, 15 May 2003 09:36:58 GMT
Herbert Poul wrote:
> Hi,
> I would like to let users choose different themes. i think it is easy to
> make something like#parse( "/themes/$user.theme/foo.vm" )
> but i want that themes doesn't need to implement all .vm files, so when
> /themes/$user.theme/foo.vm isn't found it should look for the file in e.g.
> /themes/default/foo.vmIs this somehow possible with velocity ?
> 
> I guess i need to extend the Parse class.. but how do i add it to the
> directives (without editing directive.properties in the
> velocity-dep-1.3.1.jar would be good) ?
> cu
>   Herbert Poul
> 

I do not recommend to modify the parse directive. Instead, you could
take two approaches:
a) Write a resource loader subclass that allows access and control
    of the current context (or session) that tries to obtain the file
    from the user area. Also install a default resource loader that
    loads the templates from the default loaction if no user template
    was found.
    I believe this was already asked in this list in the past, maybe
    someone wrore such a RL? Query the archive...

b) In your layout template you could make a file tool available, and
    then check $fileTool.fileExists($userTheme)
    You could use a tool I submitted to the jakarta-commons-io:
http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/FileUtils.java?rev=HEAD&content-type=text/vnd.viewcvs-markup

    I have done some tricks with it in my controller templates:

## ------------------------------------------------------------------------
## Locate the theme
## ------------------------------------------------------------------------
## Try first the user theme
#set( $l_template = "${user}/${theme}.vm" )
#set( $l_file = $ServletContext.getRealPath("templates/$l_template") )
#if( $l_file && $File.fileExists($l_file) )
   #parse( $l_template )
#else
   ## then try the common theme
   #set( $l_template = "control/${theme}.vm" )
   #set( $l_file = $ServletContext.getRealPath("templates/$l_template") )
   #if( $l_file && $File.fileExists($l_file) )
     #parse( $l_template )
   #elseif( $theme == "" )
     #error( "no theme defined." )
   #else
     #error( "" )
   #end
#end

## ------------------------------------------------------------------------
## load (and cache) the user-role-permission configuration
## ------------------------------------------------------------------------
#set( $l_xmlFile = "$ENV.MUIS_NAOMI_CONFIG/ACL.xml" )
#set( $l_fileDate = "$File.getFile($l_xmlFile).lastModified()" )
#if( !$l_fileDate.equals($cache.get('userConfigDate')) )
   ## reload
   #if( !$ACL.loadUserRoles($l_xmlFile) )
     #error( "Failed to load ACL from $l_xmlFile (due to XML errors?)" )
   #else
     #if( $cache.get('userConfigDate') )
       #log( "$date I Reloaded $File.filename($l_xmlFile) file." )
     #end
     #call( $cache.put("userConfigDate", $l_fileDate) )
   #end
#end
##

I hope this helped.

-- 
:) Christoph Reck


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message