Example usage for org.springframework.util StringUtils applyRelativePath

List of usage examples for org.springframework.util StringUtils applyRelativePath

Introduction

In this page you can find the example usage for org.springframework.util StringUtils applyRelativePath.

Prototype

public static String applyRelativePath(String path, String relativePath) 

Source Link

Document

Apply the given relative path to the given Java resource path, assuming standard Java folder separation (i.e.

Usage

From source file:org.shept.util.JarResourceCopier.java

public void initializeResources(ServletContext context) {
    String destPath = StringUtils.cleanPath(context.getRealPath(getTargetPath()));
    if (files != null && files.length > 0) {
        for (int i = 0; i < files.length; i++) {
            String source = StringUtils.applyRelativePath(getSourcePath(), files[i]);
            // surprise surprise you can't use StringUtils.applyRelativePath here this will cut off the last part of destPath
            JarUtils.copyResourcesOnce(new ClassPathResource(source), destPath, destPath + "/" + files[i]);
        }//from ww  w. j  a  v  a 2 s.  c  om
    } else {
        JarUtils.copyResourcesOnce(new ClassPathResource(getSourcePath()), destPath);
    }
}

From source file:spring.osgi.io.OsgiBundleResource.java

/**
 * Returns a resource relative to this resource. This implementation creates
 * an <code>OsgiBundleResource</code>, applying the given path relative
 * to the path of the underlying resource of this descriptor.
 *
 * @param relativePath the relative path (relative to this resource)
 * @return the resource handle for the relative resource
 * @see org.springframework.util.StringUtils#applyRelativePath(String,
 * String)/*from   w ww  . j  a  va  2  s. c om*/
 */
public Resource createRelative(String relativePath) {
    String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
    return new OsgiBundleResource(this.bundle, pathToUse);
}

From source file:org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.java

/**
 * Parse an "import" element and load the bean definitions
 * from the given resource into the bean factory.
 *///from  w w  w.  j  av  a 2  s .c  o m
protected void importBeanDefinitionResource(Element ele) {
    String location = ele.getAttribute(RESOURCE_ATTRIBUTE);
    if (!StringUtils.hasText(location)) {
        getReaderContext().error("Resource location must not be empty", ele);
        return;
    }

    // Resolve system properties: e.g. "${user.dir}"
    location = getReaderContext().getEnvironment().resolveRequiredPlaceholders(location);

    Set<Resource> actualResources = new LinkedHashSet<>(4);

    // Discover whether the location is an absolute or relative URI
    boolean absoluteLocation = false;
    try {
        absoluteLocation = ResourcePatternUtils.isUrl(location) || ResourceUtils.toURI(location).isAbsolute();
    } catch (URISyntaxException ex) {
        // cannot convert to an URI, considering the location relative
        // unless it is the well-known Spring prefix "classpath*:"
    }

    // Absolute or relative?
    if (absoluteLocation) {
        try {
            int importCount = getReaderContext().getReader().loadBeanDefinitions(location, actualResources);
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "Imported " + importCount + " bean definitions from URL location [" + location + "]");
            }
        } catch (BeanDefinitionStoreException ex) {
            getReaderContext().error("Failed to import bean definitions from URL location [" + location + "]",
                    ele, ex);
        }
    } else {
        // No URL -> considering resource location as relative to the current file.
        try {
            int importCount;
            Resource relativeResource = getReaderContext().getResource().createRelative(location);
            if (relativeResource.exists()) {
                importCount = getReaderContext().getReader().loadBeanDefinitions(relativeResource);
                actualResources.add(relativeResource);
            } else {
                String baseLocation = getReaderContext().getResource().getURL().toString();
                importCount = getReaderContext().getReader().loadBeanDefinitions(
                        StringUtils.applyRelativePath(baseLocation, location), actualResources);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Imported " + importCount + " bean definitions from relative location [" + location
                        + "]");
            }
        } catch (IOException ex) {
            getReaderContext().error("Failed to resolve current resource location", ele, ex);
        } catch (BeanDefinitionStoreException ex) {
            getReaderContext().error(
                    "Failed to import bean definitions from relative location [" + location + "]", ele, ex);
        }
    }
    Resource[] actResArray = actualResources.toArray(new Resource[actualResources.size()]);
    getReaderContext().fireImportProcessed(location, actResArray, extractSource(ele));
}

From source file:org.springframework.core.io.ClassPathResource.java

/**
 * This implementation creates a ClassPathResource, applying the given path
 * relative to the path of the underlying resource of this descriptor.
 *
 * @see org.springframework.util.StringUtils#applyRelativePath(String, String)
 *///from   ww  w  .  jav a  2s.  com
public Resource createRelative(String relativePath) {
    String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
    return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
}