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:de.fme.alfresco.bootstrap.ScriptBootstrap.java

private String getScriptName(Resource res) {
    try {/*from   www.ja  va2 s  .c  om*/
        return res.getURI().toString();
    } catch (IOException e) {
        throw new AlfrescoRuntimeException("Error reading script resource.", e);
    }

}

From source file:com.qcadoo.view.internal.resource.JspResourceResolver.java

private void copyResource(final Resource resource) {
    if (!resource.isReadable()) {
        return;//ww w.  j av a2  s  .  co m
    }

    try {
        String path = resource.getURI().toString().split("WEB-INF/jsp/")[1];
        File file = new File(webappPath + "/WEB-INF/jsp/" + path);

        if (resource.getInputStream().available() == 0) {
            FileUtils.forceMkdir(file);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Copying " + path + " to " + file.getAbsolutePath());
            }

            OutputStream output = null;

            try {
                output = new BufferedOutputStream(new FileOutputStream(file));
                IOUtils.copy(resource.getInputStream(), output);
            } finally {
                IOUtils.closeQuietly(output);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException("Cannot copy resource " + resource, e);
    }
}

From source file:com.toyota.carservice.config.config2.java

public Object newStage3(Stage stage, Label lb, String load, String judul, boolean resize, StageStyle style,
        boolean maximized) {
    try {/*  w  ww.  j a  v  a 2s  .co  m*/
        Stage st = new Stage();
        stage = (Stage) lb.getScene().getWindow();
        FXMLLoader root = new FXMLLoader(getClass().getResource(load));

        Scene scene = new Scene(root.load());
        st.initStyle(style);
        st.setResizable(resize);
        st.setMaximized(maximized);
        st.setTitle(judul);
        st.setScene(scene);
        ApplicationContext appContex = config.getInstance().getApplicationContext();
        Resource resource = appContex.getResource("classpath:com/toyota/carservice/img/kallatoyota.png");
        st.getIcons().add(new Image(resource.getURI().toString()));
        st.show();
        return root.getController();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.toyota.carservice.config.config2.java

public Object newStage(Stage stage, Label lb, String load, String judul, boolean resize, StageStyle style,
        boolean maximized) {
    try {/*ww w  .  j  a v a  2  s .  c  om*/
        Stage st = new Stage();
        stage = (Stage) lb.getScene().getWindow();
        FXMLLoader root = new FXMLLoader(getClass().getResource(load));

        Scene scene = new Scene(root.load());
        st.initStyle(style);
        st.setResizable(resize);
        st.setMaximized(maximized);
        st.setTitle(judul);
        st.setScene(scene);
        ApplicationContext appContex = config.getInstance().getApplicationContext();
        Resource resource = appContex.getResource("classpath:com/toyota/carservice/img/kallatoyota.png");
        st.getIcons().add(new Image(resource.getURI().toString()));
        st.show();
        stage.close();
        return root.getController();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.toyota.carservice.config.config2.java

public Object newStage2(Stage stage, Button lb, String load, String judul, boolean resize, StageStyle style,
        boolean maximized) {
    try {/*w w  w.  j a  v a 2  s  .c  o  m*/
        Stage st = new Stage();
        stage = (Stage) lb.getScene().getWindow();
        FXMLLoader root = new FXMLLoader(getClass().getResource(load));

        Scene scene = new Scene(root.load());
        st.initStyle(style);
        st.setResizable(resize);
        st.setMaximized(maximized);
        st.setTitle(judul);
        st.setScene(scene);
        ApplicationContext appContex = config.getInstance().getApplicationContext();
        Resource resource = appContex.getResource("classpath:com/toyota/carservice/img/kallatoyota.png");
        st.getIcons().add(new Image(resource.getURI().toString()));
        st.show();
        stage.close();
        return root.getController();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.globus.security.stores.ResourceSecurityWrapperStore.java

private Set<V> addCredentials(File directory) throws ResourceStoreException {
    FilenameFilter filter = getDefaultFilenameFilter();
    String[] children = directory.list(filter);
    Set<V> roots = new HashSet<V>();
    try {/* w  ww.  ja v a 2 s  .com*/
        for (String child : children) {
            File childFile = new File(directory, child);
            if (childFile.isDirectory()) {
                roots.addAll(addCredentials(childFile));
            } else {
                Resource resource = new FileSystemResource(childFile);
                String resourceUri = resource.getURI().toASCIIString();
                T fbo = this.wrapperMap.get(resourceUri);
                if (fbo == null) {
                    fbo = create(new FileSystemResource(childFile));
                }
                V target = fbo.create(resource);
                this.wrapperMap.put(resourceUri, fbo);
                roots.add(target);
            }
        }
        return roots;
    } catch (IOException e) {
        throw new ResourceStoreException(e);
    }
}

From source file:org.powertac.samplebroker.core.BrokerPropertiesService.java

private boolean validXmlResource(Resource xml) {
    try {//from w  ww . ja va 2  s .c  om
        log.info("Validating resource " + xml.getURI());
        String path = xml.getURI().toString();
        for (String regex : excludedPaths) {
            if (path.matches(regex)) {
                return false;
            }
            if (!xml.exists()) {
                log.warn("Resource " + xml.getURI() + " does not exist");
                return false;
            }
            if (!xml.isReadable()) {
                log.warn("Resource " + xml.getURI() + " is not readable");
                return false;
            }
        }
        return true;
    } catch (IOException e) {
        log.error("Should not happen: " + e.toString());
        return false;
    } catch (Exception e) {
        log.error("Validation error " + e.toString());
        e.printStackTrace();
        return false;
    }
}

From source file:nz.co.senanque.parser.InputStreamParserSource.java

public InputStreamParserSource(Resource resource) throws IOException {
    this(resource.getInputStream(), resource.getURI().toString(), 3000);
}

From source file:com.griddynamics.banshun.ContextParentBean.java

private List<String> collectConfigLocations(String location) throws IOException {
    List<String> result = new ArrayList<>();
    Resource[] resources = context.getResources(location);

    for (Resource resource : resources) {
        result.add(resource.getURI().toString());
    }//  ww w  .  java 2 s  .c o m
    return result;
}

From source file:org.parancoe.web.plugin.PluginHelper.java

protected void copyJspResources(ApplicationContextPlugin plugin, ServletContextEvent evt) throws IOException {
    List<String> jspResources = plugin.getJspResources();
    if (jspResources.isEmpty()) {
        log.info("No JSP resources to copy for this plugin.");
    } else {/*from w w  w  . j  ava  2 s . c  o  m*/
        String jspBasePath = Constants.DEFAULT_JSP_BASE_PATH;
        if (ctx.containsBean(Constants.JSP_BASE_PATH_BEAN_NAME)) {
            jspBasePath = (String) ctx.getBean(Constants.JSP_BASE_PATH_BEAN_NAME);
        }
        String realPath = evt.getServletContext().getRealPath(jspBasePath);
        if (realPath == null) {
            log.warn("Can't copy JSP resources to " + jspBasePath
                    + ". Is the application deployed as a WAR or in an inaccessible location?");
        } else {
            log.info("Copying JSP resources to " + realPath + " ...");
            for (String jspResource : jspResources) {
                log.info("  Copying " + jspResource + " ...");
                Resource[] resources = ctx.getResources(jspResource);
                int i = 0;
                for (Resource resource : resources) {
                    String resourceURI = resource.getURI().toString();
                    String baseName = extractJspResourceBaseName(resourceURI, plugin.getJspPrefix());
                    String destination = realPath + baseName;
                    File destinationFile = new File(destination);
                    if (destinationFile.exists()) {
                        log.warn("    Not copying " + resourceURI + " to " + destination
                                + " as it already exists.");
                    } else {
                        log.info("    Copying " + resourceURI + " to " + destination + " .");
                        destinationFile.getParentFile().mkdirs();
                        InputStream in = resource.getInputStream();
                        FileOutputStream out = new FileOutputStream(destinationFile);
                        try {
                            IOUtils.copy(in, out);
                        } finally {
                            IOUtils.closeQuietly(in);
                            IOUtils.closeQuietly(out);
                        }
                    }
                }
            }
        }
    }
}