Search in sources :

Example 1 with JMustacheTemplateFactory

use of org.springframework.web.servlet.view.mustache.jmustache.JMustacheTemplateFactory in project alf.io by alfio-event.

the class MvcConfiguration method getTemplateFactory.

@Bean
public JMustacheTemplateFactory getTemplateFactory() throws Exception {
    final JMustacheTemplateFactory templateFactory = new JMustacheTemplateFactory();
    templateFactory.setPrefix("/WEB-INF/templates");
    templateFactory.setSuffix(".ms");
    templateFactory.setTemplateLoader(templateLoader);
    templateFactory.setCompiler(Mustache.compiler().escapeHTML(true).standardsMode(false).defaultValue("").nullValue("").withFormatter((o) -> {
        if (o instanceof ZonedDateTime) {
            return DateTimeFormatter.ISO_ZONED_DATE_TIME.format((ZonedDateTime) o);
        } else if (o instanceof DefaultMessageSourceResolvable) {
            DefaultMessageSourceResolvable m = ((DefaultMessageSourceResolvable) o);
            return m.getCode() + " " + Arrays.stream(Optional.ofNullable(m.getArguments()).orElse(new Object[] {})).map(x -> "[" + x.toString() + "]").collect(Collectors.joining(" "));
        } else {
            return String.valueOf(o);
        }
    }).withLoader(templateLoader));
    templateFactory.afterPropertiesSet();
    return templateFactory;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) org.springframework.web.servlet.config.annotation(org.springframework.web.servlet.config.annotation) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ModelMap(org.springframework.ui.ModelMap) HandlerInterceptorAdapter(org.springframework.web.servlet.handler.HandlerInterceptorAdapter) RequestContextUtils(org.springframework.web.servlet.support.RequestContextUtils) LocalizationMessageInterceptor(org.springframework.web.servlet.view.mustache.jmustache.LocalizationMessageInterceptor) HandlerMethod(org.springframework.web.method.HandlerMethod) Matcher(java.util.regex.Matcher) DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) EventDescriptor(alfio.controller.decorator.EventDescriptor) JMustacheTemplateFactory(org.springframework.web.servlet.view.mustache.jmustache.JMustacheTemplateFactory) ConfigurationPathKey(alfio.model.system.Configuration.ConfigurationPathKey) MediaType(org.springframework.http.MediaType) ContentLanguage(alfio.model.ContentLanguage) Collectors(java.util.stream.Collectors) JMustacheTemplateLoader(org.springframework.web.servlet.view.mustache.jmustache.JMustacheTemplateLoader) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Configuration(org.springframework.context.annotation.Configuration) LocaleChangeInterceptor(org.springframework.web.servlet.i18n.LocaleChangeInterceptor) Environment(org.springframework.core.env.Environment) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Pattern(java.util.regex.Pattern) java.util(java.util) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ConfigurationManager(alfio.manager.system.ConfigurationManager) CommonsMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver) MustacheViewResolver(org.springframework.web.servlet.view.mustache.MustacheViewResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) org.springframework.web.servlet(org.springframework.web.servlet) MessageSource(org.springframework.context.MessageSource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) SessionLocaleResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) Mustache(com.samskivert.mustache.Mustache) ComponentScan(org.springframework.context.annotation.ComponentScan) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) DateTimeFormatter(java.time.format.DateTimeFormatter) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) I18nManager(alfio.manager.i18n.I18nManager) Event(alfio.model.Event) Bean(org.springframework.context.annotation.Bean) CsrfToken(org.springframework.security.web.csrf.CsrfToken) ConfigurationKeys(alfio.model.system.ConfigurationKeys) MustacheCustomTagInterceptor(alfio.util.MustacheCustomTagInterceptor) JMustacheTemplateFactory(org.springframework.web.servlet.view.mustache.jmustache.JMustacheTemplateFactory) ZonedDateTime(java.time.ZonedDateTime) DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) Bean(org.springframework.context.annotation.Bean)

Aggregations

EventDescriptor (alfio.controller.decorator.EventDescriptor)1 I18nManager (alfio.manager.i18n.I18nManager)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1 ContentLanguage (alfio.model.ContentLanguage)1 Event (alfio.model.Event)1 ConfigurationPathKey (alfio.model.system.Configuration.ConfigurationPathKey)1 ConfigurationKeys (alfio.model.system.ConfigurationKeys)1 MustacheCustomTagInterceptor (alfio.util.MustacheCustomTagInterceptor)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 Mustache (com.samskivert.mustache.Mustache)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1