List of usage examples for org.springframework.core.io Resource exists
boolean exists();
From source file:com.enonic.cms.business.SitePropertiesServiceImpl.java
private Properties loadSiteProperties(SiteKey siteKey) { Properties siteProperties = new Properties(defaultProperties); siteProperties.setProperty("sitekey", String.valueOf(siteKey)); String relativePathToCmsHome = "/config/site-" + siteKey + ".properties"; try {/*from w w w . java 2s.com*/ String resourcePath = homeService.getHomeDir().getURL() + relativePathToCmsHome; Resource resource = resourceLoader.getResource(resourcePath); boolean useCustomProperties = resource.exists(); if (useCustomProperties) { InputStream stream = resource.getInputStream(); siteProperties.load(stream); siteProperties.setProperty("customSiteProperties", "true"); } } catch (IOException e) { throw new RuntimeException("Failed to load site properties file: " + relativePathToCmsHome, e); } siteProperties.setProperty(SitePropertyNames.URL_DEFAULT_CHARACTER_ENCODING, VerticalProperties.getVerticalProperties().getUrlCharacterEncoding()); sitePropertiesMap.put(siteKey, siteProperties); return siteProperties; }
From source file:no.digipost.api.xml.SchemasTest.java
@Test public void allSchemasExist() throws Exception { for (Field field : Schemas.class.getFields()) { if (isStatic(field.getModifiers()) && Resource.class.isAssignableFrom(field.getType())) { Resource resource = (Resource) field.get(Schemas.class); assertTrue(resource + " must exist! (declared in " + Schemas.class.getName() + "." + field.getName() + ")", resource.exists()); }/*from w w w . j a v a 2 s . c o m*/ } }
From source file:com.wavemaker.tools.project.AbstractStudioFileSystem.java
@Override public Resource getCommonDir() throws IOException { Resource common = getWaveMakerHome().createRelative(COMMON_DIR); if (!common.exists() && getWaveMakerHome().exists()) { createCommonDir(common);//from w w w. j a v a 2 s.c o m } return common; }
From source file:de.perdian.apps.dashboard.mvc.portal.PortalController.java
private Resource computeDashboardFileResource(ServletWebRequest webRequest) throws IOException { String dashboardFileLocation = this.computeDashboardFileLocation(webRequest); Resource dashboardParentResource = this.getResourceLoader() .getResource(PortalConstants.DASHBOARD_RESOURCE_BASE); Resource dashboardFileResource = dashboardParentResource.createRelative(dashboardFileLocation); if (dashboardFileResource != null && dashboardFileResource.exists()) { return dashboardFileResource; } else {/* w ww . j av a 2s . c o m*/ throw new DashboardException("Cannot find requested dashboard file at: " + dashboardFileLocation); } }
From source file:org.carewebframework.api.ManifestIterator.java
/** * Adds the manifest referenced by the specified resource to the list. * /*from www . j a va 2 s . c om*/ * @param resource Resource that references a manifest file. * @return The manifest that was added, or null if not found or an error occurred. */ private Manifest addToList(Resource resource) { try { if (resource != null && resource.exists()) { Manifest manifest = new ManifestEx(resource); manifests.add(manifest); return manifest; } } catch (Exception e) { log.debug("Exception occurred reading manifest.", e); } return null; }
From source file:org.mitre.jose.TestJWKSetKeyStore.java
@Test public void ksEmptyConstructorkLoc() { JWKSetKeyStore ks = new JWKSetKeyStore(); File file = new File(ks_file); Resource loc = new FileSystemResource(file); assertTrue(loc.exists()); assertTrue(loc.isReadable());//from w w w . j a va 2s. c om ks.setLocation(loc); assertEquals(loc.getFilename(), ks.getLocation().getFilename()); }
From source file:org.springmodules.validation.bean.conf.loader.xml.AbstractResourceBasedBeanValidationConfigurationLoader.java
/** * Loads the default validation configuration for the given class, caches it and returns it. The configuration * resource for the given class is resolved by the {@link #createDefaultConfigurationFileName(Class)} method. * * @param clazz The class for which the default configuration should be loaded. * @return The default validation configuration of the given class. *//*from w w w . j a va 2s . c o m*/ protected BeanValidationConfiguration loadDefaultConfiguration(Class clazz) { String fileName = createDefaultConfigurationFileName(clazz); Resource resource = new ClassPathResource(fileName, clazz); if (resource.exists()) { Map configurationByClass = loadConfigurations(resource); this.configurationByClass.putAll(configurationByClass); return (BeanValidationConfiguration) configurationByClass.get(clazz); } logger.warn("Could not find the default validation configuration for class '" + clazz.getName() + "'"); this.configurationByClass.put(clazz, null); return null; }
From source file:springbatch.test.jdbc.datasource.DataSourceInitializer.java
private void doExecuteScript(final Resource scriptResource) { if (scriptResource == null || !scriptResource.exists()) return;/*from w ww. j a va 2 s .c om*/ TransactionTemplate transactionTemplate = new TransactionTemplate( new DataSourceTransactionManager(dataSource)); transactionTemplate.execute(new TransactionCallback() { @SuppressWarnings("unchecked") public Object doInTransaction(TransactionStatus status) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String[] scripts; try { scripts = StringUtils.delimitedListToStringArray( stripComments(IOUtils.readLines(scriptResource.getInputStream())), ";"); } catch (IOException e) { throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e); } for (int i = 0; i < scripts.length; i++) { String script = scripts[i].trim(); if (StringUtils.hasText(script)) { try { jdbcTemplate.execute(scripts[i]); } catch (DataAccessException e) { if (!script.toUpperCase().startsWith("DROP")) { throw e; } } } } return null; } }); }
From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.environment.WindowsFileReadingEnvironmentFactory.java
public Environment create(ConfigResponse config) throws PluginException { try {/* ww w .j ava2s . com*/ Environment environment = new Environment(); Resource wrapperConf = new FileSystemResource( Metric.decode(config.getValue("installpath")) + "/conf/wrapper.conf"); if (wrapperConf.exists()) { environment.setJvmOptions(createJvmOptions(wrapperConf)); environment.setJavaHome(createJavaHome(wrapperConf)); return environment; } return environment; } catch (Exception e) { throw new PluginException( "Unable to read existing tc Runtime configuration. Cause: " + e.getMessage()); } }
From source file:org.pentaho.pat.server.util.JdbcDriverFinder.java
public void afterPropertiesSet() throws Exception { Assert.notNull(jdbcDriverPath);//from ww w . jav a2 s .co m Assert.notNull(resourceLoader); for (String currentPath : this.jdbcDriverPath) { final Resource res = resourceLoader.getResource(currentPath); if (res == null || !res.exists()) { continue; } final File currentFile = res.getFile(); if (!currentFile.isDirectory() || !currentFile.canRead()) { continue; } this.jdbcDriverDirectory.add(currentFile); if (preLoad) { registerDrivers(); } } if (this.jdbcDriverDirectory.size() == 0) { LOG.warn(Messages.getString("Util.JdbcDriverFinder.NoDriversInPath")); //$NON-NLS-1$ } }