[stringtemplate-interest] Group files deployed in WAR

Michael Cronk mcronk at yahoo.com
Fri May 9 15:05:02 PDT 2008


I have successfully loaded a group (.stg) file when deployed in a WAR file using basically the following logic:

// Get group
org.antlr.stringtemplate.StringTemplateGroup stringTemplateGroup = null;
java.io.InputStream inputStream = null;
java.io.Reader reader = null;
try {
  java.lang.ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  inputStream = classLoader.getResourceAsStream(resourceName);
  reader = new java.io.InputStreamReader(inputStream);
  stringTemplateGroup = new org.antlr.stringtemplate.StringTemplateGroup(reader);
} finally {
  if (inputStream != null) { inputStream.close(); }
  if (reader != null) { reader.close(); }
}
// Get template
org.antlr.stringtemplate.StringTemplate stringTemplate = null;
stringTemplate = stringTemplateGroup .getInstanceOf(templateName);

However, if I try to move some of the common logic into a super group, the parser fails.
For example (and a very loose example at that): 

 ***** supergroup.stg:

group supergroup;

stringData() ::= "<data>"

 ***** subgroup.stg:

group subgroup : supergroup;

method(data) ::= "<stringData()>"

Basically, the stringData() template is not found.  It also dumps the message "no group loader registered" to the console.

I have all the templates deployed in WEB-INF/classes/tpl.  When I loaded the template, I used "tpl/subgroup.stg" as the resource name.
"supergroup.stg" is in the same path.

I prefer to place common templates in a supergroup, and don't know if this is even possible when deployed in a WAR file.
Any help would be greatly appreciated. 
Thanks in advance, Michael.


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


More information about the stringtemplate-interest mailing list