Example usage for org.springframework.core.io Resource exists

List of usage examples for org.springframework.core.io Resource exists

Introduction

In this page you can find the example usage for org.springframework.core.io Resource exists.

Prototype

boolean exists();

Source Link

Document

Determine whether this resource actually exists in physical form.

Usage

From source file:org.solmix.runtime.support.spring.SpringResourceResolver.java

@Override
public InputStream getAsStream(String name) {
    Resource r = context.getResource(name);
    if (r != null && r.exists()) {
        try {//from  w w  w  . j  a  va  2 s  .c  om
            return r.getInputStream();
        } catch (IOException e) {
            //ignore and return null
        }
    }
    r = context.getResource("/" + name);
    if (r != null && r.exists()) {
        try {
            return r.getInputStream();
        } catch (IOException e) {
            //ignore and return null
        }
    }
    return null;
}

From source file:com.thinkbiganalytics.scheduler.QuartzSchedulerClusterListener.java

private void validateQuartzClusterConfiguration() {
    Resource resource = new ClassPathResource("quartz.properties");
    if (resource.exists()) {
        try {//from  w  w w  .  ja v a2  s .c  o  m
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);
            Boolean isClustered = BooleanUtils
                    .toBoolean(properties.getProperty("org.quartz.jobStore.isClustered"));
            boolean isValid = isClustered;
            if (!isValid) {
                log.error(
                        "Kylo is running in clustered mode by Quartz scheduler is not configured for clustered mode.  Please ensure the Quartz is configured for database persistence in clustered mode ");
            }
        } catch (IOException e) {
            log.error(
                    "Kylo is running in Clustered mode the system cannot find the 'quartz.properties' file.  Please ensure the Quartz is configured for database persistence in clustered mode",
                    e);
        }
    } else {
        log.error(
                "Kylo is running in Clustered mode the system cannot find the 'quartz.properties' file. Please ensure the Quartz is configured for database persistence in clustered mode");
    }

}

From source file:de.codecentric.boot.admin.web.servlet.resource.PreferMinifiedFilteringResourceResolver.java

private Resource findMinified(Resource resource) {
    try {/* ww w. j av a2s .c  om*/
        String basename = StringUtils.stripFilenameExtension(resource.getFilename());
        String extension = StringUtils.getFilenameExtension(resource.getFilename());
        Resource minified = resource.createRelative(basename + extensionPrefix + '.' + extension);
        if (minified.exists()) {
            return minified;
        }
    } catch (IOException ex) {
        logger.trace("No minified resource for [" + resource.getFilename() + "]", ex);
    }
    return null;
}

From source file:net.javacrumbs.springws.test.lookup.ExpressionBasedResourceLookup.java

/**
 * Looks for a resource using given expression.
 * @param xpath//from w w w.ja  v a 2  s  . c om
 * @param uri
 * @param document
 * @return
 */
protected Resource findResourceForExpression(String xpath, URI uri, Document document) {
    String resourcePath = evaluateExpression(xpath, uri, document);
    logger.debug("Looking for resource \"" + resourcePath + "\"");
    Resource resultResource = getResourceLoader().getResource(resourcePath);
    resultResource = resultResource.exists() ? resultResource : null;
    return resultResource;
}

From source file:org.codehaus.groovy.grails.plugins.searchable.compass.config.mapping.CompassMappingXmlSearchableGrailsDomainClassMappingConfigurator.java

/**
 * Does this strategy handle the given domain class (and it's respective mapping type)
 *
 * @param grailsDomainClass the Grails domain class
 * @return true if the mapping of the class can be handled by this strategy
 *///from w  ww  .j  av a2s .c o m
public boolean isMappedBy(GrailsDomainClass grailsDomainClass) {
    Assert.notNull(resourceLoader, "resourceLoader cannot be null");
    Resource resource = getMappingResource(grailsDomainClass);
    return resource.exists();
}

