Search in sources :

Example 16 with SimpleDateFormat

use of com.ibm.icu.text.SimpleDateFormat 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", 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 = ComponentUtil.getPathMappingHelper().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) ServletContext(javax.servlet.ServletContext) 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) ExecutionException(java.util.concurrent.ExecutionException) Template(com.github.jknack.handlebars.Template)

Aggregations

SimpleDateFormat (com.ibm.icu.text.SimpleDateFormat)16 Date (java.util.Date)8 DateFormat (com.ibm.icu.text.DateFormat)4 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)4 Test (org.junit.Test)4 Calendar (java.util.Calendar)3 ULocale (com.ibm.icu.util.ULocale)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 Locale (java.util.Locale)2 SequenceFile (org.apache.hadoop.io.SequenceFile)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 Skeleton (com.github.anba.es6draft.runtime.objects.intl.DateFieldSymbolTable.Skeleton)1 Context (com.github.jknack.handlebars.Context)1 Handlebars (com.github.jknack.handlebars.Handlebars)1 Template (com.github.jknack.handlebars.Template)1 FileTemplateLoader (com.github.jknack.handlebars.io.FileTemplateLoader)1