@Override protected void loadTemplate(SmooksResourceConfiguration config) throws IOException { String path = config.getResource(); if(path.charAt(0) == '/') { path = path.substring(1); } String dir = path.substring(0, path.lastIndexOf('/')); templateName = path.substring(path.lastIndexOf('/'), path.indexOf(".st")); templateGroupDir = new STRawGroupDir(dir, getEncoding().displayName(),'$','$'); template = templateGroupDir.getInstanceOf(templateName); }
@Override public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) { String template = templateStream.substring(0, templateStream.size() - 1); String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName); String fullyQualifiedTemplateName = prefix + templateName; CompiledST impl = new Compiler(this).compile(fullyQualifiedTemplateName, template); CommonToken nameT = new CommonToken(STLexer.SEMI); // Seems like a hack, best I could come up with. nameT.setInputStream(templateStream); rawDefineTemplate(fullyQualifiedTemplateName, impl, nameT); impl.defineImplicitlyDefinedTemplates(this); return impl; } }
@Override public String render(Map<String, Object> config, File templateFile) throws ExecutorException { try { final File tmplDir = templateFile.getParentFile(); final String tmplName = Util.getBaseFileName(templateFile.getName()); STGroup stg = new STRawGroupDir(tmplDir.toURI().toURL(), Charsets.UTF_8.name(), delimiterStartChar, delimiterStopChar); ST st = stg.getInstanceOf(tmplName); // Populate data: config.entrySet().stream().forEach((e) -> { st.add(e.getKey(), e.getValue()); }); return st.render(); } catch(MalformedURLException ex) { throw new ExecutorException(ex); } }
@Override protected void visit(Element element, ExecutionContext executionContext) { // First thing we do is clone the template for this transformation... // Commented out as due to https://github.com/antlr/stringtemplate4/issues/100 // ST transform = new ST(template); ST transform = templateGroupDir.getInstanceOf(templateName); Map<String, Object> beans = executionContext.getBeanContext().getBeanMap(); // Set the document data beans on the template and apply it... for (Map.Entry<String, Object> entry : beans.entrySet()) { transform.add(entry.getKey(), entry.getValue()); } String templatingResult = transform.render().trim(); Node resultNode = TextSerializationUnit.createTextElement(element, templatingResult); // Process the templating action, supplying the templating result... processTemplateAction(element, resultNode, executionContext); }
@Override public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) { String template = templateStream.substring(0, templateStream.size() - 1); String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName); String fullyQualifiedTemplateName = prefix + templateName; CompiledST impl = new Compiler(this).compile(fullyQualifiedTemplateName, template); CommonToken nameT = new CommonToken(STLexer.SEMI); // Seems like a hack, best I could come up with. nameT.setInputStream(templateStream); rawDefineTemplate(fullyQualifiedTemplateName, impl, nameT); impl.defineImplicitlyDefinedTemplates(this); return impl; } }
@Override protected void visit(Element element, ExecutionContext executionContext) { // First thing we do is clone the template for this transformation... // Commented out as due to https://github.com/antlr/stringtemplate4/issues/100 // ST transform = new ST(template); ST transform = templateGroupDir.getInstanceOf(templateName); Map<String, Object> beans = executionContext.getBeanContext().getBeanMap(); // Set the document data beans on the template and apply it... for (Map.Entry<String, Object> entry : beans.entrySet()) { transform.add(entry.getKey(), entry.getValue()); } String templatingResult = transform.render().trim(); Node resultNode = TextSerializationUnit.createTextElement(element, templatingResult); // Process the templating action, supplying the templating result... processTemplateAction(element, resultNode, executionContext); }
@Override public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) { String template = templateStream.substring(0, templateStream.size() - 1); String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName); String fullyQualifiedTemplateName = prefix + templateName; CompiledST impl = new Compiler(this).compile(fullyQualifiedTemplateName, template); CommonToken nameT = new CommonToken(STLexer.SEMI); // Seems like a hack, best I could come up with. nameT.setInputStream(templateStream); rawDefineTemplate(fullyQualifiedTemplateName, impl, nameT); impl.defineImplicitlyDefinedTemplates(this); return impl; } }
@Override protected void loadTemplate(SmooksResourceConfiguration config) throws IOException { String path = config.getResource(); if(path.charAt(0) == '/') { path = path.substring(1); } String dir = path.substring(0, path.lastIndexOf('/')); templateName = path.substring(path.lastIndexOf('/'), path.indexOf(".st")); templateGroupDir = new STRawGroupDir(dir, getEncoding().displayName(),'$','$'); template = templateGroupDir.getInstanceOf(templateName); }
@Override public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) { String template = templateStream.substring(0, templateStream.size() - 1); String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName); String fullyQualifiedTemplateName = prefix + templateName; CompiledST impl = new Compiler(this).compile(fullyQualifiedTemplateName, template); CommonToken nameT = new CommonToken(STLexer.SEMI); // Seems like a hack, best I could come up with. nameT.setInputStream(templateStream); rawDefineTemplate(fullyQualifiedTemplateName, impl, nameT); impl.defineImplicitlyDefinedTemplates(this); return impl; } }
@Override public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) { String template = templateStream.substring(0, templateStream.size() - 1); String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName); String fullyQualifiedTemplateName = prefix + templateName; CompiledST impl = new Compiler(this).compile(fullyQualifiedTemplateName, template); CommonToken nameT = new CommonToken(STLexer.SEMI); // Seems like a hack, best I could come up with. nameT.setInputStream(templateStream); rawDefineTemplate(fullyQualifiedTemplateName, impl, nameT); impl.defineImplicitlyDefinedTemplates(this); return impl; } }
@Override public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) { String template = templateStream.substring(0, templateStream.size() - 1); String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName); String fullyQualifiedTemplateName = prefix + templateName; CompiledST impl = new Compiler(this).compile(fullyQualifiedTemplateName, template); CommonToken nameT = new CommonToken(STLexer.SEMI); // Seems like a hack, best I could come up with. nameT.setInputStream(templateStream); rawDefineTemplate(fullyQualifiedTemplateName, impl, nameT); impl.defineImplicitlyDefinedTemplates(this); return impl; } }
@Override public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) { String template = templateStream.substring(0, templateStream.size() - 1); String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName); String fullyQualifiedTemplateName = prefix + templateName; CompiledST impl = new Compiler(this).compile(fullyQualifiedTemplateName, template); CommonToken nameT = new CommonToken(STLexer.SEMI); // Seems like a hack, best I could come up with. nameT.setInputStream(templateStream); rawDefineTemplate(fullyQualifiedTemplateName, impl, nameT); impl.defineImplicitlyDefinedTemplates(this); return impl; } }