List of usage examples for org.springframework.core.io Resource exists
boolean exists();
From source file:org.springframework.web.multipart.commons.CommonsFileUploadSupport.java
/** * Set the temporary directory where uploaded files get stored. * Default is the servlet container's temporary directory for the web application. * @see org.springframework.web.util.WebUtils#TEMP_DIR_CONTEXT_ATTRIBUTE *///from w w w . j a v a 2s .c o m public void setUploadTempDir(Resource uploadTempDir) throws IOException { if (!uploadTempDir.exists() && !uploadTempDir.getFile().mkdirs()) { throw new IllegalArgumentException("Given uploadTempDir [" + uploadTempDir + "] could not be created"); } this.fileItemFactory.setRepository(uploadTempDir.getFile()); this.uploadTempDirSpecified = true; }
From source file:org.springframework.web.multipart.cos.CosMultipartResolver.java
/** * Set the temporary directory where uploaded files get stored. * Default is the servlet container's temporary directory for the web application. * @see org.springframework.web.util.WebUtils#TEMP_DIR_CONTEXT_ATTRIBUTE *//* w ww . ja v a2 s . c o m*/ public void setUploadTempDir(Resource uploadTempDir) throws IOException { if (!uploadTempDir.exists() && !uploadTempDir.getFile().mkdirs()) { throw new IllegalArgumentException("Given uploadTempDir [" + uploadTempDir + "] could not be created"); } this.uploadTempDir = uploadTempDir.getFile(); }
From source file:org.springframework.web.servlet.resource.GzipResourceResolver.java
@Override public Resource resolveResource(HttpServletRequest request, String requestPath, List<Resource> locations, ResourceResolverChain chain) {/*from ww w . ja v a2s . co m*/ Resource resource = chain.resolveResource(request, requestPath, locations); if ((resource == null) || !isGzipAccepted(request)) { return resource; } try { Resource gzipped = new GzippedResource(resource); if (gzipped.exists()) { return gzipped; } } catch (IOException e) { logger.trace("No gzipped resource for [" + resource.getFilename() + "]", e); } return resource; }
From source file:org.springframework.web.servlet.resource.PathResourceResolver.java
private Resource getResource(String path, List<? extends Resource> locations) { for (Resource location : locations) { try {/*from w ww .j a v a 2 s .c o m*/ if (logger.isTraceEnabled()) { logger.trace("Checking location=[" + location + "]"); } Resource resource = location.createRelative(path); if (resource.exists() && resource.isReadable()) { if (logger.isTraceEnabled()) { logger.trace("Found match"); } return resource; } else if (logger.isTraceEnabled()) { logger.trace("No match"); } } catch (IOException ex) { logger.trace("Failure checking for relative resource. Trying next location.", ex); } } return null; }
From source file:org.springframework.xd.dirt.plugins.job.support.listener.FileDeletionStepExecutionListener.java
private void deleteResources() { for (Resource r : resources) { if (r.exists()) { try { r.getFile().delete();/*w w w.ja v a2s . c om*/ } catch (IOException e) { logger.error("Failed to delete " + r, e); } } } }
From source file:org.springframework.xml.validation.XmlValidatorFactory.java
/** * Create a {@link XmlValidator} with the given schema resources and schema language type. The schema language must * be one of the <code>SCHEMA_XXX</code> constants. * * @param schemaResources an array of resource that locate the schemas to validate against * @param schemaLanguage the language of the schemas * @return a validator/*w w w .j a v a 2 s . c om*/ * @throws IOException if the schema resource cannot be read * @throws IllegalArgumentException if the schema language is not supported * @throws IllegalStateException if JAXP 1.0 cannot be located * @throws XmlValidationException if a <code>XmlValidator</code> cannot be created * @see #SCHEMA_RELAX_NG * @see #SCHEMA_W3C_XML */ public static XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws IOException { Assert.notEmpty(schemaResources, "No resources given"); Assert.hasLength(schemaLanguage, "No schema language provided"); Assert.isTrue(SCHEMA_W3C_XML.equals(schemaLanguage) || SCHEMA_RELAX_NG.equals(schemaLanguage), "Invalid schema language: " + schemaLanguage); for (Resource schemaResource : schemaResources) { Assert.isTrue(schemaResource.exists(), "schema [" + schemaResource + "] does not exist"); } if (JaxpVersion.getJaxpVersion() >= JaxpVersion.JAXP_13) { logger.trace("Creating JAXP 1.3 XmlValidator"); return Jaxp13ValidatorFactory.createValidator(schemaResources, schemaLanguage); } else { throw new IllegalStateException("Could not locate JAXP 1.3."); } }
From source file:org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection.java
public void afterPropertiesSet() throws IOException { Assert.notEmpty(xsdResources, "'xsds' must not be empty"); schemaCollection.setSchemaResolver(uriResolver); Set<XmlSchema> processedIncludes = new HashSet<XmlSchema>(); Set<XmlSchema> processedImports = new HashSet<XmlSchema>(); for (Resource xsdResource : xsdResources) { Assert.isTrue(xsdResource.exists(), xsdResource + " does not exit"); try {//from w w w. ja v a2s. c om XmlSchema xmlSchema = schemaCollection.read(SaxUtils.createInputSource(xsdResource)); xmlSchemas.add(xmlSchema); if (inline) { inlineIncludes(xmlSchema, processedIncludes, processedImports); findImports(xmlSchema, processedImports, processedIncludes); } } catch (Exception ex) { throw new CommonsXsdSchemaException("Schema [" + xsdResource + "] could not be loaded", ex); } } if (logger.isInfoEnabled()) { logger.info("Loaded " + StringUtils.arrayToCommaDelimitedString(xsdResources)); } }
From source file:org.squashtest.tm.web.internal.context.ReloadableSquashTmMessageSource.java
private void addPluginBasenames(Set<String> consolidatedBasenames) throws IOException { Resource[] resources = resourcePatternResolver .getResources("classpath*:org/squashtest/tm/plugin/**/messages.properties"); for (Resource resource : resources) { try {//from ww w. j a v a 2 s . c om if (resource.exists()) { // resource path is external-path/jar-name.jar!/internal-path/messages.properties String path = resource.getURL().getPath(); int bang = path.lastIndexOf('!'); String basename = "classpath:" + StringUtils.removeEnd(path.substring(bang + 2), ".properties"); consolidatedBasenames.add(basename); LOGGER.info( "Registering *discovered* plugin classpath path {} as a basename for application MessageSource", basename); } } catch (IOException e) { LOGGER.info("An IO error occurred while looking up plugin language resources '{}': {}", resource, e.getMessage()); LOGGER.debug("Plugin language resources lookup error for resource {}", resource, e); } } }
From source file:org.squashtest.tm.web.internal.context.ReloadableSquashTmMessageSource.java
private void addExternalBasenames(Set<String> consolidatedBasenames) { String locationPattern = squashPathProperties.getLanguagesPath() + "/**/messages.properties"; if (!locationPattern.startsWith("file:")) { locationPattern = "file:" + locationPattern; }//from w w w.j a va 2s .c o m try { Resource[] resources = resourcePatternResolver.getResources(locationPattern); for (Resource resource : resources) { if (resource.exists()) { String basename = StringUtils.removeEnd(resource.getURL().getPath(), ".properties"); consolidatedBasenames.add(basename); LOGGER.info( "Registering *discovered* external path {} as a basename for application MessageSource", basename); } } } catch (IOException e) { LOGGER.info("An IO error occurred while looking up external language resources '{}' : {}", locationPattern, e.getMessage()); LOGGER.debug("External language lookup error. Current path : {}", new File(".").toString(), e); } }
From source file:org.squashtest.tm.web.internal.context.ReloadableSquashTmMessageSource.java
private boolean isFirstLevelDirectory(Resource resource) throws IOException { if (!resource.exists()) { return false; }//from w w w.j av a 2s .c o m // in runtime env we do not work with file (exception) so we have to use URLs URL url = resource.getURL(); return url.getPath().endsWith(MESSAGES_BASE_PATH + resource.getFilename() + '/'); }