|
|
@ -34,12 +34,15 @@ import com.samskivert.mustache.Template;
|
|
|
|
* Spring MVC {@link ViewResolver} for Mustache.
|
|
|
|
* Spring MVC {@link ViewResolver} for Mustache.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Dave Syer
|
|
|
|
* @author Dave Syer
|
|
|
|
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @since 1.2.2
|
|
|
|
* @since 1.2.2
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class MustacheViewResolver extends UrlBasedViewResolver {
|
|
|
|
public class MustacheViewResolver extends UrlBasedViewResolver {
|
|
|
|
|
|
|
|
|
|
|
|
private Compiler compiler = Mustache.compiler();
|
|
|
|
private Compiler compiler = Mustache.compiler();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String charset;
|
|
|
|
|
|
|
|
|
|
|
|
public MustacheViewResolver() {
|
|
|
|
public MustacheViewResolver() {
|
|
|
|
setViewClass(MustacheView.class);
|
|
|
|
setViewClass(MustacheView.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -51,6 +54,13 @@ public class MustacheViewResolver extends UrlBasedViewResolver {
|
|
|
|
this.compiler = compiler;
|
|
|
|
this.compiler = compiler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param charset the charset to set
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void setCharset(String charset) {
|
|
|
|
|
|
|
|
this.charset = charset;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected View loadView(String viewName, Locale locale) throws Exception {
|
|
|
|
protected View loadView(String viewName, Locale locale) throws Exception {
|
|
|
|
Resource resource = resolveResource(viewName, locale);
|
|
|
|
Resource resource = resolveResource(viewName, locale);
|
|
|
@ -64,7 +74,9 @@ public class MustacheViewResolver extends UrlBasedViewResolver {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Template createTemplate(Resource resource) throws IOException {
|
|
|
|
private Template createTemplate(Resource resource) throws IOException {
|
|
|
|
return this.compiler.compile(new InputStreamReader(resource.getInputStream()));
|
|
|
|
return this.charset == null ? this.compiler.compile(new InputStreamReader(
|
|
|
|
|
|
|
|
resource.getInputStream())) : this.compiler
|
|
|
|
|
|
|
|
.compile(new InputStreamReader(resource.getInputStream(), this.charset));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Resource resolveResource(String viewName, Locale locale) {
|
|
|
|
private Resource resolveResource(String viewName, Locale locale) {
|
|
|
|