List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:org.centralperf.helper.view.AbstractPOIExcelView.java
/** * Creates the workbook from an existing XLS document. * @param url the URL of the Excel template without localization part nor extension * @param request current HTTP request//from w w w . j a v a2s .co m * @return the HSSFWorkbook * @throws Exception in case of failure */ protected Workbook getTemplateSource(String url, HttpServletRequest request) throws Exception { LocalizedResourceHelper helper = new LocalizedResourceHelper(getApplicationContext()); Locale userLocale = RequestContextUtils.getLocale(request); Resource inputFile = helper.findLocalizedResource(url, EXTENSION, userLocale); // Create the Excel document from the source. if (logger.isDebugEnabled()) { logger.debug("Loading Excel workbook from " + inputFile); } return new XSSFWorkbook(inputFile.getInputStream()); }
From source file:com.haulmont.cuba.desktop.sys.DesktopExternalUIComponentsSource.java
protected void _registerAppComponents() { String configName = AppContext.getProperty(DESKTOP_COMPONENTS_CONFIG_XML_PROP); StrTokenizer tokenizer = new StrTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); _registerComponent(stream); } catch (ClassNotFoundException | IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); }//from w w w .jav a 2 s .co m } else { log.warn("Resource {} not found, ignore it", location); } } }
From source file:com.glaf.core.todo.service.SysTodoServiceImpl.java
@Transactional public void reloadConfig() throws Exception { Map<Long, Todo> todoMap = new LinkedHashMap<Long, Todo>(); List<Todo> rows = this.getTodoList(); if (rows != null && rows.size() > 0) { Iterator<Todo> iterator = rows.iterator(); while (iterator.hasNext()) { Todo todo = iterator.next(); todoMap.put(todo.getId(), todo); }//from w ww . j ava2s . co m } TodoXmlReader reader = new TodoXmlReader(); String configPath = SystemProperties.getConfigRootPath() + TodoUtils.TODO_CONFIG; File file = new File(configPath); if (file.isDirectory()) { String[] filelist = file.list(); if (filelist != null) { for (int i = 0, len = filelist.length; i < len; i++) { String filename = filelist[i]; if (filename.toLowerCase().endsWith(".xml")) { Resource resource = new FileSystemResource(configPath + filename); List<Todo> todos = reader.read(resource.getInputStream()); Iterator<Todo> iterator = todos.iterator(); while (iterator.hasNext()) { Todo todo = iterator.next(); Todo model = todoMap.get(todo.getId()); if (model != null) { if (model.getConfigFlag() != 1) { this.deleteById(model.getId()); if (todo.getId() == null) { todo.setId(idGenerator.nextId()); } this.save(todo); } } else { this.save(todo); } } } } } } }
From source file:com.complexible.stardog.ext.spring.DataImporter.java
/** * <code>inputfile</code>// ww w . jav a 2s . co m * * Ingests a file into Stardog, public API to be used after init time * * @param format - RDFFormat enum * @param resource - Spring Resource * @return boolean */ public boolean inputFile(final RDFFormat format, final Resource resource) { return snarlTemplate.execute(new ConnectionCallback<Boolean>() { @Override public Boolean doWithConnection(Connection connection) { try { connection.add().io().format(format).stream(resource.getInputStream()); } catch (StardogException e) { log.error("Error with io adder to Stardog", e); return false; } catch (IOException e) { log.error("Error in IO to inputFile", e); return false; } return true; } }); }
From source file:com.fns.grivet.api.GrivetApiClientIT.java
private String registerTestType() { String json = null;// w w w . j av a 2 s .co m Resource r = resolver.getResource("classpath:TestType.json"); try { json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset()); given().contentType("application/json").request().body(json).then().expect().statusCode(equalTo(201)) .when().post("/api/v1/definition"); } catch (IOException e) { fail(e.getMessage()); } return json; }
From source file:com.glaf.activiti.web.rest.ActivitiProcessResource.java
@GET @Path("view/{processInstanceId}") @Produces({ MediaType.TEXT_HTML }) @ResponseBody/*w w w . j a v a 2s .c om*/ @Transactional(readOnly = true) public byte[] view(@Context HttpServletRequest request, @PathParam("processInstanceId") String processInstanceId) { String contextPath = request.getContextPath(); StringBuffer buffer = new StringBuffer(); if (StringUtils.isNotEmpty(processInstanceId)) { ProcessInstanceInfo processInstanceInfo = activitiProcessQueryService .getProcessInstanceInfo(processInstanceId); if (processInstanceInfo != null) { StringBuffer positionBuffer = new StringBuffer(); StringBuffer position = new StringBuffer(); StringBuffer text = new StringBuffer(); int id = 0; List<ActivityInfo> processedActivityInfos = processInstanceInfo.getProcessedActivityInfos(); List<ActivityInfo> activeActivityInfos = processInstanceInfo.getActiveActivityInfos(); ActivityCoordinates coordinates = null; HistoricActivityInstance activityInstance = null; if (processedActivityInfos != null && !processedActivityInfos.isEmpty()) { for (ActivityInfo info : processedActivityInfos) { coordinates = info.getCoordinates(); activityInstance = info.getActivityInstance(); if (activityInstance == null) { continue; } position.delete(0, position.length()); text.delete(0, text.length()); String elId = "_pai_" + (++id); String title = activityInstance.getActivityName(); position.append("left:").append(coordinates.getX() - 2).append("px;"); position.append("top:").append(coordinates.getY() - 2).append("px;"); position.append("height:").append(coordinates.getHeight() - 2).append("px;"); position.append("width:").append(coordinates.getWidth() - 2).append("px;"); buffer.append("\n <div class=\"tip processed\" id=\"").append(elId) .append("\" style=\"").append(position).append("\"></div>"); Date startDate = activityInstance.getStartTime(); Date endDate = activityInstance.getEndTime(); buffer.append("\n <script>$('").append(elId).append("').store('tip:title', '") .append(title).append('\'').append(").store('tip:text', '") .append("<br/><b>:</b> ").append(DateUtils.getDateTime(startDate)) .append("<br/><b>?:</b> ").append(DateUtils.getDateTime(endDate)); if (activityInstance.getAssignee() != null) { buffer.append("<br/><b>:</b> ").append(activityInstance.getAssignee()); } buffer.append("');</script>"); } } if (activeActivityInfos != null && !activeActivityInfos.isEmpty()) { id = 0; for (ActivityInfo activityInfo : activeActivityInfos) { coordinates = activityInfo.getCoordinates(); String elId = "_aai_" + (++id); positionBuffer.delete(0, positionBuffer.length()); positionBuffer.append("left:").append(coordinates.getX() - 2).append("px;"); positionBuffer.append("top:").append(coordinates.getY() - 2).append("px;"); positionBuffer.append("height:").append(coordinates.getHeight() - 2).append("px;"); positionBuffer.append("width:").append(coordinates.getWidth() - 2).append("px;"); buffer.append("\n <div class=\"tip active\" id=\"").append(elId) .append("\" style=\"").append(positionBuffer.toString()).append("\"></div>"); activityInstance = activityInfo.getActivityInstance(); if (activityInstance != null) { String title = activityInstance.getActivityName(); Date startDate = activityInstance.getStartTime(); buffer.append("\n <script>$('").append(elId).append("').store('tip:title', '") .append(title).append('\'').append(").store('tip:text', '") .append("<br/><b>:</b> ").append(DateUtils.getDateTime(startDate)); if (activityInstance.getAssignee() != null) { buffer.append("<br/><b>:</b> ").append(activityInstance.getAssignee()); } buffer.append("');</script>"); } } } } } String view = CustomProperties.getString("activiti.rs.view"); if (StringUtils.isEmpty(view)) { view = "com/glaf/activiti/web/rest/view.ftl"; } String content = null; if (cache.get(view) != null) { content = (String) cache.get(view); } else { try { Resource resouce = new ClassPathResource(view); content = FileUtils.readFile(resouce.getInputStream()); cache.put(view, content); } catch (IOException e) { e.printStackTrace(); } } Map<String, Object> context = new java.util.HashMap<String, Object>(); context.put("contextPath", contextPath); context.put("x_script", buffer.toString()); context.put("processInstanceId", processInstanceId); content = QueryUtils.replaceTextParas(content, context); try { return content.getBytes("UTF-8"); } catch (IOException e) { return content.getBytes(); } }
From source file:com.haulmont.cuba.web.sys.WebExternalUIComponentsSource.java
protected void _registerAppComponents() { String configName = AppContext.getProperty(WEB_COMPONENTS_CONFIG_XML_PROP); StrTokenizer tokenizer = new StrTokenizer(configName); for (String location : tokenizer.getTokenArray()) { Resource resource = resources.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); _registerComponent(stream); } catch (ClassNotFoundException | IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); }//from w w w . j a v a 2s .c om } else { log.warn("Resource {} not found, ignore it", location); } } }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCOwnerDaoImplTest.java
/** * // w w w .j a v a 2 s .c o m * @throws Exception */ @After public void destroyDatabase() throws Exception { Resource destroyDdl = (Resource) this.applicationContext.getBean("destroyDdl"); String sql = IOUtils.toString(destroyDdl.getInputStream()); JdbcTemplate template = new JdbcTemplate((DataSource) this.applicationContext.getBean("dataSource")); template.execute(sql); // always clear the CalendarUserDao in case a mock was temporarily set ownerDao.setCalendarAccountDao(null); }
From source file:org.jasig.schedassist.impl.caldav.xml.ReportResponseHandlerImplTest.java
@Test public void testControl() throws IOException { Resource controlExample = new ClassPathResource("caldav-examples/report-response-single-calendar.xml"); ReportResponseHandlerImpl handler = new ReportResponseHandlerImpl(); List<CalendarWithURI> calendars = handler.extractCalendars(controlExample.getInputStream()); Assert.assertEquals(1, calendars.size()); CalendarWithURI withUri = calendars.get(0); Assert.assertEquals("http://cal.example.com/bernard/work/abcd2.ics", withUri.getUri()); Assert.assertEquals("\"fffff-abcd2\"", withUri.getEtag()); Calendar cal = withUri.getCalendar(); ProdId prodId = cal.getProductId();//from w w w. j a v a2 s.c om Assert.assertNotNull(prodId); Assert.assertEquals("-//CalendarKey 2.0//iCal4j 1.0//EN", prodId.getValue()); ComponentList components = cal.getComponents(VEvent.VEVENT); Assert.assertEquals(1, components.size()); VEvent event = (VEvent) components.get(0); Assert.assertEquals("regular 10 am meeting", event.getSummary().getValue()); }