List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource
public ClassPathResource(String path)
From source file:org.paxml.selenium.rc.FileServerTest.java
@Test public void testClasspathResource() throws Exception { InputStream inWeb = null;/*from w w w. j a va 2s .c o m*/ InputStream inClass = null; final String path = "paxml/dynamic.xml"; try { URL url = new URL(server.hostIt(path, false)); inWeb = url.openStream(); inClass = new ClassPathResource(path).getInputStream(); Assert.assertEquals(IOUtils.readLines(inClass).toString(), IOUtils.readLines(inWeb).toString()); } finally { IOUtils.closeQuietly(inWeb); IOUtils.closeQuietly(inClass); } }
From source file:csns.util.MyAntiSamy.java
public MyAntiSamy(String policyFile) throws PolicyException, IOException { antiSamy = new AntiSamy(); policy = Policy.getInstance(new ClassPathResource(policyFile).getInputStream()); }
From source file:eu.jasha.demo.sbtfragments.CitiesInitializer.java
@Override public void afterPropertiesSet() throws Exception { Resource resource = new ClassPathResource(citiesFile); List<City> cities;//from w ww. jav a 2 s.co m try (InputStream inputStream = resource.getInputStream()) { cities = objectMapper.readValue(inputStream, new TypeReference<List<City>>() { }); } for (City city : cities) { cityDao.add(city); } }
From source file:com.alibaba.demo.NapoliClientDemo.java
public void init() { beanFactory = new XmlBeanFactory(new ClassPathResource("mq.xml")); //vSender = (AsyncSender) beanFactory.getBean("vSender"); qSender = (AsyncSender) beanFactory.getBean("qSender"); //vFilterSender = (AsyncSender) beanFactory.getBean("vFilterSender"); receiver0 = (Receiver) beanFactory.getBean("receiver0"); //receiver1 = (AsyncReceiver) beanFactory.getBean("receiver1"); //receiver2 = (AsyncReceiver) beanFactory.getBean("receiver2"); log.info("init finished."); }
From source file:com.googlecode.flyway.core.dbsupport.oracle.OracleSqlScriptSmallTest.java
@Test public void parseSqlStatements() throws Exception { String source = FileCopyUtils.copyToString(new InputStreamReader( new ClassPathResource("migration/dbsupport/oracle/sql/placeholders/V1.sql").getInputStream(), Charset.forName("UTF-8"))); OracleSqlScript sqlScript = new OracleSqlScript(source, PlaceholderReplacer.NO_PLACEHOLDERS); List<SqlStatement> sqlStatements = sqlScript.getSqlStatements(); assertEquals(3, sqlStatements.size()); assertEquals(18, sqlStatements.get(0).getLineNumber()); assertEquals(27, sqlStatements.get(1).getLineNumber()); assertEquals(32, sqlStatements.get(2).getLineNumber()); assertEquals("COMMIT", sqlStatements.get(2).getSql()); }
From source file:org.jdal.beans.ImagePropertyEditor.java
/** * Load image from classpath /*from www . j av a2 s . c om*/ * @param text the classpath of image resource * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String) */ @Override public void setAsText(String text) throws IllegalArgumentException { Resource resource = new ClassPathResource(text); Image image = null; try { image = Toolkit.getDefaultToolkit().getImage(resource.getURL()); } catch (IOException e) { log.error(e); } setValue(image); }
From source file:gov.guilin.service.impl.TemplateServiceImpl.java
@SuppressWarnings("unchecked") @Cacheable("template") public List<Template> getAll() { try {/*from ww w .j av a 2 s . c om*/ File guilinXmlFile = new ClassPathResource(CommonAttributes.XML_PATH).getFile(); Document document = new SAXReader().read(guilinXmlFile); List<Template> templates = new ArrayList<Template>(); List<Element> elements = document.selectNodes("/guilin/template"); for (Element element : elements) { Template template = getTemplate(element); templates.add(template); } return templates; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.zero.service.impl.TemplateServiceImpl.java
@SuppressWarnings("unchecked") public List<Template> getAll() { try {/* w w w . ja v a 2 s .c o m*/ File configXmlFile = new ClassPathResource(com.zero.CommonAttributes.CONFIG_XML_PATH).getFile(); Document document = new SAXReader().read(configXmlFile); List<Template> templates = new ArrayList<Template>(); List<Element> elements = document.selectNodes("/config/transfer"); for (Element element : elements) { Template template = getTemplate(element); templates.add(template); } return templates; } catch (Exception e) { e.printStackTrace(); return null; } }
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. j a va 2 s.co m*/ try { return cpr.getURL(); } catch (IOException ie) { throw new AuthenticationConfigurationException("Unable to load " + fileName + " file"); } }
From source file:org.openmrs.module.dhisreport.api.model.ReportTemplatesTest.java
@Test public void unMarshallReportTemplates() throws Exception { ClassPathResource resource = new ClassPathResource("templates_ethiopia.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(ReportTemplates.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); ReportTemplates reportTemplates = (ReportTemplates) jaxbUnmarshaller.unmarshal(resource.getInputStream()); assertNotNull(reportTemplates);//from w w w.j a va2 s. c om List<ReportDefinition> reportDefinitions = reportTemplates.getReportDefinitions(); assertEquals(2, reportDefinitions.size()); for (ReportDefinition rd : reportDefinitions) { for (DataValueTemplate dvt : rd.getDataValueTemplates()) { assertNotNull(dvt.getDataelement()); assertNotNull(dvt.getDataelement().getCode()); assertNotNull(dvt.getDataelement().getName()); assertNotNull(dvt.getDataelement().getUid()); assertNotNull(dvt.getDisaggregation()); assertNotNull(dvt.getDisaggregation().getCode()); assertNotNull(dvt.getDisaggregation().getName()); assertNotNull(dvt.getDisaggregation().getUid()); } } }