You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Morten Hoyer <mo...@noosh.com> on 2001/05/10 18:20:52 UTC

File resource loaded and absolute paths

I'm currently using Velocity, and it's using the build-in file resource
loader to load templates. It's configured with a "base path" and templates
are loaded with relative file-names. However, we would like the "base path"
to be empty, and pass absolute files names to Velocity. This does not seem
to work at all. Is it doable without rewriting the resource loader?

Sincerely,
Morten Hoyer



Re: File resource loaded and absolute paths

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
> Morten Hoyer wrote:
> 
> I'm currently using Velocity, and it's using the build-in file
> resource loader to load templates. It's configured with a "base path"
> and templates are loaded with relative file-names. However, we would
> like the "base path" to be empty, and pass absolute files names to
> Velocity. This does not seem to work at all. Is it doable without
> rewriting the resource loader?
> 

Why not make the template root to be root itself?

Velocity.setProperty("file.resource.loader.path", "/");
Velocity.init();


and then


Template t = Velocity.getTemplate("/etc/passwd");

should work just fine.  I haven't tried it, but I can't see why not....

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: File resource loaded and absolute paths

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
"Geir Magnusson Jr." wrote:
> 
> Jon Stevens wrote:
> >
> > on 5/10/01 9:20 AM, "Morten Hoyer" <mo...@noosh.com> wrote:
> >
> > > I'm currently using Velocity, and it's using the build-in file resource loader
> > > to load templates. It's configured with a "base path" and templates are loaded
> > > with relative file-names. However, we would like the "base path" to be empty,
> > > and pass absolute files names to Velocity. This does not seem to work at all.
> > > Is it doable without rewriting the resource loader?
> > >
> > > Sincerely,
> > > Morten Hoyer
> >
> > It is a potential security hole to do that and requires you to write your
> > own resource loader (it isn't that hard).
> >
> 
> Well... one solution that has been discussed is a switch, something like
> :
> 
> file.resource.loader.voidpath
> file.resource.loader.russianroulettewithautomatic
> file.resource.loader.landwarinasia
> 
> that would make this so.
> 
> Seriously, for application users, this makes sense.  I think that for
> web users, it's a horrible idea, but for use in non-web apps (code, sql,
> text, etc generation...) this isn't so bad.
> 

Thinking another 5 seconds or so, an application really doesn't need a
loader  :

StringWriter w = new StringWriter();

Velocity.evaluate( context, w, "myfile", BufferedReader( new
FileReader("myfile.vm") );

should do the trick...

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: File resource loaded and absolute paths

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Jon Stevens wrote:
> 
> on 5/10/01 9:20 AM, "Morten Hoyer" <mo...@noosh.com> wrote:
> 
> > I'm currently using Velocity, and it's using the build-in file resource loader
> > to load templates. It's configured with a "base path" and templates are loaded
> > with relative file-names. However, we would like the "base path" to be empty,
> > and pass absolute files names to Velocity. This does not seem to work at all.
> > Is it doable without rewriting the resource loader?
> >
> > Sincerely,
> > Morten Hoyer
> 
> It is a potential security hole to do that and requires you to write your
> own resource loader (it isn't that hard).
> 

Well... one solution that has been discussed is a switch, something like
:

file.resource.loader.voidpath
file.resource.loader.russianroulettewithautomatic
file.resource.loader.landwarinasia

that would make this so.

Seriously, for application users, this makes sense.  I think that for
web users, it's a horrible idea, but for use in non-web apps (code, sql,
text, etc generation...) this isn't so bad.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: File resource loaded and absolute paths

Posted by Jon Stevens <jo...@latchkey.com>.
on 5/10/01 9:20 AM, "Morten Hoyer" <mo...@noosh.com> wrote:

> I'm currently using Velocity, and it's using the build-in file resource loader
> to load templates. It's configured with a "base path" and templates are loaded
> with relative file-names. However, we would like the "base path" to be empty,
> and pass absolute files names to Velocity. This does not seem to work at all.
> Is it doable without rewriting the resource loader?
> 
> Sincerely, 
> Morten Hoyer 

It is a potential security hole to do that and requires you to write your
own resource loader (it isn't that hard).

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>