You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Dickerson, Monty W." <Mo...@viatel.com> on 2000/09/01 20:58:08 UTC

TemplatePath - is it absolute or relative?

in Velocity: 
	TemplatePath - is it absolute or relative?

One shortfall in WM that was annoying was the limitation 
that the #include and #parse directives required an absolute path 
to their target ... did not allow a RELATIVE path or just the filename;

the absolute path prefix should be specified in the WebMacro.properties
file, NOT IN EACH AND EVERY TEMPLATE ON THE SITE.

Why?  This makes the templates non-portable, and does not support
the three tier (dev server, staging server, deployed/prod server) model
of web development.

cheers,
montyd


--ORIGINAL MESSAGE FOLLOWS--
Date: Fri, 01 Sep 2000 17:02:34 +0100
From: Ed Randall <ed...@sellbuysector.com>
To: webmacro list <we...@lists.semiotek.com>
Subject: Re: [Webmacro] TemplatePath - is it absolute or relative?

Do people really build scalable high-performance web applications
on anything other than Unix ? ;-)

Maybe it's not a 100% solution for everybody, but my fix 
_doesn't_ actually _break_ anything,  and _does_ provide
the benefit of allowing absolute paths within the same filesystem
on Windows, and on any mounted filesystem on Unix, something
not previously possible.

It might be better to re-code it as follows using File.isAbsolute()
then though I believe isAbsolute() may be available on JDK 1.2 
only since this issue was once-upon-a-time quite high up on 
Sun's bug parade:

final public Template get(String fileName) {
    Template t;

    // First check for and handle absolute an absolute fileName
    File tFile = new File(fileName);
    if (tFile.isAbsolute()) {
        if (tFile.canRead()) {
            try {
                if (_debug) {
                    _log.debug("TemplateProvider: loading " + tFile);
                }
                t = new FileTemplate(_broker,tFile);
                t.parse();
                return t;
            } catch (Exception e) {
                _log.exception(e);
                _log.warning("TemplateProvider: Could not load template: "
                             + tFile);
            }

            if (_debug) {
                _log.debug("TemplateProvider: " + fileName + " not found.");
            }
        }
        return null;
    }

    // fileName must be relative, search the path for it
    for (int i=0; i < templateDirectory_.length; i++) {
         String dir = templateDirectory_[i];

         if (_debug) {
             _log.debug("TemplateProvider: searching directory " + dir);
         }

         tFile = new File(dir,fileName); // fileName is relative.

         if (tFile.canRead()) {
            try {
                if (_debug) {
                    _log.debug("TemplateProvider: loading " + tFile);
                }
                t = new FileTemplate(_broker,tFile);
                t.parse();
                return t;
            } catch (Exception e) {
                 _log.exception(e);
                 _log.warning("TemplateProvider: Could not load template: "
                             + tFile);
            }
            if (_debug) {
                _log.debug("TemplateProvider: " + fileName + " not found.");
            }
        }
    }
    return null;
}

Regards,

Ed

Fergus Gallagher wrote:
> 
> That could break on non-Unix since fileName could be something like
> X:\xxxx\.....
> 
> Also, Java works with /path/path/... as well as \\path\\path on Windows,
so
> File.separator won't be right. You could try
> 
>          if (fileName.replace(File.separator,"/").startsWith("/"))
> 
> but this doesn't solve the first problem.
> 
> Fergus
>
> > > [ CHOP !]

============================================================
Ed Randall                       Freelance software engineer
IngenoTech Ltd.                    http://www.ingenotech.com
Tel: 020 8892 4803          email: Ed.Randall@ingenotech.com
Mob: 07946 451 696     alternate email: Ed_Randall@yahoo.com
============================================================


Re: TemplatePath - is it absolute or relative?

Posted by Justin Wells <jr...@semiotek.com>.
OK, whatever. I have to write up a bunch of specs for AltaVista 
anyway, so what I'm plannign to do is turn those into a draft of
a spec. It won't be exactly like a spec should be written, but 
it'll be good material to start from.

Justin


On Fri, Sep 01, 2000 at 01:22:18PM -0700, Jon Stevens wrote:
> on 9/1/2000 1:17 PM, "Justin Wells" <jr...@semiotek.com> wrote:
> 
> > I'm gonna start work on it next week. We should start a private
> > list for this so we can argue and fight about it without hanging
> > out a lot of dirty laundry :-)
> > 
> > We'd work it out in private and periodically post snapshots to the
> > userbase to get feedback. Ultimately they'd vote on it.
> > 
> > Justin
> 
> I would be very much against a "private" list. This is the mentality that
> the JCP process @ Sun employs and it sucks balls.
> 
> Yes, we should use another list that people can subscribe to if they are
> interested (with disclaimers of the possibility of a flame war breaking
> out), but I'm very against making things like this private.
> 
> -jon
> 
> -- 
> http://scarab.tigris.org/    | http://noodle.tigris.org/
> http://java.apache.org/      | http://java.apache.org/turbine/
> http://www.working-dogs.com/ | http://jakarta.apache.org/velocity/
> http://www.collab.net/       | http://www.sourcexchange.com/
> 
> 

Re: TemplatePath - is it absolute or relative?

Posted by Jon Stevens <jo...@latchkey.com>.
on 9/1/2000 1:17 PM, "Justin Wells" <jr...@semiotek.com> wrote:

> I'm gonna start work on it next week. We should start a private
> list for this so we can argue and fight about it without hanging
> out a lot of dirty laundry :-)
> 
> We'd work it out in private and periodically post snapshots to the
> userbase to get feedback. Ultimately they'd vote on it.
> 
> Justin

I would be very much against a "private" list. This is the mentality that
the JCP process @ Sun employs and it sucks balls.

