[stringtemplate-interest] use template groups in a WAR
Nate
misc at n4te.com
Sun Nov 12 21:59:20 PST 2006
Hi Jean-Marie,
I think the question was misunderstood. If I put the skins on the
classpath, whether in a JAR or in the classes directory of the WAR, then
the only way to access the skins is by their absolute path in the
classpath. To do this, I create a StringTemplateGroup with no rootDir.
For example...
skinName = "redtheme";
group = new StringTemplateGroup("allSkins");
group.getInstanceOf("skins/" + skinName + "/page");
group.getInstanceOf("skins/" + skinName + "/etc");
This is not what I want. I want to use a StringTemplateGroup from the
classpath just like I do from the filesystem. This is how I use it from
the filesystem...
skinName = "redtheme";
group = new StringTemplateGroup(skinName, "skins");
group.getInstanceOf("page");
group.getInstanceOf ("etc");
I have the following three questions:
1. How can I use a StringTemplateGroup from the classpath just like I do
from the filesystem?
2. If this is not possible, what is the workaround that people use? I
cannot imagine this being a rare request.
3. If there is no workaround, will a reasonable patch be excepted? The
current constructors would stay the same and function in the same way.
My patch would add a constructor StringTemplateGroup(name, rootDir,
isClasspath) that functions as expected.
Thanks,
-Nate
Jean-Marie Renouard wrote:
> Hello,
>
> Several solutions exist :
> 1) Use a jar for template in the WEB-INF/lib
> 2) place your templates in the classpath : WEB-INF/classes for example.
> so in your case,
> WEB-INF/classes/skins/...
>
> Have a nice week :)
> Jean-Marie
>
> On 11/11/06, *Nate* <misc at n4te.com <mailto:misc at n4te.com>> wrote:
>
> I am writing a web application. I want to use StringTemplate to
> generate
> the HTML pages. I want users to be able to select a "skin" from a
> list.
> Each skin would use a different set of templates to display the HTML.
>
> My initial impression is that I'd use a different StringTemplateGroup
> for each skin. I imagined a file structure like this...
>
> skins/redtheme/page.st
> skins/redtheme/etc.st
> skins/bluetheme/page.st
> skins/bluetheme/etc.st
>
> ...the code would be something like...
>
> skinName = "redtheme";
> group = new StringTemplateGroup(skinName, "skins");
> group.getInstanceOf("page");
> group.getInstanceOf ("etc");
>
> This works fine on the filesystem. Now I zip my application up into a
> WAR file and suddenly the templates cannot be found. Next I think I
> should look up templates using the classpath. StringTemplate
> documentation leads me to think I need to use code like this...
>
> skinName = "redtheme";
> group = new StringTemplateGroup("allSkins");
> group.getInstanceOf("skins/" + skinName + "/page");
> group.getInstanceOf("skins/" + skinName + "/etc");
>
> There is no "rootDir" when using the classpath, so I cannot use the a
> StringTemplateGroup for each skin, like I could on the filesystem.
>
> What is the solution? How do other people do it? Why does it work so
> differently when JARed or WARed?
>
> Regards,
> Nathan Sweet
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> <mailto:stringtemplate-interest at antlr.org>
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
> <http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest>
>
>
>
>
> --
> Cordialement,
> Jean-Marie Renouard
More information about the stringtemplate-interest
mailing list