Search in sources :

Example 6 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class SessionCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConditionMessage.Builder message = ConditionMessage.forCondition("Session Condition");
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), "spring.session.");
    StoreType sessionStoreType = SessionStoreMappings.getType(((AnnotationMetadata) metadata).getClassName());
    if (!resolver.containsProperty("store-type")) {
        return ConditionOutcome.noMatch(message.didNotFind("spring.session.store-type property").atAll());
    }
    String value = resolver.getProperty("store-type").replace('-', '_').toUpperCase();
    if (value.equals(sessionStoreType.name())) {
        return ConditionOutcome.match(message.found("spring.session.store-type property").items(sessionStoreType));
    }
    return ConditionOutcome.noMatch(message.found("spring.session.store-type property").items(value));
}
Also used : ConditionMessage(org.springframework.boot.autoconfigure.condition.ConditionMessage) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver)

Example 7 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class TemplateAvailabilityProviders method getProvider.

/**
	 * Get the provider that can be used to render the given view.
	 * @param view the view to render
	 * @param environment the environment
	 * @param classLoader the class loader
	 * @param resourceLoader the resource loader
	 * @return a {@link TemplateAvailabilityProvider} or null
	 */
public TemplateAvailabilityProvider getProvider(String view, Environment environment, ClassLoader classLoader, ResourceLoader resourceLoader) {
    Assert.notNull(view, "View must not be null");
    Assert.notNull(environment, "Environment must not be null");
    Assert.notNull(classLoader, "ClassLoader must not be null");
    Assert.notNull(resourceLoader, "ResourceLoader must not be null");
    RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment, "spring.template.provider.");
    if (!propertyResolver.getProperty("cache", Boolean.class, true)) {
        return findProvider(view, environment, classLoader, resourceLoader);
    }
    TemplateAvailabilityProvider provider = this.resolved.get(view);
    if (provider == null) {
        synchronized (this.cache) {
            provider = findProvider(view, environment, classLoader, resourceLoader);
            provider = (provider == null ? NONE : provider);
            this.resolved.put(view, provider);
            this.cache.put(view, provider);
        }
    }
    return (provider == NONE ? null : provider);
}
Also used : RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver)

Example 8 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class ThymeleafTemplateAvailabilityProvider method isTemplateAvailable.

@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader, ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("org.thymeleaf.spring5.SpringTemplateEngine", classLoader)) {
        PropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.thymeleaf.");
        String prefix = resolver.getProperty("prefix", ThymeleafProperties.DEFAULT_PREFIX);
        String suffix = resolver.getProperty("suffix", ThymeleafProperties.DEFAULT_SUFFIX);
        return resourceLoader.getResource(prefix + view + suffix).exists();
    }
    return false;
}
Also used : RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) PropertyResolver(org.springframework.core.env.PropertyResolver)

Example 9 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class MustacheTemplateAvailabilityProvider method isTemplateAvailable.

@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader, ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("com.samskivert.mustache.Template", classLoader)) {
        PropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.mustache.");
        String prefix = resolver.getProperty("prefix", MustacheProperties.DEFAULT_PREFIX);
        String suffix = resolver.getProperty("suffix", MustacheProperties.DEFAULT_SUFFIX);
        return resourceLoader.getResource(prefix + view + suffix).exists();
    }
    return false;
}
Also used : RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) PropertyResolver(org.springframework.core.env.PropertyResolver)

Example 10 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class JspTemplateAvailabilityProvider method getResourceName.

private String getResourceName(String view, Environment environment) {
    PropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.mvc.view.");
    String prefix = resolver.getProperty("prefix", WebMvcAutoConfiguration.DEFAULT_PREFIX);
    String suffix = resolver.getProperty("suffix", WebMvcAutoConfiguration.DEFAULT_SUFFIX);
    return prefix + view + suffix;
}
Also used : RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) PropertyResolver(org.springframework.core.env.PropertyResolver)

Aggregations

RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)24 ConditionMessage (org.springframework.boot.autoconfigure.condition.ConditionMessage)5 PropertyResolver (org.springframework.core.env.PropertyResolver)5 ConditionOutcome (org.springframework.boot.autoconfigure.condition.ConditionOutcome)3 Map (java.util.Map)2 MutablePropertySources (org.springframework.core.env.MutablePropertySources)2 PropertySources (org.springframework.core.env.PropertySources)2 PropertySourcesPropertyResolver (org.springframework.core.env.PropertySourcesPropertyResolver)2 AbstractCacheBuilder (com.alicp.jetcache.AbstractCacheBuilder)1 CacheBuilder (com.alicp.jetcache.CacheBuilder)1 ConfigProvider (com.alicp.jetcache.anno.support.ConfigProvider)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 PostConstruct (javax.annotation.PostConstruct)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 BeansException (org.springframework.beans.BeansException)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1