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:com.hp.application.automation.tools.octane.tests.CopyResourceSCM.java

@Override
public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace,
        BuildListener listener, File changeLogFile) throws IOException, InterruptedException {
    if (workspace.exists()) {
        listener.getLogger().println("Deleting existing workspace " + workspace.getRemote());
        workspace.deleteRecursive();/*from   w  w w . ja  v  a 2  s  .c  o  m*/
    }
    Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:" + path + "/**");
    for (Resource resource : resources) {
        if (resource.exists() && resource.isReadable()) {
            String urlString = resource.getURL().toExternalForm();
            String targetName = urlString.substring(urlString.indexOf(path) + path.length());
            byte[] fileContent = IOUtils.toByteArray(resource.getInputStream());
            FileUtils.writeByteArrayToFile(new File(new File(workspace.getRemote(), targetPath), targetName),
                    fileContent);
        }
    }
    return true;
}

From source file:org.jdal.beans.ImagePropertyEditor.java

/**
 * Load image from classpath //from   w w  w  . ja  va2s  .c o  m
 * @param text the classpath of image resource
 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    Resource resource = new ClassPathResource(text);
    Image image = null;
    try {
        image = Toolkit.getDefaultToolkit().getImage(resource.getURL());
    } catch (IOException e) {
        log.error(e);
    }
    setValue(image);
}

From source file:org.pdfsam.community.PdfsamCommunityConfig.java

@Bean(name = "logo")
public Group logo() throws IOException {
    Resource resource = new ClassPathResource("/fxml/LogoCommunity.fxml");
    return FXMLLoader.load(resource.getURL());
}

From source file:com.saysth.commons.quartz.ResourceLoaderClassLoadHelper.java

public URL getResource(String name) {
    Resource resource = this.resourceLoader.getResource(name);
    try {/*w  ww  . j  a va  2  s .  c o  m*/
        return resource.getURL();
    } catch (FileNotFoundException ex) {
        return null;
    } catch (IOException ex) {
        logger.warn("Could not load " + resource);
        return null;
    }
}

From source file:org.jdal.beans.IconPropertyEditor.java

/**
 * Load image from classpath /*from  w  w  w  .j  a va  2  s .  co  m*/
 * @param text the classpath of image resource
 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    Resource resource = new ClassPathResource(text);
    Icon icon = null;
    try {
        Image image = Toolkit.getDefaultToolkit().getImage(resource.getURL());
        icon = new ImageIcon(image);
    } catch (IOException e) {
        log.error(e);
    }
    setValue(icon);
}

From source file:de.alpharogroup.duplicate.files.spring.SpringApplicationContext.java

/**
 * Instantiates a new spring application context.
 *///from ww w  . j a va 2 s. com
private SpringApplicationContext() {
    String rootContextDirectoryClassPath = "/ctx";

    String applicationContextPath = rootContextDirectoryClassPath + "/application-context.xml";

    ApplicationContext ac = new ClassPathXmlApplicationContext(applicationContextPath);

    Resource resource = ac.getResource("classpath:conf/log4j/log4jconfig.xml");

    try {
        DOMConfigurator.configure(resource.getURL());
    } catch (FactoryConfigurationError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    applicationContext = ac;
}

From source file:org.parancoe.web.xml.ControllerBeanDefinitionParser.java

/**
 * Return all classes in the package subtree matching Controller type.
 *
 * @param packageName The base package//from  www .j a  v a2s . co  m
 * @return The list of all classes
 */
protected List<Class> getAllControllerTypeClasses(String packageName) {
    List<Class> result = new ArrayList<Class>();
    try {
        String packagePart = packageName.replace('.', '/');
        String classPattern = "classpath*:/" + packagePart + "/**/*.class";
        Resource[] resources = this.resourceLoader.getResources(classPattern);
        for (int i = 0; i < resources.length; i++) {
            Resource resource = resources[i];
            String fileName = resource.getURL().toString();
            String className = fileName
                    .substring(fileName.indexOf(packagePart), fileName.length() - ".class".length())
                    .replace('/', '.');
            Class<?> type = Class.forName(className);

            if (Controller.class.isAssignableFrom(type)) {
                result.add(type);
            }
        }
    } catch (IOException e) {
        this.parserContext.getReaderContext().fatal(e.getMessage(), null, e);
        return null;
    } catch (ClassNotFoundException e) {
        this.parserContext.getReaderContext().fatal(e.getMessage(), null, e);
        return null;
    }
    return result;
}

From source file:com.jaspersoft.jasperserver.export.io.CastorSerializer.java

protected void createCastorMapping() {
    castorMapping = new Mapping();

    if (castorMappings != null) {
        try {//  ww  w.  jav  a2s  .c  o m
            for (int i = 0; i < castorMappings.length; i++) {
                Resource mappingRes = castorMappings[i];
                castorMapping.loadMapping(mappingRes.getURL());
            }
        } catch (IOException e) {
            log.error(e);
            throw new JSExceptionWrapper(e);
        } catch (MappingException e) {
            log.error(e);
            throw new JSExceptionWrapper(e);
        }
    }
}

From source file:com.github.jknack.handlebars.springmvc.SpringTemplateLoader.java

@Override
protected URL getResource(final String location) throws IOException {
    Resource resource = loader.getResource(location);
    if (!resource.exists()) {
        return null;
    }//from w  w w.j  a v  a 2 s.c om
    return resource.getURL();
}

From source file:hsa.awp.common.dao.template.TemplateFileSystemDao.java

public void setResource(Resource resource) {
    this.resource = resource;
    String path = "";
    try {//from ww w  . j a v a 2s. c o m
        path = resource.getURL().getPath();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (path.contains("physalix")) { //Tomcat environment
        setTemplatePath(path.substring(0, path.lastIndexOf("/") + 1) + "templates/");
    }
}