List of usage examples for org.springframework.core.io Resource isReadable
default boolean isReadable()
From source file:org.broadleafcommerce.common.web.resource.AbstractGeneratedResourceHandler.java
/** * This method can be used to read in a resource given a path and at least one resource location * //w w w .j ava 2 s . c o m * @param path * @param locations * @return the resource from the file system, classpath, etc, if it exists */ protected Resource getRawResource(String path, List<Resource> locations) { ExtensionResultHolder erh = new ExtensionResultHolder(); extensionManager.getProxy().getOverrideResource(path, erh); if (erh.getContextMap().get(ResourceRequestExtensionHandler.RESOURCE_ATTR) != null) { return (Resource) erh.getContextMap().get(ResourceRequestExtensionHandler.RESOURCE_ATTR); } for (Resource location : locations) { try { Resource resource = location.createRelative(path); if (resource.exists() && resource.isReadable()) { return resource; } } catch (IOException ex) { LOG.debug("Failed to create relative resource - trying next resource location", ex); } } return null; }
From source file:org.finra.herd.swaggergen.RestControllerProcessor.java
/** * Finds all the REST controllers within the configured REST Java package and process the REST methods within each one. * * @throws MojoExecutionException if any errors were encountered. *//*ww w .j ava2 s . c o m*/ private void findAndProcessRestControllers() throws MojoExecutionException { try { log.debug("Finding and processing REST controllers."); // Loop through each resources and process each one. for (Resource resource : ResourceUtils.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + restJavaPackage.replace('.', '/') + "/**/*.java")) { if (resource.isReadable()) { JavaClassSource javaClassSource = Roaster.parse(JavaClassSource.class, resource.getInputStream()); sourceMap.put(javaClassSource.getName(), javaClassSource); log.debug("Found Java source class \"" + javaClassSource.getName() + "\"."); } } // Loop through each controller resources and process each one. for (Resource resource : ResourceUtils .getResources( ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath( SystemPropertyUtils.resolvePlaceholders(restJavaPackage)) + "/**/*.class")) { if (resource.isReadable()) { // Create a resource resolver to fetch resources. MetadataReader metadataReader = new CachingMetadataReaderFactory( new PathMatchingResourcePatternResolver()).getMetadataReader(resource); Class<?> clazz = Class.forName(metadataReader.getClassMetadata().getClassName()); processRestControllerClass(clazz); } } } catch (ClassNotFoundException | IOException e) { throw new MojoExecutionException("Error processing REST classes. Reason: " + e.getMessage(), e); } }
From source file:org.jahia.services.importexport.DocumentViewImportHandler.java
@SuppressWarnings("unchecked") public DocumentViewImportHandler(JCRSessionWrapper session, String rootPath, Resource archive, List<String> fileList) throws IOException { super(session); JCRNodeWrapper node = null;/*from w ww. j a v a2s . c om*/ try { this.uuidMapping = session.getUuidMapping(); this.pathMapping = session.getPathMapping(); if (rootPath == null) { node = (JCRNodeWrapper) session.getRootNode(); } else { node = (JCRNodeWrapper) session.getNode(rootPath); } } catch (RepositoryException e) { logger.error(e.getMessage() + getLocation(), e); throw new IOException(); } nodes.add(node); this.archive = archive; if (archive != null && !archive.isReadable() && archive instanceof FileSystemResource) { expandImportedFilesOnDiskPath = archive.getFile().getPath(); expandImportedFilesOnDisk = true; } this.fileList = fileList; setPropertiesToSkip( (Set<String>) SpringContextSingleton.getBean("DocumentViewImportHandler.propertiesToSkip")); }
From source file:org.jahia.services.importexport.ImportExportBaseService.java
private ZipInputStream getZipInputStream(Resource file) throws IOException { ZipInputStream zis;/* w ww.j av a 2 s . co m*/ if (!file.isReadable() && file instanceof FileSystemResource) { zis = new DirectoryZipInputStream(file.getFile()); } else { zis = new NoCloseZipInputStream(new BufferedInputStream(file.getInputStream())); } return zis; }
From source file:org.kuali.rice.krad.datadictionary.parse.CustomTagAnnotations.java
/** * Finds all the classes which have a BeanTag or BeanTags annotation * * @param basePackage the package to start in * @return classes which have BeanTag or BeanTags annotation * @throws IOException/* w ww .j a va 2 s.com*/ * @throws ClassNotFoundException */ protected static List<Class<?>> findTagClasses(String basePackage) throws IOException, ClassNotFoundException { ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver); List<Class<?>> classes = new ArrayList<Class<?>>(); String resolvedBasePackage = ClassUtils .convertClassNameToResourcePath(SystemPropertyUtils.resolvePlaceholders(basePackage)); String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolvedBasePackage + "/" + "**/*.class"; Resource[] resources = resourcePatternResolver.getResources(packageSearchPath); for (Resource resource : resources) { if (resource.isReadable()) { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); if (metadataReader != null && isBeanTag(metadataReader)) { classes.add(Class.forName(metadataReader.getClassMetadata().getClassName())); } } } return classes; }
From source file:org.libreplan.web.common.entrypoints.RedirectorSynthetiser.java
private void addIfSuitable(List<Class<?>> accumulatedResult, CachingMetadataReaderFactory metadataReaderFactory, Resource resource) { try {//from ww w . j av a 2 s . co m if (resource.isReadable()) { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); ClassMetadata classMetadata = metadataReader.getClassMetadata(); if (classMetadata.isInterface() && annotationMetadata.getAnnotationTypes().contains(EntryPoints.class.getName())) { Class<?> klass = Class.forName(classMetadata.getClassName()); if (klass.isInterface()) { accumulatedResult.add(klass); } } } } catch (Exception e) { LOG.warn("exception processing " + resource, e); } }
From source file:org.mifos.reports.MifosViewerServletContextListener.java
private void copyFromClassPathToDirectory(String directoryToScan, File rootDirectory) throws IOException { ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] resources = resolver.getResources(LOCATION_PATTERN); LOGGER.info("Found " + resources.length + " Resources on " + LOCATION_PATTERN); for (Resource resource : resources) { if (resource.exists() & resource.isReadable() && resource.contentLength() > 0) { URL url = resource.getURL(); String urlString = url.toExternalForm(); String targetName = urlString.substring(urlString.indexOf(directoryToScan)); File destination = new File(rootDirectory, targetName); FileUtils.copyURLToFile(url, destination); LOGGER.info("Copied " + url + " to " + destination.getAbsolutePath()); } else {//from w ww . ja v a 2 s. c o m LOGGER.debug("Did not copy, seems to be directory: " + resource.getDescription()); } } }
From source file:org.openehealth.ipf.commons.map.config.CustomMappings.java
public void setMappingScripts(Collection<Resource> mappingScripts) { this.mappingScripts = new ArrayList<Resource>(mappingScripts.size()); for (Resource mappingScript : mappingScripts) { if (mappingScript.exists() && mappingScript.isReadable()) { this.mappingScripts.add(mappingScript); } else {/*from w ww . ja va 2 s.c o m*/ LOG.warn("Could not read mapping script " + mappingScript.getFilename()); } } this.mappingScripts = mappingScripts; }
From source file:org.openehealth.ipf.commons.map.config.CustomMappings.java
public void setMappingScript(Resource mappingScript) { if (mappingScript.exists() && mappingScript.isReadable()) { this.mappingScript = mappingScript; } else {//w ww. j a v a2 s .c o m LOG.warn("Could not read mapping script " + mappingScript.getFilename()); } }
From source file:org.springframework.boot.actuate.endpoint.web.LogFileWebEndpoint.java
@ReadOperation public Resource logFile() { Resource logFileResource = getLogFileResource(); if (logFileResource == null || !logFileResource.isReadable()) { return null; }//w ww .ja v a 2 s . c o m return logFileResource; }