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

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

Introduction

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

Prototype

URI getURI() throws IOException;

Source Link

Document

Return a URI handle for this resource.

Usage

From source file:com.griddynamics.banshun.config.xml.ParserUtils.java

public static String extractResourcePath(Resource resource) {
    try {/*from  w  w  w  .  ja v  a 2s  . com*/
        return resource.getURI().toString();
    } catch (IOException ex) {
        return resource.getDescription();
    }
}

From source file:org.bitsofinfo.util.reflection.SpringClassFinder.java

private static String convertResourceToClassName(Resource resource, String basePackage) throws IOException {
    String path = resource.getURI().toString();
    String pathWithoutSuffix = path.substring(0, path.length() - ClassUtils.CLASS_FILE_SUFFIX.length());
    String relativePathWithoutSuffix = pathWithoutSuffix.substring(pathWithoutSuffix.indexOf(basePackage));
    String className = relativePathWithoutSuffix.replace(File.separator, ".");
    return className;
}

From source file:org.mybatis.spring.boot.autoconfigure.SpringBootVFS.java

private static String preserveSubpackageName(final Resource resource, final String rootPath) {
    try {/*  w  w  w .j  av  a  2s.  co  m*/
        final String uriStr = resource.getURI().toString();
        final int start = uriStr.indexOf(rootPath);
        return uriStr.substring(start);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:guru.qas.martini.tag.ResourceExecutor.java

private static URI getURI(Resource resource) {
    URI uri = null;//from  ww  w .  ja  v  a 2 s. co  m
    try {
        uri = resource.getURI();
    } catch (Exception e) {
        LOGGER.warn("unable to obtain URI from resource {}", resource, e);
    }
    return uri;
}

From source file:nl.flotsam.hamcrest.schema.relaxng.RelaxNGMatchers.java

/**
 * Creates a RelaxNG matcher based on a {@link Resource} object pointing to a RelaxNG schema. (XML Syntax)
 *//*from   w  w  w  .java2  s.  c o  m*/
public static TypeSafeDiagnosingMatcher<Object> isValidatedBy(Resource resource) {
    VerifierFactory factory = new com.sun.msv.verifier.jarv.TheFactoryImpl();
    InputStream in = null;
    try {
        URI uri = resource.getURI();
        in = resource.getInputStream();
        if (uri == null) {
            return isValidatedBy(factory.compileSchema(in), resource.toString());
        } else {
            return isValidatedBy(factory.compileSchema(in, resource.getURI().toASCIIString()),
                    resource.getFilename());
        }
    } catch (Exception e) {
        throw new IllegalStateException("Failed to construct matcher", e);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.ethercamp.harmony.service.ImportContractIndexTest.java

private static byte[] resourceToBytes(Resource resource) throws IOException {
    return Files.readAllBytes(Paths.get(resource.getURI()));
}

From source file:com.bsb.cms.commons.utils.URLUtils.java

/**
 * ResourceLoader?excel/*from   ww  w .  java2s  .c  o m*/
 * @param fileName
 * @return
 */
public static String getExcelFilePath(String fileName) {
    Resource path = resourceLoader.getResource("classpath:report/" + fileName);//?getResource
    //Resource path = resourceLoader.getResource("/WEB-INF/classes/report/" + fileName);//?
    try {
        return path.getURI().getPath();
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:no.kantega.commons.util.XMLHelper.java

public static Document openDocument(Resource resource, EntityResolver er) throws InvalidFileException {
    try (InputStream is = resource.getInputStream()) {

        return openDocument(is, er, resource.getURI().getRawPath());
    } catch (IOException e) {
        throw new InvalidFileException("Error opening XML document from Resource", e);
    }//from  ww  w  .j  av a2 s  .com
}

From source file:com.sinosoft.one.mvc.scanning.ResourceRef.java

public static ResourceRef toResourceRef(Resource folder) throws IOException {
    ResourceRef rr = new ResourceRef(folder, null, null);
    String[] modifiers = null;//from www.j av  a 2s  . c o  m
    Resource mvcPropertiesResource = rr.getInnerResource("META-INF/mvc.properties");
    if (mvcPropertiesResource.exists()) {
        if (logger.isDebugEnabled()) {
            logger.debug("found mvc.properties: " + mvcPropertiesResource.getURI());
        }
        InputStream in = mvcPropertiesResource.getInputStream();
        rr.properties.load(in);
        in.close();
        String attrValue = rr.properties.getProperty("mvc");
        if (attrValue == null) {
            attrValue = rr.properties.getProperty("Mvc");
        }
        if (attrValue != null) {
            modifiers = StringUtils.split(attrValue, ", ;\n\r\t");
            if (logger.isDebugEnabled()) {
                logger.debug("modifiers[by properties][" + rr.getResource().getURI() + "]="
                        + Arrays.toString(modifiers));
            }
        }
    }
    //
    if (modifiers == null) {
        if (!"jar".equals(rr.getProtocol())) {
            modifiers = new String[] { "**" };
            if (logger.isDebugEnabled()) {
                logger.debug("modifiers[by default][" + rr.getResource().getURI() + "]="
                        + Arrays.toString(modifiers));
            }
        } else {
            JarFile jarFile = new JarFile(rr.getResource().getFile());
            Manifest manifest = jarFile.getManifest();
            if (manifest != null) {
                Attributes attributes = manifest.getMainAttributes();
                String attrValue = attributes.getValue("mvc");
                if (attrValue == null) {
                    attrValue = attributes.getValue("Mvc");
                }
                if (attrValue != null) {
                    modifiers = StringUtils.split(attrValue, ", ;\n\r\t");
                    if (logger.isDebugEnabled()) {
                        logger.debug("modifiers[by manifest.mf][" + rr.getResource().getURI() + "]="
                                + Arrays.toString(modifiers));
                    }
                }
            }
        }
    }
    rr.setModifiers(modifiers);
    return rr;
}

From source file:com.gzj.tulip.load.ResourceRef.java

public static ResourceRef toResourceRef(Resource folder) throws IOException {
    ResourceRef rr = new ResourceRef(folder, null, null);
    String[] modifiers = null;/*from   w w  w.  ja  v  a  2s .c o m*/
    Resource rosePropertiesResource = rr.getInnerResource("META-INF/rose.properties");
    if (rosePropertiesResource.exists()) {
        if (logger.isDebugEnabled()) {
            logger.debug("found rose.properties: " + rosePropertiesResource.getURI());
        }
        InputStream in = rosePropertiesResource.getInputStream();
        rr.properties.load(in);
        in.close();
        String attrValue = rr.properties.getProperty("rose");
        if (attrValue == null) {
            attrValue = rr.properties.getProperty("Rose");
        }
        if (attrValue != null) {
            modifiers = StringUtils.split(attrValue, ", ;\n\r\t");
            if (logger.isDebugEnabled()) {
                logger.debug("modifiers[by properties][" + rr.getResource().getURI() + "]="
                        + Arrays.toString(modifiers));
            }
        }
    }
    //
    if (modifiers == null) {
        if (!"jar".equals(rr.getProtocol())) {
            modifiers = new String[] { "**" };
            if (logger.isDebugEnabled()) {
                logger.debug("modifiers[by default][" + rr.getResource().getURI() + "]="
                        + Arrays.toString(modifiers));
            }
        } else {
            JarFile jarFile = new JarFile(rr.getResource().getFile());
            Manifest manifest = jarFile.getManifest();
            if (manifest != null) {
                Attributes attributes = manifest.getMainAttributes();
                String attrValue = attributes.getValue("rose");
                if (attrValue == null) {
                    attrValue = attributes.getValue("Rose");
                }
                if (attrValue != null) {
                    modifiers = StringUtils.split(attrValue, ", ;\n\r\t");
                    if (logger.isDebugEnabled()) {
                        logger.debug("modifiers[by manifest.mf][" + rr.getResource().getURI() + "]="
                                + Arrays.toString(modifiers));
                    }
                }
            }
        }
    }
    rr.setModifiers(modifiers);
    return rr;
}