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

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

Introduction

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

Prototype

File getFile() throws IOException;

Source Link

Document

Return a File handle for this resource.

Usage

From source file:org.dspace.servicemanager.config.DSpaceDynamicConfigurationService.java

private void loadConfiguration() {
    // now we load the settings from properties files
    String homePath = System.getProperty(DSPACE_HOME);

    // now we load from the provided parameter if its not null
    if (this.home != null && homePath == null) {
        homePath = this.home;
    }//from w w w.ja v  a 2 s .c  om

    if (homePath == null) {
        String catalina = System.getProperty("catalina.base");
        if (catalina == null)
            catalina = System.getProperty("catalina.home");
        if (catalina != null) {
            homePath = catalina + File.separatorChar + DSPACE + File.separatorChar;
        }
    }
    if (homePath == null) {
        homePath = System.getProperty("user.home");
    }
    if (homePath == null) {
        homePath = "/";
    }

    try {
        config = new DSpacePropertiesConfiguration(homePath + File.separatorChar + DSPACE_CONFIG_PATH);
        File modulesDirectory = new File(
                homePath + File.separator + DSPACE_MODULES_CONFIG_PATH + File.separator);
        modulesConfig = new TreeMap<String, DSpacePropertiesConfiguration>();
        if (modulesDirectory.exists()) {
            try {
                Resource[] resources = new PathMatchingResourcePatternResolver()
                        .getResources(modulesDirectory.toURI().toURL().toString() + "*" + DOT_CONFIG);
                if (resources != null) {
                    for (Resource resource : resources) {
                        String prefix = resource.getFilename().substring(0,
                                resource.getFilename().lastIndexOf("."));
                        modulesConfig.put(prefix, new DSpacePropertiesConfiguration(resource.getFile()));
                    }
                }
            } catch (Exception e) {
                log.error("Error while loading the modules properties from:"
                        + modulesDirectory.getAbsolutePath());
            }
        } else {
            log.info("Failed to load the modules properties since (" + homePath + File.separator
                    + DSPACE_MODULES_CONFIG_PATH + "): Does not exist");
        }

    } catch (IllegalArgumentException e) {
        //This happens if we don't have a modules directory
        log.error("Error while loading the module properties since (" + homePath + File.separator
                + DSPACE_MODULES_CONFIG_PATH + "): is not a valid directory", e);
    } catch (ConfigurationException e) {
        // This happens if an error occurs on parsing files
        log.error(
                "Error while loading properties from " + homePath + File.separator + DSPACE_MODULES_CONFIG_PATH,
                e);
    }

    try {
        File addonsDirectory = new File(homePath + File.separator + DSPACE_ADDONS_CONFIG_PATH + File.separator);
        addonsConfig = new TreeMap<String, DSpacePropertiesConfiguration>();
        if (addonsDirectory.exists()) {
            try {
                Resource[] resources = new PathMatchingResourcePatternResolver()
                        .getResources(addonsDirectory.toURI().toURL().toString() + "*" + DOT_CONFIG);
                if (resources != null) {
                    for (Resource resource : resources) {
                        String prefix = resource.getFilename().substring(0,
                                resource.getFilename().lastIndexOf("."));
                        addonsConfig.put(prefix, new DSpacePropertiesConfiguration(resource.getFile()));
                    }
                }
            } catch (Exception e) {
                log.error(
                        "Error while loading the addons properties from:" + addonsDirectory.getAbsolutePath());
            }
        } else {
            log.info("Failed to load the addons properties since (" + homePath + File.separator
                    + DSPACE_ADDONS_CONFIG_PATH + "): Does not exist");
        }

    } catch (IllegalArgumentException e) {
        //This happens if we don't have a modules directory
        log.error("Error while loading the module properties since (" + homePath + File.separator
                + DSPACE_ADDONS_CONFIG_PATH + "): is not a valid directory", e);
    }
}

From source file:org.emonocot.harvest.common.MultiResourceDeletingTasklet.java

/**
 * @param contribution Set the step contribution
 * @param chunkContext Set the chunk context
 * @return the repeat status//from   w w w  . j  av  a2 s . c  om
 * @throws Exception if there is a problem deleting the resources
 */
