[stringtemplate-interest] Problem in StringTemplate V4
Cliff Zhao
zhaotq at gmail.com
Thu Mar 4 11:19:16 PST 2010
I run into problem for StringTemplate V4. It failed in my Windows XP
environment.
I did some debug, and found the problem is about forward slash (/) and back
slash(\).
The File(name).getParent() return OS-specific path. On Windows, it is "\".
So, when I load a template in a group like
group.getInstanceOf("admin/home"), it returns null.
The code in STGroupDir.java:
public CompiledST loadTemplateFile(String fileName) {
//System.out.println("load "+fileName+" from "+root);
String prefix = new File(fileName).getParent();
if ( !prefix.endsWith("/") ) prefix += "/";
try {
String templateName = Misc.getFileNameNoSuffix(fileName);
URL f = new URL(root+fileName);
ANTLRInputStream fs = new ANTLRInputStream(f.openStream(),
encoding);
if ( ErrorManager.v3_mode) {
String template = fs.toString(); // needs > ANTLR 3.2
template = template.trim();
String justName = new File(templateName).getName();
defineTemplate(prefix,
new CommonToken(GroupParser.ID,justName),
null,
template);
}
else {
GroupLexer lexer = new GroupLexer(fs);
fs.name = fileName;
CommonTokenStream tokens = new CommonTokenStream(lexer);
GroupParser parser = new GroupParser(tokens);
parser.group = this;
=A=====> parser.templateDef(prefix);
}
=B=====> return templates.get(templateName);
}
After the A point, the templates variable contains one entry {
"\admin/home", --parsed ST--}.
At the B point, the templateName is "/admin/home". It is a mismatch!
Could you fix it?
Thank you very much.
Best Regards,
Cliff Zhao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20100304/fdb37fd3/attachment.html
More information about the stringtemplate-interest
mailing list