Search in sources :

Example 6 with Template

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;
}
Also used : Template(com.github.jknack.handlebars.Template)

Example 7 with Template

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;
}
Also used : Locale(java.util.Locale) Context(com.github.jknack.handlebars.Context) Handlebars(com.github.jknack.handlebars.Handlebars) FileTemplateLoader(com.github.jknack.handlebars.io.FileTemplateLoader) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Date(java.util.Date) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FessSystemException(org.codelibs.fess.exception.FessSystemException) ClientAbortException(org.apache.catalina.connector.ClientAbortException) IOException(java.io.IOException) Template(com.github.jknack.handlebars.Template)

Aggregations

Template (com.github.jknack.handlebars.Template)7 Handlebars (com.github.jknack.handlebars.Handlebars)4 IOException (java.io.IOException)4 Context (com.github.jknack.handlebars.Context)2 Date (java.util.Date)2 ClassPathTemplateLoader (com.github.jknack.handlebars.io.ClassPathTemplateLoader)1 FileTemplateLoader (com.github.jknack.handlebars.io.FileTemplateLoader)1 TemplateLoader (com.github.jknack.handlebars.io.TemplateLoader)1 SimpleDateFormat (com.ibm.icu.text.SimpleDateFormat)1 LineString (com.vividsolutions.jts.geom.LineString)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)1 Link (de.micromata.opengis.kml.v_2_2_0.Link)1 NetworkLink (de.micromata.opengis.kml.v_2_2_0.NetworkLink)1 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)1 TimeSpan (de.micromata.opengis.kml.v_2_2_0.TimeSpan)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1