Example usage for org.springframework.context ApplicationContext getResources

List of usage examples for org.springframework.context ApplicationContext getResources

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext getResources.

Prototype

Resource[] getResources(String locationPattern) throws IOException;

Source Link

Document

Resolve the given location pattern into Resource objects.

Usage

From source file:org.carewebframework.smart.ui.SmartLocator.java

/**
 * Search for SMART manifests within the specified path root. Each discovered manifest will
 * result in the creation of a CareWeb plugin definition for the associated SMART app.
 *
 * @param appContext The application context.
 * @param root Root path for search.// www .  jav a2  s.com
 */
private void findSmartManifests(ApplicationContext appContext, String root) {
    try {
        Resource[] resources = appContext.getResources(root + SMART_MANIFEST_PATTERN);

        for (Resource resource : resources) {
            PluginDefinition def = toDefinition(resource);

            if (def != null) {
                registry.register(def);
            }
        }
    } catch (IOException e) {
        log.error("Error searching for SMART manifests.", e);
    }

}

From source file:org.cloudfoundry.reconfiguration.util.StandardCloudUtils.java

private Boolean calculateUsingCloudServices(ApplicationContext applicationContext) {
    try {//from ww w.  java 2 s.  c o m
        for (Resource resource : applicationContext.getResources("classpath*:/META-INF/cloud/cloud-services")) {
            for (String cloudServiceClass : getCloudServiceClasses(resource)) {
                if (hasBeanOfType(applicationContext, cloudServiceClass)) {
                    return true;
                }
            }
        }
    } catch (IOException e) {
        this.logger.warning("Unable to read cloud service classes");
    }

    return false;
}

From source file:org.carewebframework.ui.LabelFinder.java

private void findLabelResources(ApplicationContext appContext, String root, String prefix,
        Map<String, LabelLocator> labelLocators) {
    try {//from w w w . j av a2s  .c o  m
        Resource[] resources = appContext.getResources(root + prefix + "-label*.properties");

        for (Resource resource : resources) {
            URL url = resource.getURL();
            String path = url.getPath();
            path = path.substring(path.lastIndexOf('!') + 1, path.lastIndexOf('/'));
            LabelLocator labelLocator = labelLocators.get(path);

            if (labelLocator == null) {
                labelLocator = new LabelLocator();
                labelLocators.put(path, labelLocator);
                Labels.register(labelLocator);

                if (log.isInfoEnabled()) {
                    log.info("Label resource(s) found at '" + path + "'.");
                }
            }

            labelLocator.addUrl(url);

            if (validate) {
                validate(resource);
            }
        }
    } catch (IOException e) {
        log.error("Error searching for labels: " + e.getMessage());
    }

}

From source file:org.carewebframework.api.alias.AliasTypeRegistry.java

/**
 * Load aliases from a property file./*  w  w  w . j  av a  2 s . c  o m*/
 * 
 * @param applicationContext The application context.
 * @param propertyFile A property file.
 */
private void loadAliases(ApplicationContext applicationContext, String propertyFile) {
    if (propertyFile.isEmpty()) {
        return;
    }

    Resource[] resources;

    try {
        resources = applicationContext.getResources(propertyFile);
    } catch (IOException e) {
        log.error("Failed to locate alias property file: " + propertyFile, e);
        return;
    }

    for (Resource resource : resources) {
        if (!resource.exists()) {
            log.info("Did not find alias property file: " + resource.getFilename());
            continue;
        }

        InputStream is = null;

        try {
            is = resource.getInputStream();
            Properties props = new Properties();
            props.load(is);

            for (Entry<Object, Object> entry : props.entrySet()) {
                try {
                    register((String) entry.getKey(), (String) entry.getValue());
                    entryCount++;
                } catch (Exception e) {
                    log.error("Error registering alias for '" + entry.getKey() + "'.", e);
                }
            }

            fileCount++;
        } catch (IOException e) {
            log.error("Failed to load alias property file: " + resource.getFilename(), e);
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
}

From source file:com.haulmont.cuba.web.sys.WebJarResourceResolver.java

protected void scanResources(ApplicationContext applicationContext) throws IOException {
    // retrieve all resources from all JARs
    Resource[] resources = applicationContext.getResources("classpath*:META-INF/resources/webjars/**");

    for (Resource resource : resources) {
        URL url = resource.getURL();
        String urlString = url.toString();
        int classPathStartIndex = urlString.indexOf(CLASSPATH_WEBJAR_PREFIX);
        if (classPathStartIndex > 0) {
            String resourcePath = urlString.substring(classPathStartIndex + CLASSPATH_WEBJAR_PREFIX.length());
            if (!Strings.isNullOrEmpty(resourcePath) && !resourcePath.endsWith("/")) {
                mapping.put(resourcePath, new UrlHolder(url));
            }/*from ww  w  .  j  av a  2  s . co  m*/
        } else {
            log.debug("Ignored WebJAR resource {} since it does not contain class path prefix {}", urlString,
                    CLASSPATH_WEBJAR_PREFIX);
        }
    }

    this.fullPathIndex = getFullPathIndex(mapping.keySet());
}

From source file:org.carewebframework.shell.themes.ThemeDefinition.java

/**
 * Uses the application context to enumerate all of the file resources associated with the root
 * path for the theme./*from   www.  jav a2  s. c o m*/
 * 
 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
 */
@Override
public void setApplicationContext(ApplicationContext appContext) throws BeansException {
    try {
        final String root = "web/" + url;
        final int rootLength = root.length();
        final String wc = "classpath*:" + root + "**";
        final Resource[] resources = appContext.getResources(wc);
        files = new HashSet<String>(resources.length);

        for (Resource resource : resources) {
            final String path = resource.getURL().getPath();
            final int i = path.indexOf(root);

            if (i > -1) {
                files.add(path.substring(i + rootLength));
            }
        }

    } catch (Exception e) {
    }

}