List of usage examples for org.springframework.core.io Resource createRelative
Resource createRelative(String relativePath) throws IOException;
From source file:org.wallride.web.support.MediaHttpRequestHandler.java
private Resource readResource(final Media media, final int width, final int height, final Media.ResizeMode mode) throws IOException { // Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); // final Resource prefix = resourceLoader.getResource(blog.getMediaPath()); final Resource prefix = resourceLoader.getResource(wallRideProperties.getMediaLocation()); final Resource resource = prefix.createRelative(media.getId()); if (!resource.exists()) { return null; }/* w w w. ja va 2 s .c om*/ Resource resized = resource; boolean doResize = (width > 0 || height > 0); if (doResize && "image".equals(MediaType.parseMediaType(media.getMimeType()).getType())) { resized = prefix.createRelative( String.format("%s.resized/%dx%d-%d", media.getId(), width, height, mode.ordinal())); if (!resized.exists() || resource.lastModified() > resized.lastModified()) { File temp = File.createTempFile(getClass().getCanonicalName() + ".resized-", "." + MediaType.parseMediaType(media.getMimeType()).getSubtype()); temp.deleteOnExit(); resizeImage(resource, temp, width, height, mode); // AmazonS3ResourceUtils.writeFile(temp, resized); ExtendedResourceUtils.write(resized, temp); FileUtils.deleteQuietly(temp); } } return resized; }
From source file:com.opengamma.component.ComponentConfigPropertiesLoader.java
/** * Handle the inclusion of another file. * // ww w. j a v a 2s . c om * @param baseResource the base resource, not null * @param includeFile the resource to include, not null * @param depth the depth of the properties file, used for logging */ private void handleInclude(final Resource baseResource, String includeFile, final int depth) { // find resource Resource include; try { include = ResourceUtils.createResource(includeFile); } catch (Exception ex) { try { include = baseResource.createRelative(includeFile); } catch (Exception ex2) { throw new OpenGammaRuntimeException(ex2.getMessage(), ex2); } } // load and merge getLogger().logInfo( StringUtils.repeat(" ", depth) + " Including item: " + ResourceUtils.getLocation(include)); load(include, depth + 1); }
From source file:com.myee.tarot.core.config.RuntimePropertyPlaceholderConfigurer.java
protected Resource[] createSharedCommonResource(Set<Resource> locations) throws IOException { Resource[] resources = new Resource[locations.size()]; int index = 0; for (Resource resource : locations) { resources[index] = resource.createRelative("common-shared.properties"); index++;//from ww w . j av a2 s . com } return resources; }
From source file:com.myee.tarot.core.config.RuntimePropertyPlaceholderConfigurer.java
protected Resource[] createCommonResource(Set<Resource> locations) throws IOException { Resource[] resources = new Resource[locations.size()]; int index = 0; for (Resource resource : locations) { resources[index] = resource.createRelative("common.properties"); index++;// w w w . ja va2 s .com } return resources; }
From source file:com.myee.tarot.core.config.RuntimePropertyPlaceholderConfigurer.java
protected Resource[] createPropertiesResource(String environment, Set<Resource> locations) throws IOException { String fileName = environment.toString().toLowerCase() + ".properties"; Resource[] resources = new Resource[locations.size()]; int index = 0; for (Resource resource : locations) { resources[index] = resource.createRelative(fileName); index++;/*ww w. j av a 2s. c o m*/ } return resources; }
From source file:com.myee.tarot.core.config.RuntimePropertyPlaceholderConfigurer.java
protected Resource[] createSharedPropertiesResource(String environment, Set<Resource> locations) throws IOException { String fileName = environment.toString().toLowerCase() + "-shared.properties"; Resource[] resources = new Resource[locations.size()]; int index = 0; for (Resource resource : locations) { resources[index] = resource.createRelative(fileName); index++;// w w w . j a v a 2 s . co m } return resources; }
From source file:com.myee.tarot.core.config.RuntimePropertyPlaceholderConfigurer.java
protected Resource[] createBroadleafResource() throws IOException { Resource[] resources = new Resource[blcPropertyLocations.size()]; int index = 0; for (Resource resource : blcPropertyLocations) { resources[index] = resource.createRelative("common.properties"); index++;// w w w . j ava 2 s . co m } return resources; }
From source file:fr.acxio.tools.agia.io.FilesOperationProcessorTest.java
@Test public void testExecuteCopy() throws Exception { FilesOperationProcessor aProcessor = new FilesOperationProcessor(); ResourcesFactory aSourceFactory = mock(ResourcesFactory.class); Resource aFileResource1 = mock(Resource.class); when(aFileResource1.getFile()).thenReturn(new File("src/test/resources/testFiles/input.csv")); when(aFileResource1.exists()).thenReturn(true); when(aSourceFactory.getResources(anyMapOf(Object.class, Object.class))) .thenReturn(new Resource[] { aFileResource1 }); ResourceFactory aDestinationFactory = mock(ResourceFactory.class); Resource aDestResource = mock(Resource.class); when(aDestResource.getFile()).thenReturn(new File("target/CP-input.csv")); when(aDestResource.exists()).thenReturn(false); Resource aRelativeResource = mock(Resource.class); when(aRelativeResource.getFile()).thenReturn(new File("target")); when(aDestResource.createRelative("/.")).thenReturn(aRelativeResource); when(aDestinationFactory.getResource(anyMapOf(Object.class, Object.class))).thenReturn(aDestResource); assertFalse(aDestResource.getFile().exists()); aProcessor.setSourceFactory(aSourceFactory); aProcessor.setDestinationFactory(aDestinationFactory); aProcessor.setOperation(Operation.COPY); aProcessor.setKey("outputFiles"); aProcessor.afterPropertiesSet();/*from www . j a v a 2 s.co m*/ Map<String, Object> aData = new HashMap<String, Object>(); aData.put("k1", "v1"); Map<String, Object> aResult = aProcessor.process(aData); assertNotNull(aResult); assertNotNull(aResult.get("outputFiles")); String aOutputFilePath = ((List<String>) aResult.get("outputFiles")).get(0); assertEquals(new File("target/CP-input.csv").getCanonicalPath(), aOutputFilePath); assertTrue(aDestResource.getFile().exists()); assertTrue(new File(aOutputFilePath).exists()); }
From source file:fr.acxio.tools.agia.io.AbstractFileOperations.java
protected boolean isDirectory(Resource sResource) throws IOException { if (sResource.exists()) { return sResource.getFile().isDirectory(); } else {//w w w . j ava2s. co m // Dirty trick to tell if the resource is a directory or not when it does not exist yet return sResource.createRelative(SAME_RELATIVE_PATH).getFile().getCanonicalPath() .equals(sResource.getFile().getCanonicalPath()); } }
From source file:com.opengamma.component.ComponentConfigIniLoader.java
/** * Handle the inclusion of another file. * //w ww . jav a2 s . c om * @param baseResource the base resource, not null * @param includeFile the resource to include, not null * @param depth the depth of the properties file, used for logging * @param config the config being loaded, not null */ private void handleInclude(final Resource baseResource, String includeFile, final int depth, final ComponentConfig config) { // find resource Resource include; try { include = ResourceUtils.createResource(includeFile); } catch (Exception ex) { try { include = baseResource.createRelative(includeFile); } catch (Exception ex2) { throw new OpenGammaRuntimeException(ex2.getMessage(), ex2); } } // load and merge getLogger().logInfo( StringUtils.repeat(" ", depth) + " Including item: " + ResourceUtils.getLocation(include)); try { doLoad(include, depth + 1, config); } catch (RuntimeException ex) { throw new OpenGammaRuntimeException("Unable to load INI file: " + include, ex); } }