use of st4hidden.org.antlr.runtime.ANTLRInputStream in project bndtools by bndtools.
the class StringTemplateEngine method loadRawTemplate.
private CompiledST loadRawTemplate(STGroup stg, String name, Resource resource) throws IOException {
if (resource.getType() != ResourceType.File)
throw new IllegalArgumentException(String.format("Cannot build resource from resource of type %s (name='%s').", resource.getType(), name));
try (InputStream is = resource.getContent()) {
ANTLRInputStream templateStream = new ANTLRInputStream(is, resource.getTextEncoding());
String template = templateStream.substring(0, templateStream.size() - 1);
CompiledST impl = new Compiler(stg).compile(name, template);
CommonToken nameT = new CommonToken(STLexer.SEMI);
nameT.setInputStream(templateStream);
stg.rawDefineTemplate("/" + name, impl, nameT);
impl.defineImplicitlyDefinedTemplates(stg);
return impl;
}
}
use of st4hidden.org.antlr.runtime.ANTLRInputStream in project bndtools by bndtools.
the class StringTemplateEngine method loadTemplate.
private void loadTemplate(STGroup stg, String fileName, InputStream is, String encoding) throws IOException {
ANTLRInputStream charStream = new ANTLRInputStream(is, encoding);
charStream.name = fileName;
try {
stg.loadTemplateFile("/", fileName, charStream);
} catch (NullPointerException e) {
throw new IOException(String.format("Error loading template file: %s. Ensure the file contains a template definition matching the file name.", fileName), e);
}
}
Aggregations