Example usage for org.springframework.core.io FileSystemResource FileSystemResource

List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource

Introduction

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

Prototype

public FileSystemResource(Path filePath) 

Source Link

Document

Create a new FileSystemResource from a Path handle, performing all file system interactions via NIO.2 instead of File .

Usage

From source file:com.wavemaker.tools.project.upgrade.swamis.PanesRenameUpgradeTest.java

public void testUpgradeEmpty() throws Exception {

    File root = IOUtils.createTempDirectory("testUpgrade", "_dir");

    Project p = new Project(new FileSystemResource(root.getAbsolutePath() + "/"), new LocalStudioFileSystem());
    p.getWebAppRoot().getFile().mkdir();
    File panes = new File(p.getWebAppRoot().getFile(), "panes");
    File pages = new File(p.getWebAppRoot().getFile(), ProjectConstants.PAGES_DIR);
    assertFalse(pages.exists());/*from  w w  w  . jav a  2 s.  co m*/

    PanesRenameUpgrade pru = new PanesRenameUpgrade();
    pru.doUpgrade(p, new UpgradeInfo());

    assertFalse(pages.exists());
    assertFalse(panes.exists());
}

From source file:io.gravitee.repository.ehcache.cache.EhCacheRepositoryConfiguration.java

@Bean
public EhCacheManagerFactoryBean getEhCacheFactory() {
    String graviteeHome = System.getProperty("gravitee.home");
    String ehCacheConfiguration = graviteeHome + File.separator + "config" + File.separator + "ehcache.xml";
    File ehCacheConfigurationFile = new File(ehCacheConfiguration);

    LOGGER.info("Loading EHCache configuration from {}", ehCacheConfiguration);

    if (!ehCacheConfigurationFile.exists()) {
        LOGGER.warn("No configuration file can be found for EHCache");
        throw new IllegalStateException("No configuration file can be found for EHCache");
    }/*  w w  w .ja v a 2  s .co  m*/

    EhCacheManagerFactoryBean factoryBean = new EhCacheManagerFactoryBean();
    factoryBean.setConfigLocation(new FileSystemResource(ehCacheConfigurationFile));
    factoryBean.setShared(true);
    return factoryBean;
}

From source file:me.springframework.di.spring.SpringConfigurationLoaderTest.java

public void testLoadMaps() {
    Resource resource = new FileSystemResource(getFile("src/test/resources/context3.xml"));
    SpringConfigurationLoader loader = new SpringConfigurationLoader();
    Configuration configuration = loader.load(resource);
    assertNotNull(configuration.getMapSources());
    assertNotNull(configuration.getPublicInstances());
    assertEquals(1, configuration.getMapSources().size());
    assertEquals(1, configuration.getPublicInstances().size());
    MapSource source = configuration.getMapSources().iterator().next();
    assertEquals(2, source.getEntries().size());

    // Check that the keys are of the proper type
    assertTrue(source.getEntries().get(0).getKey() instanceof LiteralSource);
    assertTrue(source.getEntries().get(1).getKey() instanceof LiteralSource);

    // Check that the values are of the proper type
    assertTrue(source.getEntries().get(0).getValue() instanceof Instance);
    assertTrue(source.getEntries().get(1).getValue() instanceof Instance);

    // Check that the values are set correctly
    assertEquals("coding", ((LiteralSource) source.getEntries().get(0).getKey()).getValue());
    assertEquals("modeling", ((LiteralSource) source.getEntries().get(1).getKey()).getValue());

    // Check that the bean properties are set correctly
    assertHasStringProperty(source.getEntries().get(0).getValue(), "topic", "C++");
    assertHasStringProperty(source.getEntries().get(1).getValue(), "topic", "UML");
}

From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerConfigurerTests.java

public void testFreemarkerConfigurationFactoryBeanWithConfigLocation() throws TemplateException {
    FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
    fcfb.setConfigLocation(new FileSystemResource("myprops.properties"));
    Properties props = new Properties();
    props.setProperty("myprop", "/mydir");
    fcfb.setFreemarkerSettings(props);//from  w  w  w  .jav  a 2s  . c om
    try {
        fcfb.afterPropertiesSet();
        fail("Should have thrown IOException");
    } catch (IOException ex) {
        // expected
    }
}

From source file:com.operalot.validator.util.OverridablePropertyPlaceholderConfigurer.java

@Override
public void setLocation(Resource location) {
    if (StringUtils.isBlank(getSystemPropertyName())) {
        throw new IllegalArgumentException("Missing value for 'systemPropertyName'.");
    }/*from   w  ww  .ja v a  2 s . c  o m*/
    Resource locationResource;
    final String overrideProperty = System.getProperty(getSystemPropertyName());

    if (StringUtils.isBlank(overrideProperty)) {
        locationResource = location;
    } else if (overrideProperty.startsWith(CLASSPATH)) {
        locationResource = new ClassPathResource(overrideProperty.substring(CLASSPATH.length()));
    } else {
        locationResource = new FileSystemResource(overrideProperty);
    }
    super.setLocation(locationResource);
}

