diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java index 8e62efa04c3..819d957b615 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.mustache; import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; @@ -38,9 +39,10 @@ import com.samskivert.mustache.Mustache.Compiler; import com.samskivert.mustache.Mustache.TemplateLoader; /** + * {@link EnableAutoConfiguration Auto-configuration} for Mustache. + * * @author Dave Syer * @since 1.2.2 - * */ @Configuration @ConditionalOnClass(Mustache.class) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheCompilerFactoryBean.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheCompilerFactoryBean.java index 6433e6bd8e1..63a81f60c62 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheCompilerFactoryBean.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheCompilerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,23 +26,26 @@ import com.samskivert.mustache.Mustache.Formatter; import com.samskivert.mustache.Mustache.TemplateLoader; /** - * Factory for a Mustache compiler with custom strategies. For building a - * @Bean definition in Java it probably doesn't help to use this factory - * since the underlying fluent API is actually richer. - * - * @see MustacheResourceTemplateLoader + * Factory for a Mustache compiler with custom strategies. For building a {@code @Bean} + * definition in Java it probably doesn't help to use this factory since the underlying + * fluent API is actually richer. * * @author Dave Syer * @since 1.2.2 - * + * @see MustacheResourceTemplateLoader */ public class MustacheCompilerFactoryBean implements FactoryBean { private String delims; + private TemplateLoader templateLoader; + private Formatter formatter; + private Escaper escaper; + private Collector collector; + private Compiler compiler; public void setDelims(String delims) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java index 1447ee1d867..62be1e0b509 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.boot.autoconfigure.mustache; import java.util.HashMap; @@ -11,9 +27,12 @@ import org.springframework.core.env.Environment; import com.samskivert.mustache.DefaultCollector; import com.samskivert.mustache.Mustache; +import com.samskivert.mustache.Mustache.Collector; import com.samskivert.mustache.Mustache.VariableFetcher; /** + * Mustache {@link Collector} to expose properties from the Spring {@link Environment}. + * * @author Dave Syer * @since 1.2.2 */ @@ -21,6 +40,7 @@ public class MustacheEnvironmentCollector extends DefaultCollector implements EnvironmentAware { private ConfigurableEnvironment environment; + private Map target; @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheProperties.java index 78b5c534b4b..bcff487896c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,10 @@ import org.springframework.boot.autoconfigure.template.AbstractViewResolverPrope import org.springframework.boot.context.properties.ConfigurationProperties; /** + * {@link ConfigurationProperties} for Mustache. + * * @author Dave Syer * @since 1.2.2 - * */ @ConfigurationProperties(prefix = "spring.mustache") public class MustacheProperties extends AbstractViewResolverProperties { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheResourceTemplateLoader.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheResourceTemplateLoader.java index 8f1da7191c0..abab3773711 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheResourceTemplateLoader.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheResourceTemplateLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,24 +32,23 @@ import com.samskivert.mustache.Mustache.TemplateLoader; * Resource abstraction to load a template from a file, classpath, URL etc. A * TemplateLoader is needed in the Compiler when you want to render partials (i.e. * tiles-like fetaures). - * - * @see Mustache - * @see Resource - * + * * @author Dave Syer * @since 1.2.2 - * + * @see Mustache + * @see Resource */ -public class MustacheResourceTemplateLoader implements TemplateLoader, ResourceLoaderAware { +public class MustacheResourceTemplateLoader implements TemplateLoader, + ResourceLoaderAware { private String prefix = ""; private String suffix = ""; - + private String charSet = "UTF-8"; private ResourceLoader resourceLoader = new DefaultResourceLoader(); - + public MustacheResourceTemplateLoader() { } @@ -58,7 +57,7 @@ public class MustacheResourceTemplateLoader implements TemplateLoader, ResourceL this.prefix = prefix; this.suffix = suffix; } - + /** * @param charSet the charSet to set */ @@ -76,8 +75,8 @@ public class MustacheResourceTemplateLoader implements TemplateLoader, ResourceL @Override public Reader getTemplate(String name) throws Exception { - return new InputStreamReader(resourceLoader.getResource(prefix + name + suffix) - .getInputStream(), charSet); + return new InputStreamReader(this.resourceLoader.getResource( + this.prefix + name + this.suffix).getInputStream(), this.charSet); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateAvailabilityProvider.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateAvailabilityProvider.java index 0bab6ae08ab..7ca6386db09 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateAvailabilityProvider.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateAvailabilityProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheView.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheView.java index f89c192a87a..8c2d72b273c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheView.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheView.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,18 +21,21 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.AbstractTemplateView; import com.samskivert.mustache.Template; /** - * @author Dave Syer + * Spring MVC {@link View} using the Mustache template engine. * + * @author Dave Syer + * @since 1.2.2 */ public class MustacheView extends AbstractTemplateView { private final Template template; - + public MustacheView(Template template) { this.template = template; } @@ -40,7 +43,7 @@ public class MustacheView extends AbstractTemplateView { @Override protected void renderMergedTemplateModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { - template.execute(model, response.getWriter()); + this.template.execute(model, response.getWriter()); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheViewResolver.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheViewResolver.java index 995d400001d..00097dd9a38 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheViewResolver.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheViewResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import java.util.Locale; import org.springframework.beans.propertyeditors.LocaleEditor; import org.springframework.core.io.Resource; import org.springframework.web.servlet.View; +import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.view.UrlBasedViewResolver; import com.samskivert.mustache.Mustache; @@ -30,8 +31,10 @@ import com.samskivert.mustache.Mustache.Compiler; import com.samskivert.mustache.Template; /** - * @author Dave Syer + * Spring MVC {@link ViewResolver} for Mustache. * + * @author Dave Syer + * @since 1.2.2 */ public class MustacheViewResolver extends UrlBasedViewResolver { @@ -61,17 +64,20 @@ public class MustacheViewResolver extends UrlBasedViewResolver { } private Template createTemplate(Resource resource) throws IOException { - return compiler.compile(new InputStreamReader(resource.getInputStream())); + return this.compiler.compile(new InputStreamReader(resource.getInputStream())); } private Resource resolveResource(String viewName, Locale locale) { - String l10n = ""; - if (locale != null) { - LocaleEditor localeEditor = new LocaleEditor(); - localeEditor.setValue(locale); - l10n = "_" + localeEditor.getAsText(); + return resolveFromLocale(viewName, getLocale(locale)); + } + + private String getLocale(Locale locale) { + if (locale == null) { + return ""; } - return resolveFromLocale(viewName, l10n); + LocaleEditor localeEditor = new LocaleEditor(); + localeEditor.setValue(locale); + return "_" + localeEditor.getAsText(); } private Resource resolveFromLocale(String viewName, String locale) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/AutoApplicationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java similarity index 79% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/AutoApplicationTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java index 64ab771ad4a..e524960209c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/AutoApplicationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.boot.autoconfigure.mustache; import java.lang.annotation.Documented; @@ -14,7 +30,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.mustache.AutoApplicationTests.Application; +import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfigurationIntegrationTests.Application; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; @@ -31,12 +47,17 @@ import org.springframework.web.bind.annotation.RequestMapping; import static org.junit.Assert.assertTrue; +/** + * Integration tests for {@link MustacheAutoConfiguration}. + * + * @author Dave Syer + */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @IntegrationTest({ "server.port:0", "spring.mustache.prefix:classpath:/mustache-templates/" }) @WebAppConfiguration -public class AutoApplicationTests { +public class MustacheAutoConfigurationIntegrationTests { @Autowired private EmbeddedWebApplicationContext context; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateStandaloneTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java similarity index 67% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateStandaloneTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java index 5036c389562..56695874bfa 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateStandaloneTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.boot.autoconfigure.mustache; import java.util.Collections; @@ -6,7 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.mustache.MustacheTemplateStandaloneTests.Application; +import org.springframework.boot.autoconfigure.mustache.MustacheStandaloneIntegrationTests.Application; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.context.annotation.Configuration; @@ -17,10 +33,15 @@ import com.samskivert.mustache.Mustache; import static org.junit.Assert.assertEquals; +/** + * Integration Tests for {@link MustacheAutoConfiguration} outside of a web application. + * + * @author Dave Syer + */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @IntegrationTest({ "spring.main.web_environment=false", "env.foo=Heaven", "foo=World" }) -public class MustacheTemplateStandaloneTests { +public class MustacheStandaloneIntegrationTests { @Autowired private Mustache.Compiler compiler; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheViewResolverTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheViewResolverTests.java index f4167b3a9ee..987a175f776 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheViewResolverTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheViewResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; /** - * @author Dave Syer + * Tests for {@link MustacheViewResolver}. * + * @author Dave Syer */ public class MustacheViewResolverTests { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheViewTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheViewTests.java index 5675683e05d..9587ff0920d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheViewTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,9 @@ import com.samskivert.mustache.Mustache; import static org.junit.Assert.assertEquals; /** - * @author Dave Syer + * Tests for {@link MustacheView}. * + * @author Dave Syer */ public class MustacheViewTests { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/ApplicationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheWebIntegrationTests.java similarity index 81% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/ApplicationTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheWebIntegrationTests.java index a6d91b3c606..136e549084e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/ApplicationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheWebIntegrationTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.boot.autoconfigure.mustache; import java.lang.annotation.Documented; @@ -15,8 +31,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.mustache.MustacheResourceTemplateLoader; -import org.springframework.boot.autoconfigure.mustache.ApplicationTests.Application; +import org.springframework.boot.autoconfigure.mustache.MustacheWebIntegrationTests.Application; +import org.springframework.boot.autoconfigure.mustache.web.MustacheView; import org.springframework.boot.autoconfigure.mustache.web.MustacheViewResolver; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; @@ -39,11 +55,17 @@ import com.samskivert.mustache.Template; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +/** + * Integration Tests for {@link MustacheAutoConfiguration}, {@link MustacheViewResolver} + * and {@link MustacheView}. + * + * @author Dave Syer + */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @IntegrationTest("server.port:0") @WebAppConfiguration -public class ApplicationTests { +public class MustacheWebIntegrationTests { @Autowired private EmbeddedWebApplicationContext context;