List of usage examples for org.springframework.core.io ClassPathResource exists
@Override public boolean exists()
From source file:org.cagrid.gaards.websso.utils.FileHelper.java
public InputStream getFileAsStream(String fileName) throws AuthenticationConfigurationException { ClassPathResource cpr = new ClassPathResource(fileName); if (!cpr.exists()) { throw new AuthenticationConfigurationException("Unable to load " + fileName + " file"); }/* w w w . j av a 2s . c o m*/ try { return cpr.getInputStream(); } catch (IOException ie) { throw new AuthenticationConfigurationException("Unable to load " + fileName + " file"); } }
From source file:org.cagrid.gaards.websso.utils.FileHelper.java
public URL getFileAsURL(String fileName) throws AuthenticationConfigurationException { ClassPathResource cpr = new ClassPathResource(fileName); if (!cpr.exists()) { throw new AuthenticationConfigurationException("Unable to load " + fileName + " file"); }//from w w w .ja v a 2 s. c o m try { return cpr.getURL(); } catch (IOException ie) { throw new AuthenticationConfigurationException("Unable to load " + fileName + " file"); } }
From source file:dk.teachus.backend.bean.impl.SpringVelocityBean.java
public String mergeTemplate(String template, Map<String, Object> model, Locale locale) throws VelocityException { StringBuilder templateLocation = new StringBuilder(template); if (locale != null) { StringBuilder localeTemplateLocation = new StringBuilder(templateLocation); localeTemplateLocation.append(UNDERSCORE); localeTemplateLocation.append(locale.toString()); localeTemplateLocation.append(VM); ClassPathResource classPathResource = new ClassPathResource(localeTemplateLocation.toString()); if (classPathResource.exists()) { templateLocation = localeTemplateLocation; } else {/* www .j ava 2s .c om*/ templateLocation.append(VM); } } else { templateLocation.append(VM); } return mergeTemplate(templateLocation.toString(), model); }
From source file:com.frdna.config.context.spring.SpringContext.java
public SpringContext(Object environment, String name) { String fileName = name;/*w w w. ja v a 2 s. co m*/ if (fileName == null) { fileName = "config.xml"; } GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); Log.info(this, "Loading SpringContext from [classpath:%s]", fileName); applicationContext.load(new ClassPathResource(fileName)); if (environment != null) { Log.info(this, "Loading SpringContext from [classpath:%s/%s]", environment, fileName); ClassPathResource resource = new ClassPathResource(String.valueOf(environment) + "/" + fileName); if (resource.exists()) { applicationContext.load(resource); } else { Log.warn(this, "Unable to find environment resource [%s]", resource); } } applicationContext.refresh(); this.applicationContext = applicationContext; }
From source file:com.github.mrstampy.gameboot.otp.OtpTestConfiguration.java
private InputStream getResource(String name) throws Exception { ClassPathResource r = new ClassPathResource(name); if (!r.exists()) throw new IllegalStateException("No " + name + " on the classpath"); return r.getInputStream(); }
From source file:org.jboss.arquillian.spring.integration.inject.utils.ClassPathResourceLocationsProcessor.java
/** * Builds array with default locations for {@param testClass} test instance. * * @param testClass - test class wrapped by TestClass instance. * * @return array with default location (in form testClassName-context.xml) or empty array otherwise. *///from w ww . j av a 2s. c om String[] defaultLocationForGivenTestClass(Class testClass) { String fullyQualifiedTestClassName = testClass.getName(); String defaultConfigResourcePath = SLASH + fullyQualifiedTestClassName.replace('.', '/') + DEFAULT_LOCATION_SUFFIX; String prefixedResourcePath = CLASSPATH_PREFIX + defaultConfigResourcePath; ClassPathResource classPathResource = new ClassPathResource(defaultConfigResourcePath, testClass); if (classPathResource.exists()) { return new String[] { prefixedResourcePath }; } return EMPTY_STRING_ARRAY; }
From source file:nl.surfnet.coin.db.AbstractInMemoryDatabaseTest.java
@After public void afterClass() throws Exception { ClassPathResource resource = new ClassPathResource(getMockDataCleanUpFilename()); if (resource.exists()) { logger.debug("Cleaning database content from " + resource); final String sql = IOUtils.toString(resource.getInputStream()); final String[] split = sql.split(";"); for (String s : split) { if (!StringUtils.hasText(s)) { continue; }// w ww . j a va 2 s .c o m jdbcTemplate.execute(s + ';'); } } }
From source file:com.brienwheeler.svc.email.impl.SmartTemplateLoader.java
@Override public Object findTemplateSource(String name) throws IOException { ValidationUtils.assertNotNull(name, "name cannot be null"); if (!name.startsWith(CLASSPATH_PREFIX)) return fileLoader.findTemplateSource(name); ClassPathResource resource = new ClassPathResource(name.substring(CLASSPATH_PREFIX.length())); if (resource.exists()) return new ClassPathTemplateSource(resource); else/* ww w .j ava2 s. c om*/ return null; }
From source file:InvokeGridService.java
public InputStream getResourceInputStream(String fileName) throws Exception { ClassPathResource cpr = new ClassPathResource(fileName); if (!cpr.exists()) { throw new Exception(fileName + " does not exist."); }/*ww w . j a v a2 s .c o m*/ try { InputStream inputStream = cpr.getInputStream(); return inputStream; } catch (IOException e) { throw new Exception("Error loading file " + fileName); } }
From source file:at.ac.tuwien.infosys.jcloudscale.classLoader.simple.RemoteClassProvider.java
@Override public void onMessage(Message message) { String className = null;//from w w w. ja v a2s. c o m try { className = ((ClassRequest) ((ObjectMessage) message).getObject()).className; log.fine("Message received:" + className); // we expect sender to specify the query he's waiting response into the JMSReplyTo Destination destination = message.getJMSReplyTo(); UUID correlationId = UUID.fromString(message.getJMSCorrelationID()); // preparing class bytecode. byte[] bytecode = null; try { String classPath = className.replace('.', '/') + ".class";//TODO: use utils. InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(classPath); // If the class cannot be found, attempt to find a resource with the requested name if (is == null) { try { ClassPathResource resource = new ClassPathResource(className); if (resource.exists()) { is = resource.getInputStream(); } } catch (IOException e) { // Ignore } } if (is == null) log.severe(String.format("Requested class %s was not found.", className)); else bytecode = RemoteClassLoaderUtils.getByteArray(is); } catch (Exception ex) { log.severe("Failed to provide required class " + className + ": " + ex.toString()); ex.printStackTrace(); } finally { mq.respond(new ClassResponse(bytecode), destination, correlationId); } } catch (JMSException e) { log.severe("Failed to process message (" + className + "): " + e.toString()); e.printStackTrace(); } }