[stringtemplate-interest] use template groups in a WAR

Harry Karadimas harry.karadimas at hmn.aphp.fr
Tue Nov 14 08:21:53 PST 2006


Hi Nate,

You are right, I made a simple application to try out what you suggested.

The code is here :

    InputStream ins =
      getClass().getResourceAsStream("/stringtemplate_test/grouptest.stg");
    InputStreamReader in = new InputStreamReader(ins);
    StringTemplateGroup g = 
      new StringTemplateGroup(in);
    StringTemplate st = g.getInstanceOf("hello");
    String r = st.toString();    
    System.out.println("r="+r);


If I use this template :

group grouptest;
hello() ::= "<world()>"
world() ::= "Hello from inside of group"


I will as expected get the following output :

r=Hello from inside of group


Now if I remove the declaration for world(), and put instead a template 
file |world.st|, st won't find the
template, wether I put it in the classpath at 
stringtemplate_test/world.st, the local filesystem, etc.

I ran the program with a debugger, and in fact it seems that st while 
parsing the group records
records that it didn't find the template and associates the special 
value NOT_FOUND_ST with the name.
So any further attempt to load the template will fail.
As I can see from the comment of "templatesDefinedInGroupFile" variable, 
this is what was intended,
so I guess for now either everything is inside a group file, or 
everything is inside individual template files.
There does not seem to be any inbetween.
I guess this could be customized using StringTemplateGroupLoader, but I 
didn't check further.

Hope this helps,

                                                       Harry Karadimas
/______________________________________________________________________
Dr Harry Karadimas  Medecin Ingenieur resp. Recherche et Developpement
Departement d'Information Hospitalier
CHU Henri Mondor 51, av. du Mal de Lattre de Tassigny   94010  CRETEIL
tel : (00 33 1) 49 81 21 79                fax : (00 33 1) 49 81 27 08
secr.: (00 33 1) 49 81 23 82 m.el.:harry.karadimas at hmn.ap-hop-paris.fr
/



Nate a écrit :
> Hi Harry, please see my list message in reply to Jean-Marie (sent 
> 11/12/06). I realize that I can access templates on the classpath 
> using a path relative to the root of the classpath. However, I want to 
> access templates on the classpath based on a root directory. This can 
> be done on the filesystem and, IMHO, should also be possible on the 
> classpath.
>
> Thanks,
> -Nate
>
>
> Harry Karadimas wrote:
>> Put your files in /WEB-INF/classes, and try "/" in front of your 
>> path, e.g.
>> */*skins/redtheme/etc.st
>>                                                        Harry Karadimas
>> /______________________________________________________________________
>> Dr Harry Karadimas  Medecin Ingenieur resp. Recherche et Developpement
>> Departement d'Information Hospitalier
>> CHU Henri Mondor 51, av. du Mal de Lattre de Tassigny   94010  CRETEIL
>> tel : (00 33 1) 49 81 21 79                fax : (00 33 1) 49 81 27 08
>> secr.: (00 33 1) 49 81 23 82 m.el.:harry.karadimas at hmn.ap-hop-paris.fr
>> /
>>
>>
>> stringtemplate-interest-request at antlr.org a écrit :
>>> Send stringtemplate-interest mailing list submissions to
>>>     stringtemplate-interest at antlr.org
>>>
>>> To subscribe or unsubscribe via the World Wide Web, visit
>>>     http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>>> or, via email, send a message with subject or body 'help' to
>>>     stringtemplate-interest-request at antlr.org
>>>
>>> You can reach the person managing the list at
>>>     stringtemplate-interest-owner at antlr.org
>>>
>>> When replying, please edit your Subject line so it is more specific
>>> than "Re: Contents of stringtemplate-interest digest..."
>>>
>>>
>>> Today's Topics:
>>>
>>>    1. use template groups in a WAR (Nate)
>>>
>>>
>>> ----------------------------------------------------------------------
>>>
>>> Message: 1
>>> Date: Fri, 10 Nov 2006 17:44:23 -0800
>>> From: Nate <misc at n4te.com>
>>> Subject: [stringtemplate-interest] use template groups in a WAR
>>> To: stringtemplate-interest at antlr.org
>>> Message-ID: <45552AF7.4080904 at n4te.com>
>>> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>>>
>>> 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
>>>     
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061114/6cdb1df0/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: harry.karadimas.vcf
Type: text/x-vcard
Size: 407 bytes
Desc: not available
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061114/6cdb1df0/attachment.vcf 


More information about the stringtemplate-interest mailing list