/** * Sets mapping between names in the search filter template and actual values. * @param key marker in the search filter template. * @param value actual value * @return the current instance of the builder */ public QueryBuilder map(String key, String value) { filterTemplate.add(key, value); return this; }
/** * Sets search filter template. * @param filterTemplate search filter template * @return the current instance of the builder */ public QueryBuilder filter(String filterTemplate) { this.filterTemplate = new ST(filterTemplate); return this; }
private String createFilter() { return filterTemplate.render(); }
private String executeTemplate(Primitive primitive1, Primitive primitive2, String templateName) { ST template = this.findTemplate(templateName); template.add("primitive1", primitive1); template.add("primitive2", primitive2); template.add("sameTwoPrimitives", primitive1 == primitive2); return template.render(); }
public byte[] getTemplateData(String templateResource, Map<String, WidInfo> widInfoMap) throws IOException { ST stTemplate = new ST(getTemplateResourceFileAsString(templateResource), '$', '$'); stTemplate.add("widInfo", widInfoMap); stTemplate.add("openbracket", "{"); stTemplate.add("closebracket", "}"); return stTemplate.render().getBytes(); }
private void setTest() { this.isTest = this.templateFile.getInstanceOf("isTest") == null ? false : Boolean.valueOf(this.templateFile.getInstanceOf("isTest").render()); }
private static ST findTemplateInGroup(String path, String name, STGroup group) { if (!group.isDefined(name)) { throw new IllegalStateException("No StringTemplate group " + name + " for path " + path); } return group.getInstanceOf(name); }
private static STGroup readStringTemplateGroup(ClassLoader classLoader, String path) { try { URL resource = classLoader.getResource(path); STGroupFile group = new STGroupFile(resource, StandardCharsets.UTF_8.name(), '<', '>'); group.load(); return group; } catch (Exception e) { throw new RuntimeException("Unable to read StringTemplate group file at " + path + " on classpath", e); } } }
private ST findTemplate(String templateName) { ST template = this.templateFile.getInstanceOf(templateName); if (template == null) { throw new RuntimeException("Could not find template " + templateName + " in " + this.templateFile.getFileName()); } return template; }
public String toString(Object object, String formatString, Locale locale) { if (!(object instanceof String)) { throw new RuntimeException("Only works on Strings"); } try { Integer integer = Integer.valueOf((String) object); return this.numberRenderer.toString(integer, formatString, locale); } catch (NumberFormatException ignored) { return this.stringRenderer.toString(object, formatString, locale); } } }
private String executeTemplate(Primitive primitive1, Primitive primitive2, String templateName) { ST template = this.findTemplate(templateName); template.add("primitive1", primitive1); template.add("primitive2", primitive2); template.add("sameTwoPrimitives", primitive1 == primitive2); return template.render(); }
private void setTest() { this.isTest = this.templateFile.getInstanceOf("isTest") == null ? false : Boolean.valueOf(this.templateFile.getInstanceOf("isTest").render()); }
/** * Sets mapping between names in the search filter template and actual values. * @param key marker in the search filter template. * @param values array of values * @return the current instance of the builder */ public QueryBuilder map(String key, String[] values) { filterTemplate.add(key, values); return this; }
/** * Locates SQL for the given type and name. Example: Given a type <code>com.foo.Bar</code> and a name of * <code>baz</code>, loads a StringTemplate group file from the resource named <code>com/foo/Bar.sql.stg</code> on * the classpath, and returns the template with the given name from the group. * * @param type the type that "owns" the given StringTemplate group file. Dictates the filename of the * StringTemplate group file on the classpath. * @param name the template name within the StringTemplate group. * @return the located SQL. */ public static ST findStringTemplate(Class<?> type, String name) { STGroup group = findStringTemplateGroup(type); if (!group.isDefined(name)) { throw new IllegalStateException("No StringTemplate group " + name + " for class " + type); } return group.getInstanceOf(name); }
private ST findTemplate(String templateName) { ST template = this.templateFile.getInstanceOf(templateName); if (template == null) { throw new RuntimeException("Could not find template " + templateName + " in " + this.templateFile.getFileName()); } return template; }