use of com.github.jknack.handlebars.Template in project ddf by codice.
the class RegistryReportBuilder method getSummaryHtmlFromMetacard.
public String getSummaryHtmlFromMetacard(Metacard metacard) throws IOException {
Map<String, Object> reportMap = getSummaryMap(metacard);
Template template = handlebars.compile(SUMMARY);
String html = template.apply(reportMap);
html = html.replaceAll("\n", "");
return html;
}
use of com.github.jknack.handlebars.Template in project fess by codelibs.
the class ViewHelper method createCacheContent.
public String createCacheContent(final Map<String, Object> doc, final String[] queries) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final FileTemplateLoader loader = new FileTemplateLoader(ResourceUtil.getViewTemplatePath().toFile());
final Handlebars handlebars = new Handlebars(loader);
Locale locale = ComponentUtil.getRequestManager().getUserLocale();
if (locale == null) {
locale = Locale.ENGLISH;
}
String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
if (url == null) {
url = ComponentUtil.getMessageManager().getMessage(locale, "labels.search_unknown");
}
doc.put(fessConfig.getResponseFieldUrlLink(), getUrlLink(doc));
String createdStr;
final Date created = DocumentUtil.getValue(doc, fessConfig.getIndexFieldCreated(), Date.class);
if (created != null) {
final SimpleDateFormat sdf = new SimpleDateFormat(CoreLibConstants.DATE_FORMAT_ISO_8601_EXTEND);
createdStr = sdf.format(created);
} else {
createdStr = ComponentUtil.getMessageManager().getMessage(locale, "labels.search_unknown");
}
doc.put(CACHE_MSG, ComponentUtil.getMessageManager().getMessage(locale, "labels.search_cache_msg", new Object[] { url, createdStr }));
doc.put(QUERIES, queries);
String cache = DocumentUtil.getValue(doc, fessConfig.getIndexFieldCache(), String.class);
if (cache != null) {
final String mimetype = DocumentUtil.getValue(doc, fessConfig.getIndexFieldMimetype(), String.class);
if (!ComponentUtil.getFessConfig().isHtmlMimetypeForCache(mimetype)) {
cache = StringEscapeUtils.escapeHtml4(cache);
}
cache = pathMappingHelper.replaceUrls(cache);
if (queries != null && queries.length > 0) {
doc.put(HL_CACHE, replaceHighlightQueries(cache, queries));
} else {
doc.put(HL_CACHE, cache);
}
} else {
doc.put(fessConfig.getIndexFieldCache(), StringUtil.EMPTY);
doc.put(HL_CACHE, StringUtil.EMPTY);
}
try {
final Template template = handlebars.compile(cacheTemplateName);
final Context hbsContext = Context.newContext(doc);
return template.apply(hbsContext);
} catch (final Exception e) {
logger.warn("Failed to create a cache response.", e);
}
return null;
}
Aggregations