List of usage examples for org.springframework.core.io Resource getFilename
@Nullable String getFilename();
From source file:com.civilizer.web.handler.ResourceHttpRequestHandler.java
/** * Determine an appropriate media type for the given resource. * @param resource the resource to check * @return the corresponding media type, or {@code null} if none found *///from w w w. j av a 2 s . c om protected MediaType getMediaType(Resource resource) { MediaType mediaType = null; String mimeType = getServletContext().getMimeType(resource.getFilename()); if (StringUtils.hasText(mimeType)) { mediaType = MediaType.parseMediaType(mimeType); } if (jafPresent && (mediaType == null || MediaType.APPLICATION_OCTET_STREAM.equals(mediaType))) { MediaType jafMediaType = ActivationMediaTypeFactory.getMediaType(resource.getFilename()); if (jafMediaType != null && !MediaType.APPLICATION_OCTET_STREAM.equals(jafMediaType)) { mediaType = jafMediaType; } } return mediaType; }
From source file:org.solmix.runtime.cm.support.SpringConfigureUnitManager.java
protected Properties loadProperties(Resource location) { Properties props = new Properties(); InputStream is = null;// w w w. jav a 2 s . c om try { is = location.getInputStream(); String filename = location.getFilename(); if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) { this.propertiesPersister.loadFromXml(props, is); } else { if (this.fileEncoding != null) { this.propertiesPersister.load(props, new InputStreamReader(is, this.fileEncoding)); } else { this.propertiesPersister.load(props, is); } } } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not load properties from " + location + ": " + ex.getMessage()); } } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } checkSystemProperties(props); return props; }
From source file:se.ivankrizsan.messagecowboy.services.transport.AbstractXmlConfigurerdTransportService.java
/** * Retrieves configuration resource information for the currently configured * XML configuration resources./*from w w w. j a va2s. c om*/ * * @return List of configuration resource information. * @throws IOException If error occurs discovering or accessing configuration resource. */ protected List<XmlConfigurationResourceInfo> retrieveXmlConfigResourceInfos() throws IOException { final PathMatchingResourcePatternResolver theConnectorsResolver = new PathMatchingResourcePatternResolver(); final List<XmlConfigurationResourceInfo> theConfigRsrcInfos = new ArrayList<XmlConfigurationResourceInfo>(); for (String theConfigRsrcsLocationPattern : mConfigResourcesLocationPatterns) { final Resource[] theConnectorsConfigurations = theConnectorsResolver .getResources(theConfigRsrcsLocationPattern); LOGGER.debug("Found {} connector configuration files using the pattern {}", theConnectorsConfigurations.length, theConfigRsrcsLocationPattern); if (theConnectorsConfigurations.length > 0) { for (Resource theResource : theConnectorsConfigurations) { final byte[] theConfigRsrcContents = FileCopyUtils .copyToByteArray(theResource.getInputStream()); final String theConfigRsrcName = theResource.getFilename(); final String theConfigRsrcChecksum = DigestUtils.md5Hex(theConfigRsrcContents); final XmlConfigurationResourceInfo theConfigRsrcInfo = new XmlConfigurationResourceInfo( theConfigRsrcName, theConfigRsrcChecksum); theConfigRsrcInfos.add(theConfigRsrcInfo); } } } return theConfigRsrcInfos; }
From source file:com.bluexml.side.framework.alfresco.commons.configurations.PropertiesConfiguration.java
protected void loadResource(Resource r) { if (r.exists()) { Properties properties = new Properties(); try {/*from ww w . ja v a 2s . co m*/ properties.load(r.getInputStream()); logger.info("Load Properties form Resource " + r); } catch (IOException e) { logger.error("Unexpected error loading property file \"" + r.getFilename() + "\" ", e); } if (isValidePropertiesResource(properties)) { for (Object property : properties.keySet()) { String key = (String) property; String value = (String) properties.getProperty(key); dictionary.put(key, value); } } } else { logger.info("Resource do not exists :" + r.getDescription()); } }
From source file:net.sf.springderby.ExecuteSqlScriptsAction.java
public Object doInConnection(Connection connection) throws SQLException, DataAccessException { for (Resource resource : scripts) { try {// ww w .j av a 2 s . c o m sqlScriptExecutionSupport.getSqlScriptExecutor().executeScript(connection, resource, encoding); } catch (IOException ex) { // TODO: this exception is no longer appropriate throw new SchemaCreationException("Failed to read script " + resource.getFilename(), ex); } } return null; }
From source file:jails.http.converter.FormHttpMessageConverter.java
/** * Return the filename of the given multipart part. This value will be used for the {@code Content-Disposition} header. * <p>Default implementation returns {@link Resource#getFilename()} if the part is a {@code Resource}, and * {@code null} in other cases. Can be overridden in subclasses. * @param part the part to determine the file name for * @return the filename, or {@code null} if not known *///from w w w . j av a 2 s . c om protected String getFilename(Object part) { if (part instanceof Resource) { Resource resource = (Resource) part; return resource.getFilename(); } else { return null; } }
From source file:com.wooki.services.ImportServiceImpl.java
public Book importApt(Resource apt) { try {/*from w w w .jav a 2 s .c o m*/ String from = "apt"; File out = File.createTempFile("fromAptToXHTML", ".html"); String to = "html"; Converter converter = new DefaultConverter(); InputFileWrapper input = InputFileWrapper.valueOf(apt.getFilename(), from, "ISO-8859-1", converter.getInputFormats()); OutputFileWrapper output = OutputFileWrapper.valueOf(out.getAbsolutePath(), to, "UTF-8", converter.getOutputFormats()); converter.convert(input, output); return importDocbook(fromAptToDocbook.performTransformation(new FileSystemResource(out))); } catch (UnsupportedFormatException e) { e.printStackTrace(); } catch (ConverterException e) { e.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return null; }
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.registry.VersionRegisterableScriptClasspathScanner.java
/** * Matches and processes an actual source file * * @param resourcePattern/* www . ja v a 2 s . c om*/ * the resource pattern for the current level * @param patternStack * the stack of patterns evaluated thus far * @param versionDataContainer * the container for collection version information * @param subRegistry * the sub-registry to register the script in or {@code null} if no sub-registry is to be used * @param resource * the resource representing the source file * @throws IOException * if any exception occurs handling the resource */ protected void matchSourceFile(final String resourcePattern, final Collection<String> patternStack, final VersionRegisterableScriptAdapter<Script> versionDataContainer, final String subRegistry, final Resource resource) throws IOException { final String scriptName = resource.getFilename(); final String simpleScriptName = scriptName.endsWith(".js") ? scriptName.substring(0, scriptName.length() - 3) : scriptName; LOGGER.debug("Matched script file {}", scriptName); final RegisterableScript<Script> script = this.getScript(resourcePattern + "/" + scriptName); if (script != null) { // copy the script adapter final VersionRegisterableScriptAdapter<Script> scriptAdapter = new VersionRegisterableScriptAdapter<Script>(); scriptAdapter.setForCommunity(versionDataContainer.isForCommunity()); scriptAdapter.setAppliesFrom(versionDataContainer.getAppliesFrom()); scriptAdapter.setAppliesTo(versionDataContainer.getAppliesTo()); scriptAdapter.setAppliesFromExclusive(versionDataContainer.isAppliesFromExclusive()); scriptAdapter.setAppliesToExclusive(versionDataContainer.isAppliesToExclusive()); scriptAdapter.setVersion(versionDataContainer.getVersion()); scriptAdapter.setAdaptedScript(script); if (subRegistry == null || subRegistry.trim().length() == 0) { this.scriptRegistry.registerScript(simpleScriptName, scriptAdapter); LOGGER.debug("Registered script {} into script registry {}", scriptAdapter, this.scriptRegistry); } else { this.scriptRegistry.registerScript(simpleScriptName, subRegistry, scriptAdapter); LOGGER.debug("Registered script {} into sub-registry {} of script registry {}", new Object[] { scriptAdapter, subRegistry, this.scriptRegistry }); } } }
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.registry.VersionRegisterableScriptClasspathScanner.java
/** * Scans the next level in a resource path for script source files * * @param resourcePattern// www . j a va 2s. co m * the root resource pattern * @param patternStack * the stack of evaluated token patterns * @param versionDataContainer * the container of collected version data * @param subRegistry * the sub-registry to register the script in or {@code null} if no sub-registry is to be used * @throws IOException * if any exception occurs handling the resource */ protected void scanNextLevel(final String resourcePattern, final Collection<String> patternStack, final VersionRegisterableScriptAdapter<Script> versionDataContainer, final String subRegistry) throws IOException { final Resource[] resources = this.resourcePatternResolver.getResources(resourcePattern + "/*"); for (final Resource resource : resources) { final String fileName = resource.getFilename(); LOGGER.debug("Matching next level element name {} below resource", fileName, resourcePattern); boolean dealtWith = false; if (!(patternStack.contains(VERSION_PATTERN) || patternStack.contains(VERSION_RANGE_PATTERN))) { if (fileName.matches(VERSION_PATTERN)) { this.matchVersion(resourcePattern, patternStack, versionDataContainer, subRegistry, fileName); dealtWith = true; } else if (fileName.matches(VERSION_RANGE_PATTERN)) { this.matchVersionRange(resourcePattern, patternStack, versionDataContainer, subRegistry, fileName); dealtWith = true; } } if (!dealtWith && !patternStack.contains(EDITION_PATTERN)) { if (fileName.matches(EDITION_PATTERN)) { this.matchEdition(resourcePattern, patternStack, versionDataContainer, subRegistry, fileName); dealtWith = true; } } if (!dealtWith && !patternStack.contains(SOURCE_FILE_PATTERN)) { if (fileName.matches(SOURCE_FILE_PATTERN)) { this.matchSourceFile(resourcePattern, patternStack, versionDataContainer, subRegistry, resource); dealtWith = true; } } if (!dealtWith && subRegistry == null) { this.scanNextLevel(resourcePattern + "/" + fileName, patternStack, versionDataContainer, fileName); dealtWith = true; } if (!dealtWith) { LOGGER.warn( "Next level element name {} below resource {} could not be matched to a valid fragment - back-stepping", fileName, resourcePattern); } } }
From source file:org.codehaus.groovy.grails.scaffolding.AbstractGrailsTemplateGenerator.java
protected Set<String> extractNames(Resource[] resources) { Set<String> names = new HashSet<String>(); for (Resource resource : resources) { String name = resource.getFilename(); names.add(name.substring(0, name.length() - 4)); }/*from w ww . ja v a2 s .c o m*/ return names; }