Refine search
private STGroupDir loadGroupDir(String path) { try { return new STGroupDir(path, '$', '$'); } catch (IllegalArgumentException e) { //websphere classloader needs a trailing / to find directories on the classpath //-> add it to check if it exists, and then remove it final STGroupDir stGroupDir = new STGroupDir(path + "/", '$', '$'); final String url = stGroupDir.root.toExternalForm(); try { stGroupDir.root = new URL(url.substring(0, url.length() - 1)); return stGroupDir; } catch (MalformedURLException me) { throw new IllegalArgumentException(me); } } }
groupFileURL = new URL(root+parent+".stg"); is = groupFileURL.openStream(); return loadTemplateFile(parent, name+".st"); // load t.st file errMgr.internalError(null, "can't close template file stream "+name, ioe); loadGroupFile(parent, root+parent+".stg"); return rawGetTemplate(name);
@Override public void importTemplates(Token fileNameToken) { String msg = "import illegal in group files embedded in STGroupDirs; "+ "import "+fileNameToken.getText()+" in STGroupDir "+this.getName(); throw new UnsupportedOperationException(msg); }
public class App { public static void main(String[] args) { STGroupDir group = new STGroupDir("src/main/resource", '$', '$'); group.registerRenderer(String.class, new HtmlEscapeStringRenderer()); ST st = group.getInstanceOf("people"); st.add("people", Arrays.asList( new Person("<b>Dave</b>", "dave@ohai.com"), new Person("<b>Nick</b>", "nick@kthxbai.com") )); System.out.println(st.render()); } public static class HtmlEscapeStringRenderer implements AttributeRenderer { public String toString(Object o, String s, Locale locale) { return (String) (s == null ? o : StringEscapeUtils.escapeHtml((String) o)); } } }
fileUnderRoot = new URL(thisRoot+"/"+fileName); if ( fileURL!=null ) { try { InputStream s = fileURL.openStream(); ANTLRInputStream templateStream = new ANTLRInputStream(s, encoding); templateStream.name = fileName; g = new STGroupDir(fileUnderRoot, encoding, delimiterStartChar, delimiterStopChar); g.setListener(this.getListener()); g = new STGroupDir(fileName, delimiterStartChar, delimiterStopChar); g.setListener(this.getListener());
/** Load .st as relative file name relative to root by {@code prefix}. */ public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName) { if ( verbose ) System.out.println("loadTemplateFile("+unqualifiedFileName+") in groupdir "+ "from "+root+" prefix="+prefix); URL f; try { f = new URL(root+prefix+unqualifiedFileName); } catch (MalformedURLException me) { errMgr.runTimeError(null, null, ErrorType.INVALID_TEMPLATE_NAME, me, root + unqualifiedFileName); return null; } ANTLRInputStream fs; try { fs = new ANTLRInputStream(f.openStream(), encoding); fs.name = unqualifiedFileName; } catch (IOException ioe) { if ( verbose ) System.out.println(root+"/"+unqualifiedFileName+" doesn't exist"); //errMgr.IOError(null, ErrorType.NO_SUCH_TEMPLATE, ioe, unqualifiedFileName); return null; } return loadTemplateFile(prefix, unqualifiedFileName, fs); }
/** * Get the body content of the email. * * @param resetUrl the password reset URL * @param account the user account that has had its password reset * @param locale the locale of the user who reset the password * @return The message body as a string. */ private String formatBody(URL resetUrl, ILocalAccountPerson account, Locale locale) { final STGroup group = new STGroupDir(templateDir, '$', '$'); final ST template = group.getInstanceOf(templateName); String name = findDisplayNameFromLocalAccountPerson(account); template.add("displayName", name); template.add("url", resetUrl.toString()); return template.render(); }
STGroup group = new STGroupDir("emails", '$','$');
protected void generateAggregateResultClasses(String packageName, File dir) throws IOException { ClassMetadata gen = new ClassMetadata(packageName, null); ST template = templates.getInstanceOf(AGGREGATE_RESULT); javaFiles.add(generate(packageName, AGGREGATE_RESULT_JAVA, gen, template, dir)); }
fileUnderRoot = new URL(thisRoot+"/"+fileName); if ( fileURL!=null ) { try { InputStream s = fileURL.openStream(); ANTLRInputStream templateStream = new ANTLRInputStream(s); templateStream.name = fileName; g = new STGroupDir(fileUnderRoot, encoding, delimiterStartChar, delimiterStopChar); g.setListener(this.getListener()); g = new STGroupDir(fileName, delimiterStartChar, delimiterStopChar); g.setListener(this.getListener());
/** Load .st as relative file name relative to root by {@code prefix}. */ public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName) { if ( verbose ) System.out.println("loadTemplateFile("+unqualifiedFileName+") in groupdir "+ "from "+root+" prefix="+prefix); URL f; try { f = new URL(root+prefix+unqualifiedFileName); } catch (MalformedURLException me) { errMgr.runTimeError(null, null, ErrorType.INVALID_TEMPLATE_NAME, me, root + unqualifiedFileName); return null; } ANTLRInputStream fs; try { fs = new ANTLRInputStream(f.openStream(), encoding); fs.name = unqualifiedFileName; } catch (IOException ioe) { if ( verbose ) System.out.println(root+"/"+unqualifiedFileName+" doesn't exist"); //errMgr.IOError(null, ErrorType.NO_SUCH_TEMPLATE, ioe, unqualifiedFileName); return null; } return loadTemplateFile(prefix, unqualifiedFileName, fs); }
STGroup group = new STGroupDir("templates",'$','$');
protected void generateAggregateResultClasses(String packageName, File dir) throws IOException { ClassMetadata gen = new ClassMetadata(packageName, null); ST template = templates.getInstanceOf(AGGREGATE_RESULT); javaFiles.add(generate(packageName, AGGREGATE_RESULT_JAVA, gen, template, dir)); }
groupFileURL = new URL(root+parent+GROUP_FILE_EXTENSION); is = groupFileURL.openStream(); return loadTemplateFile(prefix, unqualifiedName+TEMPLATE_FILE_EXTENSION); // load t.st file loadGroupFile(prefix, root+parent+GROUP_FILE_EXTENSION); return rawGetTemplate(name);
fileUnderRoot = new URL(thisRoot+"/"+fileName); if ( fileURL!=null ) { try { InputStream s = fileURL.openStream(); ANTLRInputStream templateStream = new ANTLRInputStream(s, encoding); templateStream.name = fileName; g = new STGroupDir(fileUnderRoot, encoding, delimiterStartChar, delimiterStopChar); g.setListener(this.getListener()); g = new STGroupDir(fileName, delimiterStartChar, delimiterStopChar); g.setListener(this.getListener());
/** Load .st as relative file name relative to root by {@code prefix}. */ public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName) { if ( verbose ) System.out.println("loadTemplateFile("+unqualifiedFileName+") in groupdir "+ "from "+root+" prefix="+prefix); URL f = null; try { f = new URL(root+prefix+unqualifiedFileName); } catch (MalformedURLException me) { errMgr.runTimeError(null, null, ErrorType.INVALID_TEMPLATE_NAME, me, root + unqualifiedFileName); return null; } ANTLRInputStream fs; try { fs = new ANTLRInputStream(f.openStream(), encoding); fs.name = unqualifiedFileName; } catch (IOException ioe) { if ( verbose ) System.out.println(root+"/"+unqualifiedFileName+" doesn't exist"); //errMgr.IOError(null, ErrorType.NO_SUCH_TEMPLATE, ioe, unqualifiedFileName); return null; } return loadTemplateFile(prefix, unqualifiedFileName, fs); }
STGroup group = new STGroupDir("shiro/definitions/test"); ST st = group.getInstanceOf("decl");
@Override public void importTemplates(Token fileNameToken) { String msg = "import illegal in group files embedded in STGroupDirs; "+ "import "+fileNameToken.getText()+" in STGroupDir "+this.getName(); throw new UnsupportedOperationException(msg); }
private void generateConnectorClasses(Definitions definitions, File dir) throws IOException { ConnectorMetadata gen = new ConnectorMetadata(definitions, packagePrefix); ST template = templates.getInstanceOf(CONNECTOR); javaFiles.add(generate(gen.getPackageName(), CONNECTOR_JAVA, gen, template, dir)); }
groupFileURL = new URL(root+parent+GROUP_FILE_EXTENSION); is = groupFileURL.openStream(); return loadTemplateFile(prefix, unqualifiedName+TEMPLATE_FILE_EXTENSION); // load t.st file loadGroupFile(prefix, root+parent+GROUP_FILE_EXTENSION); return rawGetTemplate(name);