From source file:com.github.ukase.config.WebConfig.java

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    String location = "classpath:static/";

    if (devMode) {
        Path path = Paths.get(getProjectRootRequired(), "ui", "target", "dist");
        location = path.toUri().toString();
    }//ww w. j a v  a 2 s. co m

    newResourceHandler(registry, "/bundle.*.js", location).addTransformer(new AppCacheManifestTransformer());

    newResourceHandler(registry, "/cache*.appcache", location);

    newResourceHandler(registry, "/**", location + "index.html").addResolver(new PathResourceResolver() {
        @Override
        protected Resource getResource(String resourcePath, Resource location) throws IOException {
            Resource resource = location.createRelative(resourcePath);
            return resource.exists() && resource.isReadable() ? resource : null;
        }
    });
}

From source file:com.yeahmobi.yunit.dataset.AbstractDataSetLoader.java

/**
 * Loads a {@link IDataSet dataset} from {@link Resource}s obtained from the specified <tt>location</tt>. Each
 * <tt>location</tt> can be mapped to a number of potential {@link #getResourceLocations resources}, the first
 * resource that {@link Resource#exists() exists} will be used. {@link Resource}s are loaded using the
 * {@link ResourceLoader} returned from {@link #getResourceLoader}.
 * <p>//from w w w  .j a  v a 2s  .c o  m
 * If no resource can be found then <tt>null</tt> will be returned.
 *
 * @see #createDataSet(Resource)
 * @see com.yeahmobi.yunit.dataset.DataSetLoader#loadDataSet(Class,Method,String,String) java.lang.String)
 */
public IDataSet loadDataSet(Class<?> testClass, Method testMethod, String location, String suffix)
        throws Exception {
    ResourceLoader[] resourceLoaders = getResourceLoader(testClass);
    for (ResourceLoader resourceLoader : resourceLoaders) {
        String[] resourceLocations = getResourceLocations(testClass, testMethod, location, suffix);
        for (String resourceLocation : resourceLocations) {
            Resource resource = resourceLoader.getResource(resourceLocation);
            if (resource.exists()) {
                return createDataSet(resource);
            }
        }
    }
    return null;
}

From source file:grails.plugin.searchable.internal.compass.config.mapping.CompassMappingXmlSearchableGrailsDomainClassMappingConfigurator.java

/**
 * Does this strategy handle the given domain class (and it's respective mapping type)
 *
 * @param grailsDomainClass the Grails domain class
 * @return true if the mapping of the class can be handled by this strategy
 *///  w w  w  .  ja v a2  s.  c  om
@Override
public boolean isMappedBy(GrailsDomainClass grailsDomainClass) {
    Assert.notNull(resourceLoader, "resourceLoader cannot be null");
    Resource resource = getMappingResource(grailsDomainClass);
    return resource.exists();
}

From source file:net.opentsdb.contrib.tsquare.support.TsWebApplicationContextInitializer.java

private TsdbConfigPropertySource loadTsdbConfig(final ResourcePatternResolver resolver) throws IOException {
    Resource configResource = null;

    for (final String location : OVERRIDE_SEARCH_LOCATIONS) {
        final String fullLoc = String.format("%s%s", location, CONFIG_FILENAME);
        log.debug("Searching for TSDB config in {}", fullLoc);

        final Resource res = resolver.getResource(fullLoc);
        if (res != null && res.exists()) {
            configResource = res;//from  w  w  w .  j  a  v  a  2s  . c  o  m
            log.info("Found TSDB config file using {} ", fullLoc);
            break;
        }
    }

    if (configResource == null) {
        return new TsdbConfigPropertySource(PROPERTY_SOURCE_NAME, new Config(true));
    } else if (configResource.isReadable()) {
        return new TsdbConfigPropertySource(PROPERTY_SOURCE_NAME,
                new Config(configResource.getFile().getAbsolutePath()));
    } else {
        throw new IllegalStateException("Unable to locate any TSDB config files!");
    }
}

From source file:org.brekka.stillingar.spring.resource.dir.WebappDirectory.java

@Override
public Resource getDirResource() {
    if (!ClassUtils.isPresent("org.springframework.web.context.WebApplicationContext",
            this.getClass().getClassLoader())) {
        return new UnresolvableResource("Not a webapp");
    }/*from ww  w .  j  ava2 s .  com*/
    if (applicationContext instanceof org.springframework.web.context.WebApplicationContext == false) {
        return new UnresolvableResource("Web context not available");
    }

    Resource resource = applicationContext.getResource(path);
    if (!resource.exists()) {
        resource = new UnresolvableResource("Webapp path '%s' not found", path);
    }

    return resource;
}