List of usage examples for org.springframework.core.io DefaultResourceLoader getResource
@Override
public Resource getResource(String location)
From source file:com.edgenius.core.util.FileUtil.java
/** * IMPORTANT: this location must be Spring resource format, such as, file://c:/abc.txt * or classpath:abc.properties etc. If there is not protocol prefix, this method may not * return correct value (always false).//w w w.j a va 2s. co m * @param location * @return */ public static boolean exist(String location) { DefaultResourceLoader loader = new DefaultResourceLoader(); Resource res = loader.getResource(location); return res.exists(); }
From source file:com.edgenius.core.util.FileUtil.java
/** * Wrapper of Spring DefaultResourceLoader. * The location must start with "classpath:" or "file://", otherwise, this method * may throw file not found exception./*from w w w .j a va 2 s . c o m*/ * Important: The file must be in file system. This means it won't work if it is in jar or zip file etc. * Please getFileInputStream() to get input stream directly if they are in jar or zip * * @param location * @return * @throws IOException */ public static File getFile(String location) throws IOException { DefaultResourceLoader loader = new DefaultResourceLoader(); Resource res = loader.getResource(location); try { return res.getFile(); } catch (IOException e) { throw (e); } }
From source file:com.edgenius.core.util.FileUtil.java
/** * /*from ww w . ja v a 2 s . c o m*/ * @param location * @return * @throws IOException */ public static InputStream getFileInputStream(String location) throws IOException { //Don't user DefaultResourceLoader directly, as test it try to find host "c" if using method resource.getInputStream() // while location is "file://c:/var/test" etc. DefaultResourceLoader loader = new DefaultResourceLoader(); Resource res = loader.getResource(location); if (ResourceUtils.isJarURL(res.getURL())) { //it is in jar file, we just assume it won't be changed in runtime, so below method is safe. try { return res.getInputStream(); } catch (IOException e) { throw (e); } } else { //in Tomcat, the classLoader cache the input stream even using thread scope classloader, but it is still failed //if the reload in same thread. For example, DataRoot class save and reload in same thread when install. //So, we assume if the file is not inside jar file, we will always reload the file into a new InputStream from file system. //if it is not jar resource, then try to refresh the input stream by file system return new FileInputStream(res.getFile()); } }
From source file:org.codehaus.grepo.procedure.AbstractProcedureRepositoryTest.java
/** * @param fileName The file name.// w ww .j av a2 s . co m * @throws FileNotFoundException in case of errors. * @throws IOException in case of errors. */ protected void executeSqlFromFile(String fileName) throws FileNotFoundException, IOException { DefaultResourceLoader drl = new DefaultResourceLoader(); Resource resource = drl.getResource(fileName); BufferedReader br = new BufferedReader(new FileReader(resource.getFile())); StringBuilder sb = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } br.close(); getJdbcTemplate().execute(sb.toString()); }
From source file:com.ofbizian.infinispan.AtomikosJtaConfiguration.java
private void executeScript(Connection connection, String location) { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); populator.addScript(resourceLoader.getResource(location)); try {/*from w w w . j a va2 s . c o m*/ populator.populate(connection); } catch (Exception e) { e.printStackTrace(); } }
From source file:gov.va.vinci.leo.cr.ExternalCollectionReader.java
/** * Load a resource object from the path to the CollectionReader descriptor then use the framework to initialize the reader. * * @param collectionReaderDescriptor Path to the CollectionReader descriptor. * @throws ResourceInitializationException if there is an error reading the descriptor. * @throws IOException if there is an error in the XML of the descriptor. * @throws InvalidXMLException if the CollectionReader cannot be initialized by the framework. *//*w w w . j av a 2 s. c o m*/ private void setCollectionReader(String collectionReaderDescriptor) throws IOException, InvalidXMLException, ResourceInitializationException { ClassLoader cl = ClassLoader.getSystemClassLoader(); DefaultResourceLoader loader = new DefaultResourceLoader(cl); Resource resource = loader.getResource(collectionReaderDescriptor); setCollectionReader(resource.getFile()); }
From source file:lichen.orm.internal.HibernateSessionManagerWithSpringImpl.java
public HibernateSessionManagerWithSpringImpl(final List<HibernateConfiger> hibernateConfigurers, final DataSource ds, final LobHandler lobHandler, final @Symbol(LichenOrmSymbols.HIBERNATE_CFG_FILE) String cfgFile) { sessionFactoryBean = new LocalSessionFactoryBean() { protected void postProcessConfiguration(Configuration config) throws HibernateException { for (HibernateConfiger configer : hibernateConfigurers) { configer.config(config); }/*from w ww. j a v a 2 s. c om*/ } }; //set hibernate cfg file DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); sessionFactoryBean.setConfigLocation(resourceLoader.getResource(cfgFile)); //datasource sessionFactoryBean.setDataSource(ds); sessionFactoryBean.setLobHandler(lobHandler); sessionFactoryBean.setSchemaUpdate(false); try { //build SessionFactory Bean sessionFactoryBean.afterPropertiesSet(); } catch (Exception e) { throw new RuntimeException(e); } sessionFactory = (SessionFactory) sessionFactoryBean.getObject(); configuration = sessionFactoryBean.getConfiguration(); }
From source file:com.edgenius.wiki.service.impl.SystemPropertyPlaceholderConfigurer.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Properties props = loadProperties(); DefaultResourceLoader loader = new DefaultResourceLoader(); Resource globalConf = loader.getResource(props.get(DataRoot.rootKey) + Global.FILE); initGlobal(globalConf);//from w w w. ja va 2 s . c o m super.postProcessBeanFactory(beanFactory); }
From source file:org.sinekartapdfa.alfresco.action.DocumentToPDFA.java
public void afterPropertiesSet() throws Exception { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); try {/*from w w w . j av a 2s .c o m*/ InputStream is = resourceLoader.getResource(documentFormatsConfiguration).getInputStream(); formatRegistry = new XmlDocumentFormatRegistry(is); } catch (IOException e) { tracer.error("Unable to load document formats configuration file: " + documentFormatsConfiguration, e); throw new AlfrescoRuntimeException( "Unable to load document formats configuration file: " + documentFormatsConfiguration, e); } // set up the converter if (converter == null) { converter = new StreamOpenOfficeDocumentConverter(connection); } }
From source file:se.vgregion.alfresco.repo.content.transform.JodContentTransformer.java
@Override public void afterPropertiesSet() throws Exception { // load the document conversion configuration if (this.documentFormatsConfiguration != null) { final DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); try {/* www .j ava2 s .c o m*/ final InputStream is = resourceLoader.getResource(this.documentFormatsConfiguration) .getInputStream(); this.formatRegistry = new JooReportsXmlDocumentFormatRegistryAdapter(is); // We do not need to explicitly close this InputStream as it is closed // for us within the XmlDocumentFormatRegistry } catch (final IOException e) { throw new AlfrescoRuntimeException( "Unable to load document formats configuration file: " + this.documentFormatsConfiguration); } } else { this.formatRegistry = new JooReportsXmlDocumentFormatRegistryAdapter(); } }