use of com.github.jknack.handlebars.Handlebars in project acs-aem-commons by Adobe-Consulting-Services.
the class QueryReportExecutor method prepareStatement.
private void prepareStatement() throws ReportException {
try {
Map<String, String> parameters = new HashMap<String, String>();
Enumeration<String> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String key = paramNames.nextElement();
parameters.put(key, StringEscapeUtils.escapeSql(request.getParameter(key)));
}
log.trace("Loading parameters from request: {}", parameters);
Handlebars handlebars = new Handlebars();
Template template = handlebars.compileInline(config.getQuery());
statement = template.apply(parameters);
log.trace("Loaded statement: {}", statement);
} catch (IOException ioe) {
throw new ReportException("Exception templating query", ioe);
}
}
use of com.github.jknack.handlebars.Handlebars in project cloudbreak by hortonworks.
the class HandlebarUtils method handlebars.
public static Handlebars handlebars() {
Handlebars handlebars = new Handlebars();
handlebars.with(value -> StringEscapeUtils.escapeJava(value.toString()));
handlebars.registerHelper(EqHelper.NAME, EqHelper.INSTANCE);
handlebars.registerHelper(NeqHelper.NAME, NeqHelper.INSTANCE);
handlebars.registerHelperMissing((context, options) -> options.fn.text());
return handlebars;
}
use of com.github.jknack.handlebars.Handlebars in project ballerina by ballerina-lang.
the class CodeGenerator method compileTemplate.
/**
* This method will compile and return template of passed template definition.
*
* @param defaultTemplateDir template directory which contains set of templates
* @param templateName template file name to be used as template
* @return compiled template generated for template definition.
* @throws CodeGeneratorException throws IOException when compilation error occurs.
*/
private Template compileTemplate(String defaultTemplateDir, String templateName) throws CodeGeneratorException {
String templatesDirPath = System.getProperty(GeneratorConstants.TEMPLATES_DIR_PATH_KEY, defaultTemplateDir);
ClassPathTemplateLoader cpTemplateLoader = new ClassPathTemplateLoader((templatesDirPath));
FileTemplateLoader fileTemplateLoader = new FileTemplateLoader(templatesDirPath);
cpTemplateLoader.setSuffix(GeneratorConstants.TEMPLATES_SUFFIX);
fileTemplateLoader.setSuffix(GeneratorConstants.TEMPLATES_SUFFIX);
Handlebars handlebars = new Handlebars().with(cpTemplateLoader, fileTemplateLoader);
handlebars.registerHelpers(StringHelpers.class);
handlebars.registerHelper("equals", (object, options) -> {
CharSequence result;
Object param0 = options.param(0);
if (param0 == null) {
throw new IllegalArgumentException("found 'null', expected 'string'");
}
if (object != null && object.toString().equals(param0.toString())) {
result = options.fn(options.context);
} else {
result = null;
}
return result;
});
try {
return handlebars.compile(templateName);
} catch (IOException e) {
throw new CodeGeneratorException("Error while compiling template", e);
}
}
use of com.github.jknack.handlebars.Handlebars in project ballerina by ballerina-lang.
the class BalGenerationUtils method compileTemplate.
private static Template compileTemplate(String defaultTemplateDir, String templateName) throws IOException {
String templatesDirPath = System.getProperty(TEMPLATES_DIR_PATH_KEY, defaultTemplateDir);
ClassPathTemplateLoader cpTemplateLoader = new ClassPathTemplateLoader((templatesDirPath));
FileTemplateLoader fileTemplateLoader = new FileTemplateLoader(templatesDirPath);
cpTemplateLoader.setSuffix(TEMPLATES_SUFFIX);
fileTemplateLoader.setSuffix(TEMPLATES_SUFFIX);
Handlebars handlebars = new Handlebars().with(cpTemplateLoader, fileTemplateLoader);
handlebars.registerHelpers(StringHelpers.class);
handlebars.registerHelper("equals", (object, options) -> {
CharSequence result;
Object param0 = options.param(0);
if (param0 == null) {
throw new IllegalArgumentException("found n'null', expected 'string'");
}
if (object != null && object.toString().equals(param0.toString())) {
result = options.fn(options.context);
} else {
result = null;
}
return result;
});
return handlebars.compile(templateName);
}
use of com.github.jknack.handlebars.Handlebars in project ddf by codice.
the class KmlEndpoint method createRootNetworkLink.
private Kml createRootNetworkLink(UriInfo uriInfo) throws UnknownHostException {
Kml kml = KmlFactory.createKml();
NetworkLink rootNetworkLink = kml.createAndSetNetworkLink();
rootNetworkLink.setName(this.productName);
rootNetworkLink.setSnippet(KmlFactory.createSnippet().withMaxLines(0));
UriBuilder baseUrlBuidler = UriBuilder.fromUri(uriInfo.getBaseUri());
baseUrlBuidler.replacePath("");
this.baseUrl = baseUrlBuidler.build().toString();
String descriptionHtml = description;
Handlebars handlebars = new Handlebars(templateLoader);
try {
Template template = handlebars.compile("description");
descriptionHtml = template.apply(this);
LOGGER.debug(descriptionHtml);
} catch (IOException e) {
LOGGER.debug("Failed to apply description Template", e);
}
rootNetworkLink.setDescription(descriptionHtml);
rootNetworkLink.setOpen(true);
rootNetworkLink.setVisibility(false);
Link link = rootNetworkLink.createAndSetLink();
UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri());
builder = generateEndpointUrl(SystemBaseUrl.EXTERNAL.constructUrl(FORWARD_SLASH + CATALOG_URL_PATH + FORWARD_SLASH + KML_TRANSFORM_PARAM + FORWARD_SLASH + "sources", true), builder);
link.setHref(builder.build().toString());
link.setViewRefreshMode(ViewRefreshMode.NEVER);
link.setRefreshMode(RefreshMode.ON_INTERVAL);
link.setRefreshInterval(REFRESH_INTERVAL);
return kml;
}
Aggregations