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

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

Introduction

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

Prototype

String getDescription();

Source Link

Document

Return a description for this resource, to be used for error output when working with the resource.

Usage

From source file:org.spring.resource.PatternResolverTest.java

public static void main(String[] args) throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

    ///////*from w ww  . j  ava  2  s  .  c  om*/
    // xml??
    //////

    Resource resources[] = resolver.getResources("classpath*:*.xml");
    for (Resource resource : resources) {
        System.out.println("?" + resource.getDescription());
    }
}

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

public static String extractResourcePath(Resource resource) {
    try {/*  w w w .j a va 2 s  .c  o  m*/
        return resource.getURI().toString();
    } catch (IOException ex) {
        return resource.getDescription();
    }
}

From source file:gov.nih.nci.integration.util.CommonsPropertyLoaderUtil.java

/**
 * fill properties from given resource/* ww  w . j  av a2  s  .  c om*/
 * 
 * @param resource - resource
 * @param properties - properties to fill
 */
private static void fillProperties(Resource resource, Properties properties) {
    try {
        if (resource.exists()) {
            LOG.info("merging properties form : " + resource.getDescription());
            PropertiesLoaderUtils.fillProperties(properties, resource);
        } else {
            LOG.info(String.format("can not merge property from %s as resource does not exists.",
                    resource.getDescription()));
        }
    } catch (IOException e) {
        final String message = "error while loading properties from resource" + resource;
        LOG.error(message, e);
        throw new RuntimeException(message, e);// NOPMD
    }
}

From source file:gov.nih.nci.cacis.common.util.CommonsPropertyLoaderUtil.java

/**
 * fill properties from given resource/*  w w w. j  a  v  a 2 s . c  o m*/
 *
 * @param resource   - resource
 * @param properties - properties to fill
 */
private static void fillProperties(Resource resource, Properties properties) {
    try {
        if (resource.exists()) {
            LOG.info("merging properties form : " + resource.getDescription());
            PropertiesLoaderUtils.fillProperties(properties, resource);
        } else {
            LOG.info(String.format("can not merge property from %s as resource does not exists.",
                    resource.getDescription()));
        }
    } catch (IOException e) {
        final String message = "error while loading properties from resource" + resource;
        LOG.error(message, e);
        throw new ApplicationRuntimeException(message, e);
    }
}

From source file:org.biopax.validator.Main.java

protected static void runBatch(Validator validator, Collection<Resource> resources) throws IOException {

    //collect all reports in this object (only if --output option was used)
    final ValidatorResponse consolidatedReport = new ValidatorResponse();

    // Read from the batch and validate from file, id or url, line-by-line (stops on first empty line)
    for (Resource resource : resources) {
        Validation result = new Validation(new IdentifierImpl(), resource.getDescription(), autofix, null,
                maxErrors, profile);//from w  w w .  j a  v  a2  s .  c o  m
        result.setDescription(resource.getDescription());
        log.info("BioPAX DATA IMPORT FROM: " + result.getDescription());
        try {
            validator.importModel(result, resource.getInputStream());
            validator.validate(result);

            //if autofix is enabled, then do normalize too
            if (autofix) {
                Model model = (Model) result.getModel();
                Normalizer normalizer = new Normalizer();
                normalizer.setXmlBase(xmlBase); //if xmlBase is null, the model's one is used
                normalizer.normalize(model);
            }

            if (output != null)
                consolidatedReport.addValidationResult(result);

        } catch (Exception e) {
            log.error("failed", e);
        }

        final String filename = outFileName(result);
        PrintWriter writer;

        // save modified (normalized) biopax if the option was used
        if (autofix) {
            Model model = (Model) result.getModel();
            (new SimpleIOHandler()).convertToOWL(model, new FileOutputStream(filename + EXT));
        }

        // remove the BioPAX data before writing report
        result.setModel(null);
        result.setModelData(null);

        // save the individual validation results
        //unless the user specified the output file explicitly
        if (output == null || output.isEmpty()) {
            writer = new PrintWriter(filename + ".validation." + outFormat);
            Source xsltSrc = (outFormat.equalsIgnoreCase("html"))
                    ? new StreamSource(ctx.getResource("classpath:html-result.xsl").getInputStream())
                    : null;
            ValidatorUtils.write(result, writer, xsltSrc);
            writer.close();
        }

        validator.getResults().remove(result);
        log.info("Done with " + filename);
    }

    // save if the user specified the output file explicitly
    if (output != null) {
        Writer writer = new PrintWriter(output);
        Source xsltSrc = (outFormat.equalsIgnoreCase("html"))
                ? new StreamSource(ctx.getResource("classpath:html-result.xsl").getInputStream())
                : null;
        ValidatorUtils.write(consolidatedReport, writer, xsltSrc);
        writer.close();
    }
}

From source file:com.googlecode.flyway.core.util.ResourceUtils.java

/**
 * Loads this resource in a string using this encoding.
 *
 * @param resource The resource to load.
 * @param encoding The encoding of the resource.
 * @return The resource contents as a string.
 *//*from   w  w  w. j  ava  2 s  .c om*/
public static String loadResourceAsString(Resource resource, String encoding) {
    try {
        Reader reader = new InputStreamReader(resource.getInputStream(), Charset.forName(encoding));
        return FileCopyUtils.copyToString(reader);
    } catch (IOException e) {
        throw new IllegalStateException(
                "Unable to load resource: " + resource.getDescription() + " (encoding: " + encoding + ")", e);
    }
}

From source file:com.microsoft.exchange.impl.ExchangeWebServicesClient.java

/**
 * /*from  w w  w  . j av  a  2s .  com*/
 * @param resource
 * @param password
 * @return
 */
protected static KeyStore getKeystoreFromResource(Resource resource, char[] password) {
    try {
        KeyStore k = KeyStore.getInstance(KeyStore.getDefaultType());
        k.load(resource.getInputStream(), password);
        return k;
    } catch (KeyStoreException e) {
        throw new IllegalArgumentException("failed to load keystore from " + resource.getDescription(), e);
    } catch (CertificateException e) {
        throw new IllegalArgumentException("failed to load keystore from " + resource.getDescription(), e);
    } catch (IOException e) {
        throw new IllegalArgumentException("failed to load keystore from " + resource.getDescription(), e);
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalArgumentException("failed to load keystore from " + resource.getDescription(), e);
    }

}

From source file:ch.rasc.edsutil.optimizer.graph.Graph.java

public Node createNode(Resource resource) {
    Node newNode = this.nodesDb.get(resource.getDescription());
    if (newNode == null) {
        newNode = new Node(resource);
        this.nodesDb.put(resource.getDescription(), newNode);
    }//from  w w w. j ava2 s  .com
    return newNode;
}

From source file:org.springmodules.validation.bean.conf.ResourceConfigurationLoadingException.java

public ResourceConfigurationLoadingException(Resource resource) {
    super("Could not load configuration from resource '" + resource.getDescription() + "'");
    this.resource = resource;
}

From source file:org.springmodules.validation.bean.conf.ResourceConfigurationLoadingException.java

public ResourceConfigurationLoadingException(Resource resource, Throwable cause) {
    super("Could not load configuration from resource '" + resource.getDescription() + "'", cause);
    this.resource = resource;
}