Yes, we should use another list that people can subscribe to if they are
interested (with disclaimers of the possibility of a flame war breaking
out), but I'm very against making things like this private.

-jon

-- 
http://scarab.tigris.org/    | http://noodle.tigris.org/
http://java.apache.org/      | http://java.apache.org/turbine/
http://www.working-dogs.com/ | http://jakarta.apache.org/velocity/
http://www.collab.net/       | http://www.sourcexchange.com/



Re: TemplatePath - is it absolute or relative?

Posted by Justin Wells <jr...@semiotek.com>.
I'm gonna start work on it next week. We should start a private
list for this so we can argue and fight about it without hanging
out a lot of dirty laundry :-)

We'd work it out in private and periodically post snapshots to the 
userbase to get feedback. Ultimately they'd vote on it.

Justin

On Fri, Sep 01, 2000 at 01:00:17PM -0700, Jon Stevens wrote:
> on 9/1/2000 1:03 PM, "Justin Wells" <jr...@semiotek.com> wrote:
> 
> > You can assume that the compatibility
> > "requirement" is to support all of relative paths, absolute paths,
> > and URLs.
> 
> Justin, lets get a spec done ASAP.
> 
> -jon
> 
> -- 
> http://scarab.tigris.org/    | http://noodle.tigris.org/
> http://java.apache.org/      | http://java.apache.org/turbine/
> http://www.working-dogs.com/ | http://jakarta.apache.org/velocity/
> http://www.collab.net/       | http://www.sourcexchange.com/
> 
> 

Re: Spec

Posted by Jon Stevens <jo...@latchkey.com>.
on 9/1/2000 1:18 PM, "Travis Low" <tr...@dawnstar.org> wrote:

> Will you spec out the (default) language separately from the template
> engine?

Here is the type of wording that would go into the spec...

The template engine is an implementation of a language. The container
"Velocity" should be able to implement multiple template engines.

The spec will define the interfaces for the template engine as well as the
definition of the language (as well as other stuff).

-jon

-- 
http://scarab.tigris.org/    | http://noodle.tigris.org/
http://java.apache.org/      | http://java.apache.org/turbine/
http://www.working-dogs.com/ | http://jakarta.apache.org/velocity/
http://www.collab.net/       | http://www.sourcexchange.com/



Spec

Posted by Travis Low <tr...@dawnstar.org>.
Jon Stevens wrote:
> 
> on 9/1/2000 1:03 PM, "Justin Wells" <jr...@semiotek.com> wrote:
> 
> > You can assume that the compatibility
> > "requirement" is to support all of relative paths, absolute paths,
> > and URLs.
> 
> Justin, lets get a spec done ASAP.

Will you spec out the (default) language separately from the template
engine?

-- Travis Low  
   <ma...@dawnstar.org>
   <http://dawnstar.org/travis>

Re: TemplatePath - is it absolute or relative?

Posted by Jon Stevens <jo...@latchkey.com>.
on 9/1/2000 1:03 PM, "Justin Wells" <jr...@semiotek.com> wrote:

> You can assume that the compatibility
> "requirement" is to support all of relative paths, absolute paths,
> and URLs.

Justin, lets get a spec done ASAP.

-jon

-- 
http://scarab.tigris.org/    | http://noodle.tigris.org/
http://java.apache.org/      | http://java.apache.org/turbine/
http://www.working-dogs.com/ | http://jakarta.apache.org/velocity/
http://www.collab.net/       | http://www.sourcexchange.com/



Re: TemplatePath - is it absolute or relative?

Posted by Justin Wells <jr...@semiotek.com>.
On Fri, Sep 01, 2000 at 01:58:08PM -0500, Dickerson, Monty W. wrote:
> One shortfall in WM that was annoying was the limitation 
> that the #include and #parse directives required an absolute path 
> to their target ... did not allow a RELATIVE path or just the filename;

That was only in the last snapshot. Historically #parse/#include are 
supposed to support relatives. You can assume that the compatibility
"requirement" is to support all of relative paths, absolute paths, 
and URLs. On the WM list we are talking about extending this to 
support classloading as well, I think a patch is being uploaded now
to implement all this stuff.

Wm is up to 13 core developers now and looking for more. The Vel/WM
projects are merging so of course Vel developers are all welcome.

Justin


Re: TemplatePath - is it absolute or relative?

Posted by Jon Stevens <jo...@latchkey.com>.
on 9/1/2000 11:58 AM, "Dickerson, Monty W." <Mo...@viatel.com>
wrote:

> in Velocity: 
> TemplatePath - is it absolute or relative?
> 
> One shortfall in WM that was annoying was the limitation
> that the #include and #parse directives required an absolute path
> to their target ... did not allow a RELATIVE path or just the filename;
> 
> the absolute path prefix should be specified in the WebMacro.properties
> file, NOT IN EACH AND EVERY TEMPLATE ON THE SITE.
> 
> Why?  This makes the templates non-portable, and does not support
> the three tier (dev server, staging server, deployed/prod server) model
> of web development.
> 
> cheers,
> montyd

I think there should be different TemplateLoaders that allow you to do
something like this:

RelativeTemplateLoader and AbsoluteTemplateLoader.

That way, it is up to you to choose.

Yes, monty, I agree that relative paths to the TemplateRoot is better. It
also helps enforce security issues. We need to watch out for ../ in the path
though to prevent people from "escaping" the relative root path.

-jon

-- 
http://scarab.tigris.org/    | http://noodle.tigris.org/
http://java.apache.org/      | http://java.apache.org/turbine/
http://www.working-dogs.com/ | http://jakarta.apache.org/velocity/
http://www.collab.net/       | http://www.sourcexchange.com/