From source file:nu.yona.server.rest.StandardResourcesController.java

@RequestMapping(value = "/vpn/profile.ovpn", method = RequestMethod.GET, produces = {
        "application/x-openvpn-profile" })
@ResponseBody//from  w w  w .  j  a  va  2 s .  c  o m
public FileSystemResource getOvpnProfile() {
    return new FileSystemResource(yonaProperties.getSecurity().getOvpnProfileFile());
}

From source file:org.cagrid.identifiers.namingauthority.util.SecurityUtil.java

public static void addAdmin(String naConfigurationFile, String naProperties, String adminUser)

        throws InvalidIdentifierException, URISyntaxException, NamingAuthorityConfigurationException,
        NamingAuthoritySecurityException, InvalidIdentifierValuesException {

    FileSystemResource naConfResource = new FileSystemResource(naConfigurationFile);
    FileSystemResource naPropertiesResource = new FileSystemResource(naProperties);

    XmlBeanFactory factory = new XmlBeanFactory(naConfResource);
    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setLocation(naPropertiesResource);
    cfg.postProcessBeanFactory(factory);

    NamingAuthorityImpl na = (NamingAuthorityImpl) factory.getBean("NamingAuthority",
            MaintainerNamingAuthority.class);
    na.getIdentifierDao().createInitialAdministrator(adminUser);

    //        KeyData kd = na.getKeyData(null, na.getSystemIdentifier(), Keys.ADMIN_USERS);
    //        if (kd == null) {
    //           System.err.println("KD IS NULL");
    //           kd = new KeyData();
    //        }/*  w  ww . j a  v a2s  .  c om*/
    //        
    //        List<String> values = kd.getValues();
    //        if (values == null) {
    //           System.err.println("VALUES IS NULL");
    //           values = new ArrayList<String>();
    //        }
    //        
    //        if (values.contains(adminUser)) {
    //           throw new NamingAuthorityConfigurationException("Provided identity [" + adminUser + "] is already an administrator");
    //        }
    //        
    //        values.add(adminUser);
    //        
    //        IdentifierValues ivalues = new IdentifierValues();
    //        ivalues.put(Keys.ADMIN_USERS, kd);
    //        na.replaceKeys(null, na.getSystemIdentifier(), ivalues);
}

From source file:nl.knaw.dans.common.lang.spring.HomeDirectoryBasedPropertyPlaceholderConfigurer.java

public HomeDirectoryBasedPropertyPlaceholderConfigurer(final HomeDirectory homedir) {
    final File file = new File(homedir.getHomeDirectory(), "cfg/application.properties");
    if (!file.exists()) {
        String m = MessageFormatter.format("Cannot find application properties at {}", file).getMessage();
        log.error(m);//from  w  w  w. ja  va 2s . c  om
        throw new RuntimeException(m);
    }
    if (!file.isFile()) {
        String m = MessageFormatter
                .format("Application properites file {} exists, but is not a regular file", file).getMessage();
        log.error(m);
        throw new RuntimeException(m);

    }
    setLocation(new FileSystemResource(file));
}

From source file:de.langmi.spring.batch.examples.playground.file.multiresourcepartitioner.FiltersFoldersMultiResourcePartitioner.java

/**
 * Runs recursively through the rootFile.listFiles() and adds each file to the 
 * fileList.//  w w w  .j  a  va2  s.  c o  m
 * 
 * @param rootFile
 * @param fileList 
 * @param filenameFilter
 */
private static void runNestedDirs(File rootFile, List<FileSystemResource> fileList,
        FilenameFilter filenameFilter) {
    File files[] = rootFile.listFiles(filenameFilter);
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            if (file.isDirectory()) {
                runNestedDirs(file, fileList, filenameFilter);
            } else {
                LOG.debug("adding:" + file.getName());
                fileList.add(new FileSystemResource(file));
            }
        }
    }
}

From source file:edu.usf.cutr.fdot7.io.IndividualCsvEntityReader.java

public IndividualCsvEntityReader(String entity) {
    _entity = entity;/*www. j  a  v  a2 s. com*/
    BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
            System.getProperty("user.dir") + System.getProperty("file.separator") + "data-source.xml"));
    fdSchema = (FdotSchemaImpl) factory.getBean(_entity);
    if (_entity.equals("shapes")) {
        data = new ShapeGtfsData(_entity);
    } else {
        data = new GenericGtfsDataImpl(_entity);
    }
}