public final RepeatStatus execute(final StepContribution contribution, final ChunkContext chunkContext)
        throws Exception {
    for (Resource lResource : resources) {
        FileSystemResource lFileSystemResource = new FileSystemResource(lResource.getFile().getAbsolutePath());
        if (!lFileSystemResource.exists()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Resource " + lFileSystemResource.getDescription()
                        + " does not exist. The resource is ignored");
            }
        } else {
            File lFile = lFileSystemResource.getFile();
            if (lFile.isDirectory()) {
                // supprime le rpertoire et son contenu
                FileUtils.deleteDirectory(lFile);
            } else {
                if (!lFile.delete()) {
                    throw new IOException("The file " + lFile + " cannot be deleted.");
                }
            }
        }
    }
    return RepeatStatus.FINISHED;
}

From source file:org.encuestame.core.test.config.XmlConfigurationText.java

/**
 * @throws ConfigurationException//from w  ww  .  j  av  a  2 s .  c o  m
 *
 */
@Test
public void testXmlFile() {
    // final ConfigurationManager configurationManager = new
    // ConfigurationManager("encuestame-config.xml");
    // System.out.println(configurationManager.getIntProperty("encuestame.database.version"));
    XMLConfiguration xmlConfiguration = null;
    try {
        Resource res = new ClassPathResource("properties-test/encuestame-test-config.xml");
        // System.out.println(res.getFilename());
        // System.out.println(res.getFile().getAbsolutePath());
        xmlConfiguration = new XMLConfiguration(res.getFile());
        // System.out.println(xmlConfiguration.getString("encuestame.database.version"));
        // System.out.println(xmlConfiguration.getString("database.version"));
        xmlConfiguration.setAutoSave(true);
        xmlConfiguration.addProperty("juan", "juan");

        // System.out.println(xmlConfiguration.getString("administration"));
        // System.out.println(xmlConfiguration.getString("version"));

        // System.out.println(xmlConfiguration.getRootElementName());
        // System.out.println(xmlConfiguration.getKeys());
        final Iterator i = xmlConfiguration.getKeys();
        while (i.hasNext()) {
            Object object = (Object) i.next();
            //System.out.println(object);
        }

        // System.out.println(xmlConfiguration.getList("social-networks.social-network.social-network-name"));
        // System.out.println(xmlConfiguration.getList("social-networks.social-network.social-network-name").size());
        // System.out.println(xmlConfiguration.getList("social-networks"));
        // System.out.println(xmlConfiguration.getList("social-networks").size());

        List fields = xmlConfiguration.configurationsAt("tables.table(0).fields.field");
        for (Iterator it = fields.iterator(); it.hasNext();) {
            HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
            // sub contains all data about a single field
            String fieldName = sub.getString("name");
            String fieldType = sub.getString("type");
        }

    } catch (ConfigurationException e) {

        e.printStackTrace();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        //e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.fao.fenix.ftp.FTPTask.java

public FTPTask(Resource resource) throws FenixSystemException {
    try {//from  w  w w  . j av  a 2  s .c o m
        System.out.println("=== amis-ftp === FTPTask: == INFO == resource.getFile().getPath() ..."
                + resource.getFile().getPath());
        System.out.println(resource.getFile().getPath());

        this.setPath(resource.getFile().getPath());
    } catch (IOException e) {
        throw new FenixSystemException(e.getMessage());
    }
}

From source file:org.fao.fenix.web.modules.latex.server.LatexServiceImpl.java

public LatexServiceImpl(Resource resource) {
    try {/*from  w w w.  j  a va 2  s  .  co  m*/
        setDir(resource.getFile());
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.globus.workspace.accounting.impls.dbdefault.DBAccountingAdapter.java

public void setCurrentReservationsResource(Resource currentReservationsResource) throws IOException {
    this.currentReservationsPath = currentReservationsResource.getFile().getAbsolutePath();
}

From source file:org.globus.workspace.accounting.impls.dbdefault.DBAccountingAdapter.java

public void setEventsResource(Resource eventsResource) throws IOException {
    this.eventsPath = eventsResource.getFile().getAbsolutePath();
}

From source file:org.globus.workspace.remoting.RemotingClient.java

public void setSocketResource(Resource socketResource) throws IOException {
    this.socketDirectory = socketResource.getFile();
}

From source file:org.globus.workspace.scheduler.defaults.pilot.PilotSlotManagement.java

public void setAccountsResource(Resource accountsResource) throws IOException {
    this.accountsPath = accountsResource.getFile().getAbsolutePath();
}

From source file:org.globus.workspace.scheduler.defaults.pilot.PilotSlotManagement.java

public void setPollScriptResource(Resource pollScriptResource) throws IOException {
    this.pollScript = pollScriptResource.getFile().getAbsolutePath();
}