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

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

Introduction

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

Prototype

URL getURL() throws IOException;

Source Link

Document

Return a URL handle for this resource.

Usage

From source file:edu.duke.cabig.c3pr.rules.deploy.SystemRulesDeployer.java

public SystemRulesDeployer(RuleDeploymentService ruleDeploymentService) {
    if (log.isInfoEnabled())
        log.info("Begining system rule loading......");
    try {//  w ww.ja  v  a2s. c  om

        // 1. create the base pattern.
        String pattern = "classpath*:" + SystemRulesDeployer.class.getPackage().getName().replace(".", "/")
                + "/*.xml";

        // 2. Load the rule files, that are to be loaded in repository
        // and load them only if they are not already loaded.
        for (Resource resource : getResources(pattern)) {
            if (log.isDebugEnabled())
                log.debug("Loading rule file :" + resource.getURL().toString());
            try {
                String ruleXml = getFileContext(resource.getInputStream());
                org.drools.rule.Package rulePackage = XMLUtil.unmarshalToPackage(ruleXml);
                String ruleBindUri = rulePackage.getName();
                // unregister the rules
                try {
                    ruleDeploymentService.deregisterRuleSet(ruleBindUri);
                } catch (Exception ignore) {
                }
                // register the rules
                if (log.isDebugEnabled())
                    log.debug("Registering at bindUri : " + ruleBindUri + "\r\n\r\n" + ruleXml);
                ruleDeploymentService.registerRulePackage(ruleBindUri, rulePackage);
                if (log.isDebugEnabled())
                    log.debug("Sucessfully deployed rule at bindUri :" + ruleBindUri);
            } catch (RuntimeException e) {
                log.debug("It seems the system rule is already available, so ignoring", e);
            }

        }

    } catch (Exception e) {
        log.warn("Error while loading system rules :", e);
    }
    if (log.isInfoEnabled())
        log.debug("Finished system rule loading......");
}

From source file:com.vilt.minium.script.test.impl.MiniumRhinoTestsSupport.java

protected List<String> getModulesUrls() throws IOException {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(classLoader);
    Resource[] resources = resolver.getResources("classpath*:modules");
    List<String> moduleUrls = Lists.newArrayList();
    for (Resource resource : resources) {
        moduleUrls.add(resource.getURL().toExternalForm());
    }//from  w w  w .  j  av a  2 s. c  om
    return moduleUrls;
}

From source file:org.carewebframework.shell.BaseXmlParser.java

/**
 * Return the path of the resource being parsed.
 * //from  w ww. ja v  a2s  .  c o  m
 * @param parserContext The current parser context.
 * @return The resource being parsed, or null if cannot be determined.
 */
protected String getResourcePath(ParserContext parserContext) {
    if (parserContext != null) {
        try {
            Resource resource = parserContext.getReaderContext().getResource();
            return resource == null ? null : resource.getURL().getPath();
        } catch (IOException e) {
        }
    }

    return null;
}

From source file:org.osiam.OsiamHome.java

public void initialize() {
    try {/* w w  w . jav  a  2 s.com*/
        if (Files.notExists(osiamHome)) {
            Files.createDirectories(osiamHome);
        } else {
            checkState(Files.isDirectory(osiamHome), "'osiam.home' (%s) is not a directory", osiamHome);
            checkState(Files.isReadable(osiamHome), "'osiam.home' (%s) is not readable", osiamHome);
            checkState(Files.isExecutable(osiamHome), "'osiam.home' (%s) is not accessible", osiamHome);
        }

        if (!isEmpty(osiamHome)) {
            return;
        }

        checkState(Files.isWritable(osiamHome), "'osiam.home' (%s) is not writable", osiamHome);
        Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath:/home/**/*");
        for (Resource resource : resources) {
            // don't process directories
            if (resource.getURL().toString().endsWith("/")) {
                continue;
            }
            copyToHome(resource, osiamHome);
        }
        if (Files.notExists(osiamHome.resolve("data"))) {
            Files.createDirectories(osiamHome.resolve("data"));
        }

        hasInitializedHome = true;
    } catch (IOException e) {
        throw new IllegalStateException("Could not initialize osiam.home", e);
    }
}

From source file:uk.co.grahamcox.yui.spring.ControllerBeanDefinitionParser.java

/**
 * Build the groups to use/* w  w w  . j  av a 2s .  c o  m*/
 * @param groups the map of group details
 * @return the groups to use
 */
private Collection<ModuleGroup> buildGroups(Map<String, String> groups) throws IOException {
    Set<ModuleGroup> result = new HashSet<>();
    ModuleGroupLoader loader = new JsonModuleGroupLoader();
    for (String key : groups.keySet()) {
        Resource resource = resourceLoader.getResource(groups.get(key));
        result.add(loader.load(key, resource.getURL()));
    }
    return result;
}

From source file:com.agileapes.couteau.maven.resource.ClassPathScanningClassProvider.java

private Class resolveClass(Resource resource, String basePackage) throws IOException, ClassNotFoundException {
    final String clazzCleanPath = StringUtils.cleanPath(resource.getURL().getPath());
    final String clazzPathWithoutExtension = StringUtils.stripFilenameExtension(clazzCleanPath);
    final String resourcePackageLikeStr = ClassUtils.convertResourcePathToClassName(clazzPathWithoutExtension);
    final String className = resourcePackageLikeStr.substring(resourcePackageLikeStr.lastIndexOf(basePackage));
    return ClassUtils.forName(className, classLoader);
}

From source file:org.carewebframework.ui.icons.IconLibraryBase.java

@Override
public List<String> getMatching(String iconName, String dimensions) {
    List<String> urls = new ArrayList<String>();

    try {//from www .  java2s  .  c  o  m
        for (Resource resource : applicationContext
                .getResources(formatURL(iconName, dimensions, "classpath:web"))) {
            String path = resource.getURL().getPath();
            int i = path.indexOf(resourcePath);
            urls.add("~." + path.substring(i));
        }
    } catch (IOException e) {
        log.error("Error enumerating icons.", e);
    }

    return urls;
}

From source file:org.dozer.spring.DozerBeanMapperFactoryBean.java

private void loadMappingFiles() throws IOException {
    if (this.mappingFiles != null) {
        final List<String> mappings = new ArrayList<String>(this.mappingFiles.length);
        for (Resource mappingFile : this.mappingFiles) {
            URL url = mappingFile.getURL();
            mappings.add(url.toString());
        }/*from w w w  . ja v a 2 s  . co m*/
        this.beanMapper.setMappingFiles(mappings);
    }
}

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 .  ja va  2  s .co 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) {
    }

}

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 a  v a  2  s  .  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());
    }

}