Polish templates code

This commit is contained in:
Phillip Webb
2014-04-30 21:17:58 +01:00
parent 1d5cddc1e9
commit decee8d871
11 changed files with 43 additions and 33 deletions

View File

@@ -44,8 +44,9 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
/**
* {@link EnableAutoConfiguration Auto-configuration} for FreeMarker.
*
*
* @author Andy Wilkinson
* @since 1.1.0
*/
@Configuration
@ConditionalOnClass(freemarker.template.Configuration.class)

View File

@@ -22,11 +22,11 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;
/**
* {@link TemplateAvailabilityProvider} that provides availability information
* for FreeMarker view templates
*
* {@link TemplateAvailabilityProvider} that provides availability information for
* FreeMarker view templates
*
* @author Andy Wilkinson
*
* @since 1.1.0
*/
public class FreeMarkerTemplateAvailabilityProvider implements
TemplateAvailabilityProvider {
@@ -34,15 +34,16 @@ public class FreeMarkerTemplateAvailabilityProvider implements
@Override
public boolean isTemplateAvailable(String view, Environment environment,
ClassLoader classLoader, ResourceLoader resourceLoader) {
if (ClassUtils.isPresent("freemarker.template.Configuration",
classLoader)) {
String loaderPath = environment.getProperty("spring.freemarker.templateLoaderPath",
if (ClassUtils.isPresent("freemarker.template.Configuration", classLoader)) {
String loaderPath = environment.getProperty(
"spring.freemarker.templateLoaderPath",
FreeMarkerAutoConfiguration.DEFAULT_TEMPLATE_LOADER_PATH);
String prefix = environment.getProperty("spring.freemarker.prefix",
FreeMarkerAutoConfiguration.DEFAULT_PREFIX);
String suffix = environment.getProperty("spring.freemarker.suffix",
FreeMarkerAutoConfiguration.DEFAULT_SUFFIX);
return resourceLoader.getResource(loaderPath + prefix + view + suffix).exists();
return resourceLoader.getResource(loaderPath + prefix + view + suffix)
.exists();
}
return false;
}

View File

@@ -24,9 +24,9 @@ import org.springframework.util.ClassUtils;
/**
* {@link TemplateAvailabilityProvider} that provides availability information for
* Thymeleaf view templates
*
*
* @author Andy Wilkinson
*
* @since 1.1.0
*/
public class ThymeleafTemplateAvailabilityProvider implements
TemplateAvailabilityProvider {

View File

@@ -58,7 +58,7 @@ import org.springframework.web.servlet.view.BeanNameViewResolver;
/**
* {@link EnableAutoConfiguration Auto-configuration} to render errors via a MVC error
* controller.
*
*
* @author Dave Syer
* @author Andy Wilkinson
*/

View File

@@ -21,6 +21,13 @@ import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;
/**
* {@link TemplateAvailabilityProvider} that provides availability information for JSP
* view templates
*
* @author Andy Wilkinson
* @since 1.1.0
*/
public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProvider {
@Override

View File

@@ -41,7 +41,7 @@ import static org.junit.Assert.assertTrue;
/**
* Tests for {@link FreeMarkerAutoConfiguration}.
*
*
* @author Andy Wilkinson
*/
public class FreeMarkerAutoConfigurationTests {
@@ -85,8 +85,8 @@ public class FreeMarkerAutoConfigurationTests {
new File("target/test-classes/templates/empty-directory").mkdir();
EnvironmentTestUtils
.addEnvironment(this.context,
"spring.freemarker.templateLoaderPath:classpath:/templates/empty-directory/");
.addEnvironment(this.context,
"spring.freemarker.templateLoaderPath:classpath:/templates/empty-directory/");
this.context.register(FreeMarkerAutoConfiguration.class);
this.context.refresh();

View File

@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
/**
* Tests for {@link FreeMarkerTemplateAvailabilityProvider}.
*
*
* @author Andy Wilkinson
*/
public class FreeMarkerTemplateAvailabilityProviderTests {

View File

@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
/**
* Tests for {@link ThymeleafTemplateAvailabilityProvider}.
*
*
* @author Andy Wilkinson
*/
public class ThymeleafTemplateAvailabilityProviderTests {