[prev in list] [next in list] [prev in thread] [next in thread]
List: velocity-user
Subject: Re: mergeTemplate - non-standard resource
From: Byron Foster <byron () base2 ! cc>
Date: 2009-05-05 19:36:18
Message-ID: D50E8603-C487-49D9-9972-36B4C098BF16 () base2 ! cc
[Download RAW message or body]
On May 5, 2009, at 5:01 , Mark Fenbers wrote:
> I need to give some background info before I ask the Velocity
> question...
>
> I've changed my code to use class resources instead of absolute or
> relative pathnames. In other words, I changed this:
>
> Image myImage = new Image(display, "bin/gov/noaa/ohrfc/resources/
> rvf.icon.png");
>
> to this:
>
> Image myImage = new Image(display,
> this.getClass().getResource("resources/rvf.icon.png").getFile());
>
> This is less direct, but has several advantages, including that
> getResource uses the class location (bin/gov/noaa/ohrfc) to complete
> the full pathname of "resource/rvf.icon.png". The getFile() method
> will return the full pathname of the file (which is: /home/oper/
> workspace/GIFTS/bin/gov/noaa/ohrfc/resources/rvf.icon.png). This
> makes it more portable, and makes it more compatible with using Java
> Web Start for this application. Using getResource(), my code
> doesn't break if I move my classes somewhere else besides "bin/gov/
> noaa/ohrfc".
>
> The problem comes in with Velocity's mergeTemplate() method which
> chokes when an absolute pathname is used. It also chokes when I use
> a pathname that is relative to the class location. Rather, it
> requires something in between whereby I have to specify the class
> location *and* the relative path to the template file, namely, I
> need to specify "bin/gov/noaa/ohrfc/resources/SHEF.template",
> whereas I want to specify "resources/SHEF.template" or give it the
> full absolute pathname.
>
> I am using version 1.6.1-dep. Does a later version fix this
> problem? Or is there another work-around where I can either: 1)
> avoid giving the class location (bin/gov/noaa/ohrfc)' or 2) give the
> entire absolute path location [which can be determined on-the-fly
> using getResource().getFile()]?
Could you do something like so with your absolute paths:
file.resource.loader.path = /
There may be security considerations, but you could also set the
resource loader path to something more reasonable, and within a
wrapper method around templateMerge you could remove any base
directory from the merge path.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic