Created
September 5, 2014 05:48
-
-
Save A-pZ/205eb0eb55fac1b440a2 to your computer and use it in GitHub Desktop.
Thymeleafプラグインのテンプレートエンジンプロバイダ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.codework.struts.plugins.thymeleaf.spi; | |
import org.codework.struts.plugins.thymeleaf.StrutsMessageResolver; | |
import org.thymeleaf.TemplateEngine; | |
import org.thymeleaf.templateresolver.ServletContextTemplateResolver; | |
import com.opensymphony.xwork2.inject.Inject; | |
/** | |
* A default implementation of {@link TemplateEngineProvider}. | |
* | |
* @author Steven Benitez / Updated A-pZ(Koji.Azuma) | |
* @since 2.3.15 | |
* @version 2.3.16.3 | |
*/ | |
public class DefaultTemplateEngineProvider implements TemplateEngineProvider { | |
private TemplateEngine templateEngine; | |
public DefaultTemplateEngineProvider() { | |
} | |
/** | |
* Setting struts.properties. | |
*/ | |
public void configure() { | |
ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); | |
// HTML5 is the future! | |
templateResolver.setTemplateMode("HTML5"); | |
// This will convert "home" to "/WEB-INF/templates/home.html" | |
// templateResolver.setPrefix("/WEB-INF/templates/"); | |
// templateResolver.setSuffix(".html"); | |
templateResolver.setPrefix(prefix); | |
templateResolver.setSuffix(suffix); | |
templateResolver.setCacheable(cacheable); | |
// Set template cache TTL to 1 hour. If not set, entries would live in | |
// cache | |
// until expelled by LRU | |
templateResolver.setCacheTTLMs(cacheTTLMs); | |
templateEngine = new TemplateEngine(); | |
templateEngine.setTemplateResolver(templateResolver); | |
templateEngine.setMessageResolver(new StrutsMessageResolver()); | |
} | |
@Inject(value = "struts.thymeleaf.prefix", required = false) | |
public void setPrefix(String prefix) { | |
this.prefix = prefix; | |
} | |
@Inject(value = "struts.thymeleaf.suffix", required = false) | |
public void setSuffix(String suffix) { | |
this.suffix = suffix; | |
} | |
@Inject(value = "struts.thymeleaf.cacheable", required = false) | |
public void setCacheable(String cacheable) { | |
this.cacheable = Boolean.parseBoolean(cacheable); | |
} | |
@Inject(value = "struts.thymeleaf.cacheTTLMs", required = false) | |
public void setCacheTTLMs(String cacheTTLMs) { | |
this.cacheTTLMs = Long.parseLong(cacheTTLMs); | |
} | |
@Override | |
public TemplateEngine get() { | |
if ( templateEngine == null ) { | |
configure(); | |
} | |
return templateEngine; | |
} | |
/** | |
* Template HTML file directory. | |
*/ | |
private String prefix = "/WEB-INF/template/"; | |
/** | |
* Template HTML filename extension. | |
*/ | |
private String suffix = ".html"; | |
/** | |
* Template cache enable. | |
*/ | |
private boolean cacheable = false; | |
/** | |
* Template cache life cycle.(msec) | |
*/ | |
private Long cacheTTLMs = 3600000L; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment