Example usage for org.springframework.core.env PropertyResolver getProperty

List of usage examples for org.springframework.core.env PropertyResolver getProperty

Introduction

In this page you can find the example usage for org.springframework.core.env PropertyResolver getProperty.

Prototype

@Nullable
<T> T getProperty(String key, Class<T> targetType);

Source Link

Document

Return the property value associated with the given key, or null if the key cannot be resolved.

Usage

From source file:jp.gr.java_conf.bufferings.thymeleaf.spring.boot.Thymeleaf3TemplateAvailabilityProvider.java

@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader,
        ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("org.thymeleaf.spring4.SpringTemplateEngine", classLoader)
            && ClassUtils.isPresent("org.thymeleaf.Thymeleaf", classLoader)) {
        PropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.thymeleaf3.");
        String prefix = resolver.getProperty("prefix", Thymeleaf3Properties.DEFAULT_PREFIX);
        String suffix = resolver.getProperty("suffix", Thymeleaf3Properties.DEFAULT_SUFFIX);
        return resourceLoader.getResource(prefix + view + suffix).exists();
    }//w  w w  .j  a va  2 s.c o m
    return false;
}

From source file:net.alpha.velocity.configuration.VelocityTemplateAvailabilityProvider.java

@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader,
        ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("org.apache.velocity.app.VelocityEngine", classLoader)) {
        PropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.velocity.");
        String loaderPath = resolver.getProperty("resource-loader-path",
                VelocityProperties.DEFAULT_RESOURCE_LOADER_PATH);
        String prefix = resolver.getProperty("prefix", VelocityProperties.DEFAULT_PREFIX);
        String suffix = resolver.getProperty("suffix", VelocityProperties.DEFAULT_SUFFIX);
        return resourceLoader.getResource(loaderPath + prefix + view + suffix).exists();
    }/*  w ww .  j  a v  a2s  .co m*/
    return false;
}

From source file:com.indeed.imhotep.iql.cache.S3QueryCache.java

public S3QueryCache(PropertyResolver props) {
    String awsRegion;// ww  w . j a v a 2s  .  co m
    String awsKey;
    String awsSecret;

    enabled = true;
    try {
        bucket = props.getProperty("query.cache.s3.bucket", String.class);
        awsKey = props.getProperty("query.cache.s3.s3key", String.class);
        awsSecret = props.getProperty("query.cache.s3.s3secret", String.class);
        if (awsKey == null || awsSecret == null) {
            log.warn("No AWS key or Secret found.  Using Anonymous access.");
            client = new AmazonS3Client();
        } else {
            client = new AmazonS3Client(new BasicAWSCredentials(awsKey, awsSecret));
        }

        boolean exists = client.doesBucketExist(bucket);
        if (!exists) {
            awsRegion = props.getProperty("aws.s3.region", String.class, Region.US_Standard.toString());
            client.createBucket(bucket, awsRegion);
        }
    } catch (Exception e) {
        log.info("Failed to initialize the S3 client. Caching disabled.", e);
        enabled = false;
    }
}