Merge branch '1.2.x'

pull/2657/merge
Andy Wilkinson 10 years ago
commit d7818b441e

@ -108,6 +108,7 @@ public class MustacheAutoConfiguration {
resolver.setCache(this.mustache.isCache()); resolver.setCache(this.mustache.isCache());
resolver.setViewNames(this.mustache.getViewNames()); resolver.setViewNames(this.mustache.getViewNames());
resolver.setContentType(this.mustache.getContentType()); resolver.setContentType(this.mustache.getContentType());
resolver.setCharset(this.mustache.getCharset());
resolver.setCompiler(mustacheCompiler); resolver.setCompiler(mustacheCompiler);
resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10); resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
return resolver; return resolver;

@ -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) {

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.autoconfigure.mustache; package org.springframework.boot.autoconfigure.mustache.web;
import java.util.Locale; import java.util.Locale;

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.autoconfigure.mustache; package org.springframework.boot.autoconfigure.mustache.web;
import java.util.Collections; import java.util.Collections;

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.autoconfigure.mustache; package org.springframework.boot.autoconfigure.mustache.web;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
@ -31,9 +31,11 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.mustache.MustacheWebIntegrationTests.Application; import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration;
import org.springframework.boot.autoconfigure.mustache.MustacheResourceTemplateLoader;
import org.springframework.boot.autoconfigure.mustache.web.MustacheView; import org.springframework.boot.autoconfigure.mustache.web.MustacheView;
import org.springframework.boot.autoconfigure.mustache.web.MustacheViewResolver; import org.springframework.boot.autoconfigure.mustache.web.MustacheViewResolver;
import org.springframework.boot.autoconfigure.mustache.web.MustacheWebIntegrationTests.Application;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
Loading…
Cancel
Save