Package com.vina.web.thymeleaf

Source Code of com.vina.web.thymeleaf.TemplateEngineUtil

package com.vina.web.thymeleaf;


import javax.servlet.http.HttpServletRequest;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;

public class TemplateEngineUtil {
 
//  private static String resolverEncoding;
  private static TemplateEngine templateEngine;
  private static TemplateEngineUtil instance;
 
  public static TemplateEngineUtil getInstance(){
    if(instance==null){
      instance = new TemplateEngineUtil();
    }
    initializeTemplateEngine();
    return instance;
  }
 
  private static void initializeTemplateEngine(){
    ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
    templateResolver.setTemplateMode("XHTML");
    templateResolver.setPrefix("/WEB-INF/templates/");
        templateResolver.setSuffix(".html");
        templateResolver.setCharacterEncoding("utf-8");
        templateResolver.setCacheTTLMs(Long.valueOf(3600000L));
       
//        resolverEncoding = templateResolver.getCharacterEncoding();
        templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(templateResolver);
  }
 
//  public String getEncoding(){
//    return resolverEncoding;
//  }
  public TemplateEngine getEngine(){
    return templateEngine;
  }
  public String getTemplateName(HttpServletRequest request) {
        String requestPath = request.getRequestURI();
        String contextPath = request.getContextPath();
        if (contextPath == null) {
            contextPath = "";
        }

        return requestPath.substring(contextPath.length());
    }
}
TOP

Related Classes of com.vina.web.thymeleaf.TemplateEngineUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.