List of usage examples for org.apache.wicket.util.resource AbstractResourceStream AbstractResourceStream
AbstractResourceStream
From source file:com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream.java
License:Apache License
public void onRequest() { final InputStream byteStream = initStream(); if (byteStream == null) { return;//from w w w. j a v a 2 s.c o m } IResourceStream resourceStream = new AbstractResourceStream() { @Override public String getContentType() { return contentType; } @Override public InputStream getInputStream() throws ResourceStreamNotFoundException { return byteStream; } @Override public void close() throws IOException { byteStream.close(); } }; getComponent().getRequestCycle() .scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) { @Override public void respond(IRequestCycle requestCycle) { super.respond(requestCycle); } }.setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(Duration.ONE_SECOND)); }
From source file:de.tudarmstadt.ukp.clarin.webanno.monitoring.page.AgreementTable.java
License:Apache License
private Behavior makeDownloadBehavior(final String aKey1, final String aKey2) { return new AjaxEventBehavior("onclick") { private static final long serialVersionUID = 1L; @Override/* w w w . j a v a 2 s .com*/ protected void onEvent(AjaxRequestTarget aTarget) { AJAXDownload download = new AJAXDownload() { private static final long serialVersionUID = 1L; @Override protected IResourceStream getResourceStream() { return new AbstractResourceStream() { private static final long serialVersionUID = 1L; @Override public InputStream getInputStream() throws ResourceStreamNotFoundException { try { AgreementResult result = AgreementTable.this.getModelObject().getStudy(aKey1, aKey2); switch (settings.getObject().exportFormat) { case CSV: return generateCsvReport(result); case DEBUG: return generateDebugReport(result); default: throw new IllegalStateException("Unknown export format [" + settings.getObject().exportFormat + "]"); } } catch (Exception e) { // FIXME Is there some better error handling here? LOG.error("Unable to generate agreement report", e); throw new ResourceStreamNotFoundException(e); } } @Override public void close() throws IOException { // Nothing to do } }; } }; getComponent().add(download); download.initiate(aTarget, "agreement" + settings.getObject().exportFormat.getExtension()); } }; }
From source file:de.tudarmstadt.ukp.clarin.webanno.support.AJAXDownload.java
License:Apache License
/** * Hook method providing the actual resource stream. * //from w w w.j ava 2 s.co m * @return the stream. */ protected IResourceStream getResourceStream() { IResourceStream resStream = new AbstractResourceStream() { private static final long serialVersionUID = 1L; InputStream inStream; @Override public InputStream getInputStream() throws ResourceStreamNotFoundException { try { inStream = new FileInputStream(fileName); } catch (IOException e) { } return inStream; } @Override public void close() throws IOException { inStream.close(); inStream = null; FileUtils.forceDelete(new File(fileName)); } }; return resStream; }
From source file:gr.interamerican.wicket.markup.html.panel.CheckBoxPanel.java
License:Open Source License
public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> clazz) { final StringBuilder builder = new StringBuilder(); builder.append("<html><body>"); //$NON-NLS-1$ builder.append("<wicket:panel>"); //$NON-NLS-1$ builder.append("<input type=\"checkbox\" wicket:id=\"checkboxId\"></input>"); //$NON-NLS-1$ builder.append("</wicket:panel></body></html>"); //$NON-NLS-1$ return new AbstractResourceStream() { /**/*from w w w .j ava 2 s. c o m*/ * UID */ private static final long serialVersionUID = 1L; public InputStream getInputStream() throws ResourceStreamNotFoundException { return new ByteArrayInputStream(builder.toString().getBytes()); } public void close() throws IOException { return; } }; }
From source file:gr.interamerican.wicket.markup.html.panel.DataTableCheckBoxPanel.java
License:Open Source License
@SuppressWarnings({ "nls", "serial" }) public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) { final StringBuffer builder = new StringBuffer(); builder.append("<html><body><wicket:panel>"); builder.append("<input type=\"checkbox\" wicket:id=\"" + CHECKBOX_ID + "\"/>"); builder.append("</wicket:panel></body></html>"); return new AbstractResourceStream() { public InputStream getInputStream() throws ResourceStreamNotFoundException { return new ByteArrayInputStream(builder.toString().getBytes()); }/* ww w.jav a 2s .c o m*/ public void close() throws IOException { /* empty */ } }; }
From source file:gr.interamerican.wicket.markup.html.panel.DataTableRadioButtonPanel.java
License:Open Source License
@SuppressWarnings({ "nls", "serial" }) public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) { final StringBuffer builder = new StringBuffer(); builder.append("<html><body><wicket:panel>"); builder.append("<input type=\"radio\" wicket:id=\"" + RADIO_ID + "\"/>"); builder.append("</wicket:panel></body></html>"); return new AbstractResourceStream() { public InputStream getInputStream() throws ResourceStreamNotFoundException { return new ByteArrayInputStream(builder.toString().getBytes()); }/*from w w w . j a va 2 s . co m*/ public void close() throws IOException { /* empty */ } }; }
From source file:org.apache.isis.viewer.wicket.model.models.ActionModel.java
License:Apache License
private static IResourceStream resourceStreamFor(final Blob blob) { final IResourceStream resourceStream = new AbstractResourceStream() { private static final long serialVersionUID = 1L; @Override//from w ww.j av a 2 s. c om public InputStream getInputStream() throws ResourceStreamNotFoundException { return new ByteArrayInputStream(blob.getBytes()); } @Override public String getContentType() { return blob.getMimeType().toString(); } @Override public void close() throws IOException { } }; return resourceStream; }
From source file:org.apache.openmeetings.web.admin.labels.LangPanel.java
License:Apache License
public LangPanel(String id) { super(id);//from w w w .ja v a 2s . c o m // Create feedback panels add(feedback.setOutputMarkupId(true)); language = new AbstractMap.SimpleEntry<Long, Locale>(1L, Locale.ENGLISH); final LabelsForm form = new LabelsForm("form", this, new StringLabel(null, null)); form.showNewRecord(); add(form); final SearchableDataView<StringLabel> dataView = new SearchableDataView<StringLabel>("langList", new SearchableDataProvider<StringLabel>(LabelDao.class) { private static final long serialVersionUID = 1L; @Override protected LabelDao getDao() { return (LabelDao) super.getDao(); } @Override public long size() { return getDao().count(language.getValue(), search); } @Override public Iterator<? extends StringLabel> iterator(long first, long count) { return getDao().get(language.getValue(), search, (int) first, (int) count, getSort()) .iterator(); } }) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final Item<StringLabel> item) { final StringLabel fv = item.getModelObject(); item.add(new Label("key")); item.add(new Label("value")); item.add(new AjaxEventBehavior("click") { private static final long serialVersionUID = 1L; @Override protected void onEvent(AjaxRequestTarget target) { form.setModelObject(fv); form.hideNewRecord(); target.add(form, listContainer); target.appendJavaScript("labelsInit();"); } }); item.add(AttributeModifier.append("class", getRowClass(fv.getId(), form.getModelObject().getId()))); } }; add(listContainer.add(dataView).setOutputMarkupId(true)); PagedEntityListPanel navigator = new PagedEntityListPanel("navigator", dataView) { private static final long serialVersionUID = 1L; @Override protected void onEvent(AjaxRequestTarget target) { dataView.modelChanging(); target.add(listContainer); } }; DataViewContainer<StringLabel> container = new DataViewContainer<StringLabel>(listContainer, dataView, navigator); container.addLink(new OmOrderByBorder<StringLabel>("orderByName", "key", container)) .addLink(new OmOrderByBorder<StringLabel>("orderByValue", "value", container)); add(container.getLinks()); add(navigator); langForm = new LangForm("langForm", listContainer, this); fileUploadField = new FileUploadField("fileInput"); langForm.add(fileUploadField); langForm.add(new UploadProgressBar("progress", langForm, fileUploadField)); fileUploadField.add(new AjaxFormSubmitBehavior(langForm, "change") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { FileUpload download = fileUploadField.getFileUpload(); try { if (download == null || download.getInputStream() == null) { feedback.error("File is empty"); return; } LabelDao.upload(language.getValue(), download.getInputStream()); } catch (Exception e) { log.error("Exception on panel language editor import ", e); feedback.error(e); } // repaint the feedback panel so that it is hidden target.add(listContainer, feedback); } }); // Add a component to download a file without page refresh final AjaxDownload download = new AjaxDownload(); langForm.add(download); langForm.add(new AjaxButton("export") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { final String name = LabelDao.getLabelFileName(language.getValue()); download.setFileName(name); download.setResourceStream(new AbstractResourceStream() { private static final long serialVersionUID = 1L; private transient InputStream is; @Override public InputStream getInputStream() throws ResourceStreamNotFoundException { try { is = Application.class.getResourceAsStream(name); return is; } catch (Exception e) { throw new ResourceStreamNotFoundException(e); } } @Override public void close() throws IOException { if (is != null) { is.close(); is = null; } } }); download.initiate(target); // repaint the feedback panel so that it is hidden target.add(feedback); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { // repaint the feedback panel so errors are shown target.add(feedback); } }); add(langForm); final AddLanguageDialog addLang = new AddLanguageDialog("addLang", this); add(addLang, new AjaxLink<Void>("addLangBtn") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { addLang.open(target); } }); add(BootstrapFileUploadBehavior.INSTANCE); }
From source file:org.cast.cwm.components.FileDownloadLink.java
License:Open Source License
@Override public void onClick() { AbstractResourceStream rs = new AbstractResourceStream() { private static final long serialVersionUID = 1L; private transient InputStream inputStream; @Override/*from w ww.ja v a 2 s.c o m*/ public InputStream getInputStream() throws ResourceStreamNotFoundException { inputStream = new ByteArrayInputStream(getModelObject()); return inputStream; } @Override public void close() throws IOException { if (inputStream != null) { inputStream.close(); inputStream = null; } } @Override public String getContentType() { return mMimeType.getObject(); } @Override public Bytes length() { return Bytes.bytes(getModelObject().length); } }; ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(rs); handler.setContentDisposition(ContentDisposition.ATTACHMENT).setFileName(mFileName.getObject()); getRequestCycle().scheduleRequestHandlerAfterCurrent(handler); }
From source file:org.geoserver.web.GeoServerResourceStreamLocator.java
License:Open Source License
@SuppressWarnings({ "unchecked", "serial" }) public IResourceStream locate(Class clazz, String path) { int i = path.lastIndexOf("/"); if (i != -1) { String p = path.substring(i + 1); if (GS_PROPERTIES.matcher(p).matches()) { try { // process the classpath for property files Enumeration<URL> urls = getClass().getClassLoader().getResources(p); // build up a single properties file Properties properties = new Properties(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); InputStream in = url.openStream(); properties.load(in); in.close();//from ww w .ja v a 2 s. c o m } // transform the properties to a stream final ByteArrayOutputStream out = new ByteArrayOutputStream(); properties.store(out, ""); return new AbstractResourceStream() { public InputStream getInputStream() throws ResourceStreamNotFoundException { return new ByteArrayInputStream(out.toByteArray()); } public void close() throws IOException { out.close(); } }; } catch (IOException e) { LOGGER.log(Level.WARNING, "", e); } } else if (GS_LOCAL_I18N.matcher(path).matches()) { return null; } else if (path.matches("org/geoserver/.*" + clazz.getName() + ".*_.*.html")) { return null; } } return super.locate(clazz, path); }