List of usage examples for org.springframework.core.io Resource exists
boolean exists();
From source file:org.springextensions.db4o.io.ResourceStorageTest.java
@Test public void testExists() { String uri = "resource"; Resource resource = mock(Resource.class); when(resource.exists()).thenReturn(true); ResourceLoader resourceLoader = mock(ResourceLoader.class); when(resourceLoader.getResource(uri)).thenReturn(resource); ResourceStorage resourceStorage = new ResourceStorage(); resourceStorage.setResourceLoader(resourceLoader); Assert.assertTrue(resourceStorage.exists(uri)); }
From source file:org.springextensions.db4o.io.ResourceStorageTest.java
@Test public void testExistsNot() { String uri = "resource"; Resource resource = mock(Resource.class); when(resource.exists()).thenReturn(false); ResourceLoader resourceLoader = mock(ResourceLoader.class); when(resourceLoader.getResource(uri)).thenReturn(resource); ResourceStorage resourceStorage = new ResourceStorage(); resourceStorage.setResourceLoader(resourceLoader); Assert.assertFalse(resourceStorage.exists(uri)); }
From source file:org.eclipse.gemini.blueprint.test.internal.util.FileSystemStorageTest.java
public void testDispose() throws Exception { Resource res = storage.getResource(); File file = res.getFile();//from ww w.ja v a2 s .c o m assertTrue(res.exists()); assertTrue(file.exists()); storage.dispose(); assertFalse(res.exists()); assertFalse(file.exists()); }
From source file:org.springextensions.db4o.io.ResourceStorage.java
/** * @param uri/* w w w .ja v a 2 s .c o m*/ * @return Return whether this resource actually exists in physical form. * @see org.springframework.core.io.Resource#exists() */ @Override public boolean exists(String uri) { Resource resource = resourceLoader.getResource(uri); return resource.exists(); }
From source file:com.github.jknack.handlebars.springmvc.SpringTemplateLoader.java
@Override protected URL getResource(final String location) throws IOException { Resource resource = loader.getResource(location); if (!resource.exists()) { return null; }/*from www . java2 s .c o m*/ return resource.getURL(); }
From source file:gov.nih.nci.cabig.caaers2adeers.xslt.ClasspathURIResolver.java
public Source resolve(String href, String base) throws TransformerException { if (log.isDebugEnabled()) log.debug(//from w w w. j a v a2s .com "resolving (" + baseFolder + href + ") the resource [base : " + base + ", href :" + href + "]"); try { Resource resource = resourceLoader.getResource(baseFolder + href); if (resource != null && resource.exists()) return new StreamSource(resource.getInputStream()); } catch (Exception e) { log.error("Unable to load resource [base : " + base + ", href: " + href + "]", e); } if (log.isDebugEnabled()) log.debug("unable to find resource [base : " + base + ", href :" + href + "], " + "so instructing to use default lookup"); return null; //use default lookup }
From source file:org.craftercms.commons.properties.OverrideProperties.java
/** * Checks and starts the reading of the given Resources. *//*from w ww . jav a 2 s . c o m*/ public void init() { for (Resource resource : resources) { if (resource.exists()) { try (InputStream in = resource.getInputStream()) { readPropertyFile(in); } catch (IOException ex) { log.debug("Unable to load queries from " + resource.getDescription(), ex); } } else { log.info("Query file at {} not found. Ignoring it...", resource.getDescription()); } } }
From source file:com.mitchellbosecke.pebble.spring.PebbleTemplateLoader.java
@Override public Reader getReader(String resourceName) throws LoaderException { resourceName = getFullyQualifiedResourceName(resourceName); Resource resource = resourceLoader.getResource(resourceName); if (resource.exists()) { try {/*w w w.j a v a 2 s. c om*/ return new InputStreamReader(resource.getInputStream(), charset); } catch (IOException e) { throw new LoaderException(e, "Failed to load template: " + resourceName); } } throw new LoaderException(null, "No template exists named: " + resourceName); }
From source file:org.brekka.stillingar.spring.resource.dir.ResourceDirectory.java
@Override public Resource getDirResource() { Resource resource = applicationContext.getResource(location); if (!resource.exists()) { resource = new UnresolvableResource("Resource location '%s' not found", location); }/*from w w w.jav a2 s. c om*/ return resource; }
From source file:com.github.springtestdbunit.dataset.AbstractDataSetLoader.java
/** * Loads a {@link IDataSet dataset} from {@link Resource}s obtained from the specified <tt>location</tt>. Each * <tt>location</tt> can be mapped to a number of potential {@link #getResourceLocations resources}, the first * resource that {@link Resource#exists() exists} will be used. {@link Resource}s are loaded using the * {@link ResourceLoader} returned from {@link #getResourceLoader}. * <p>//w w w . j a va 2 s . c om * If no resource can be found then <tt>null</tt> will be returned. * * @see #createDataSet(Resource) * @see com.github.springtestdbunit.dataset.DataSetLoader#loadDataSet(Class, String) java.lang.String) */ public IDataSet loadDataSet(Class<?> testClass, String location) throws Exception { ResourceLoader resourceLoader = getResourceLoader(testClass); String[] resourceLocations = getResourceLocations(testClass, location); for (String resourceLocation : resourceLocations) { Resource resource = resourceLoader.getResource(resourceLocation); if (resource.exists()) { return createDataSet(resource); } } return null; }