org.zodiac.autoconfigure.template.velocity.view.VelocityTemplateViewWebAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.template.velocity.view;
import java.io.IOException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain;
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.template.velocity.condition.ConditionalOnVelocityTemplateEnabled;
@SpringBootConfiguration
@ConditionalOnVelocityTemplateEnabled
@ConditionalOnClass(value = {org.apache.velocity.app.VelocityEngine.class, org.zodiac.template.velocity.spring.ui.VelocityEngineFactory.class})
@ConditionalOnProperty(name = org.zodiac.template.velocity.constants.VelocityTemplateSystemPropertiesConstants.SPRING_TEMPLATE_VELOCITY_VIEW_ENABLED, havingValue = "true")
public class VelocityTemplateViewWebAutoConfiguration {
public VelocityTemplateViewWebAutoConfiguration() {}
@SpringBootConfiguration
@ConditionalOnNotWebApplication
@ConditionalOnVelocityTemplateEnabled
@ConditionalOnProperty(name = org.zodiac.template.velocity.constants.VelocityTemplateSystemPropertiesConstants.SPRING_TEMPLATE_VELOCITY_VIEW_ENABLED, havingValue = "true")
protected static class VelocityNonWebConfiguration extends AbstractVelocityViewConfiguration {
public VelocityNonWebConfiguration() {
}
@Bean
@ConditionalOnMissingBean
protected org.zodiac.template.velocity.spring.ui.VelocityEngineFactoryBean velocityConfiguration(VelocityTemplateViewProperties properties) {
org.zodiac.template.velocity.spring.ui.VelocityEngineFactoryBean velocityEngineFactoryBean =
new org.zodiac.template.velocity.spring.ui.VelocityEngineFactoryBean();
applyProperties(velocityEngineFactoryBean, properties);
return velocityEngineFactoryBean;
}
}
@SpringBootConfiguration
@ConditionalOnVelocityTemplateEnabled
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnClass(value = {javax.servlet.Servlet.class})
@AutoConfigureAfter(value = {WebMvcAutoConfiguration.class})
@ConditionalOnProperty(name = org.zodiac.template.velocity.constants.VelocityTemplateSystemPropertiesConstants.SPRING_TEMPLATE_VELOCITY_VIEW_ENABLED, havingValue = "true")
protected static class VelocityWebServletConfiguration extends AbstractVelocityViewConfiguration {
public VelocityWebServletConfiguration() {
}
@Bean
@ConditionalOnMissingBean(org.zodiac.template.velocity.spring.view.VelocityConfig.class)
protected org.zodiac.template.velocity.spring.view.VelocityConfigurer velocityConfigurer(VelocityTemplateViewProperties properties,
ObjectProvider velocityTemplateEngineProvider) {
org.zodiac.template.velocity.VelocityTemplateEngine velocityTemplateEngine = velocityTemplateEngineProvider.getIfAvailable();
org.zodiac.template.velocity.spring.view.VelocityConfigurer configurer =
new org.zodiac.template.velocity.spring.view.VelocityConfigurer();
configurer.setVelocityEngine(velocityTemplateEngine.getVelocityEngine());
applyProperties(configurer, properties);
return configurer;
}
@Bean
@ConditionalOnMissingBean
protected org.apache.velocity.app.VelocityEngine
velocityEngine(org.zodiac.template.velocity.spring.view.VelocityConfigurer configurer)
throws org.apache.velocity.exception.VelocityException, IOException {
return configurer.getVelocityEngine();
}
@Bean
@ConditionalOnMissingBean(name = org.zodiac.template.velocity.constants.VelocityTemplateConstants.VELOCITY_VIEW_RESOLVER_BEAN_NAME)
//@ConditionalOnProperty(name = org.zodiac.template.velocity.constants.TemplateVelocitySystemPropertiesConstants.SPRING_TEMPLATE_VELOCITY_VIEW_ENABLED, havingValue = "true")
protected org.zodiac.template.velocity.spring.view.servlet.ServletVelocityViewResolver velocityViewResolver(VelocityTemplateViewProperties properties) {
org.zodiac.template.velocity.spring.view.servlet.ServletVelocityViewResolver resolver =
new org.zodiac.template.velocity.spring.view.servlet.ServletVelocityViewResolver();
properties.applyToViewResolver(resolver);
return resolver;
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledResourceChain
protected org.springframework.web.servlet.resource.ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
return new org.springframework.web.servlet.resource.ResourceUrlEncodingFilter();
}
}
@SpringBootConfiguration
@ConditionalOnVelocityTemplateEnabled
@ConditionalOnWebApplication(type = Type.REACTIVE)
@AutoConfigureAfter(value = {WebFluxAutoConfiguration.class})
@ConditionalOnClass(value = {org.springframework.web.reactive.DispatcherHandler.class})
@ConditionalOnProperty(name = org.zodiac.template.velocity.constants.VelocityTemplateSystemPropertiesConstants.SPRING_TEMPLATE_VELOCITY_VIEW_ENABLED, havingValue = "true")
protected class ReactiveVelocityViewConfiguration extends AbstractVelocityViewConfiguration {
public ReactiveVelocityViewConfiguration() {
}
@Bean
@ConditionalOnMissingBean(org.zodiac.template.velocity.spring.view.VelocityConfig.class)
protected org.zodiac.template.velocity.spring.view.VelocityConfigurer velocityConfigurer(VelocityTemplateViewProperties properties,
ObjectProvider velocityTemplateEngineProvider) {
org.zodiac.template.velocity.VelocityTemplateEngine velocityTemplateEngine = velocityTemplateEngineProvider.getIfAvailable();
org.zodiac.template.velocity.spring.view.VelocityConfigurer configurer =
new org.zodiac.template.velocity.spring.view.reactive.ReactiveVelocityConfigurer();
configurer.setVelocityEngine(velocityTemplateEngine.getVelocityEngine());
applyProperties(configurer, properties);
return configurer;
}
@Bean
@ConditionalOnMissingBean
protected org.apache.velocity.app.VelocityEngine
velocityEngine(org.zodiac.template.velocity.spring.view.VelocityConfigurer configurer)
throws org.apache.velocity.exception.VelocityException, IOException {
return configurer.getVelocityEngine();
}
@Bean
@ConditionalOnMissingBean(name = org.zodiac.template.velocity.constants.VelocityTemplateConstants.VELOCITY_VIEW_RESOLVER_BEAN_NAME)
//@ConditionalOnProperty(name = org.zodiac.template.velocity.constants.TemplateVelocitySystemPropertiesConstants.SPRING_TEMPLATE_VELOCITY_VIEW_ENABLED, havingValue = "true")
protected org.zodiac.template.velocity.spring.view.reactive.ReactiveVelocityViewResolver velocityViewResolver(VelocityTemplateViewProperties properties) {
org.zodiac.template.velocity.spring.view.reactive.ReactiveVelocityViewResolver resolver =
new org.zodiac.template.velocity.spring.view.reactive.ReactiveVelocityViewResolver();
properties.applyToViewResolver(resolver);
return resolver;
}
}
}