List of usage examples for org.apache.wicket.util.resource IResourceStream IResourceStream
IResourceStream
From source file:com.doculibre.constellio.wicket.panels.results.MailDetailsPanel.java
License:Open Source License
public MailDetailsPanel(String id, final Email email) { super(id, new CompoundPropertyModel(email)); add(new Label("froms").setEscapeModelStrings(false)); String messageContentText = email.getMessageContentHtml(); String text = email.getMessageContentText(); //FIXME : hack car les fichiers textes attachs sont ajout comme contenu texte if (text.length() > messageContentText.length()) { messageContentText = text;//from w w w . ja v a2s .c o m } messageContentText = StringUtils.replace(messageContentText, ">>", ">>"); messageContentText = StringUtils.replace(messageContentText, "\n>", "\n>"); messageContentText = StringUtils.replace(messageContentText, "\n", "\n<br />"); // String encodedString; // try { // encodedString = new String(messageContentText.getBytes(), email.getContentEncoding()); // } catch (UnsupportedEncodingException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // encodedString = messageContentText; // } // add(new Label("messageContent", encodedString).setEscapeModelStrings(false)); add(new Label("messageContent", messageContentText).setEscapeModelStrings(false)); add(new ListView("linksList", email.getAttachments()) { @Override protected void populateItem(final ListItem item) { final Email.AttachmentClass element = (Email.AttachmentClass) item.getModelObject(); final AJAXDownload download = new AJAXDownload() { @Override protected IResourceStream getResourceStream() { return createResourceStream(element); } @Override protected String getFileName() { return element.getAttachmentName(); } private IResourceStream createResourceStream(final Email.AttachmentClass element) { IResourceStream resourceStream = new IResourceStream() { private Locale locale = null; private InputStream inputStream = null; @Override public void close() throws IOException { if (inputStream != null) { IOUtils.closeQuietly(inputStream); } } @Override public String getContentType() { return element.getAttachmentType(); } @Override public InputStream getInputStream() throws ResourceStreamNotFoundException { if (inputStream == null) { inputStream = new ByteArrayInputStream(element.getAttachmentContent()); } return inputStream; } @Override public Locale getLocale() { return locale; } @Override public long length() { return ((Integer) element.getAttachmentContent().length).longValue(); } @Override public void setLocale(Locale locale) { this.locale = locale; } @Override public Time lastModifiedTime() { // TODO Auto-generated method stub return null; } }; return resourceStream; } }; item.add(download); AjaxLink link; item.add(link = new AjaxLink("attachmentLinks") { @Override public void onClick(AjaxRequestTarget target) { download.initiate(target); } }); link.add(new Label("urlTitle", element.getAttachmentName())); /*Link link; add(link = new DownloadInputStreamLink("attachmentLinks", new LoadableDetachableModel() { @Override protected Object load() { ByteArrayInputStream in = new ByteArrayInputStream( element.getAttachmentContent()); return in; } }, element.getAttachmentName(), element .getAttachmentType(), ((Integer) element.getAttachmentContent().length) .longValue(), new Date())); link.add(new Label("urlTitle", element.getAttachmentName()));*/ item.add(link); } }); add(new Label("recipients").setEscapeModelStrings(false)); //FIXME 1 by 1 String flags = StringUtils.join(email.getFlags(), ", "); //FIXME i18n flags = StringUtils.replace(flags, "seen", getLocalizer().getString("seen", this)); flags = StringUtils.replace(flags, "flagged", getLocalizer().getString("flagged", this)); add(new Label("flags", flags).setEscapeModelStrings(false)); // add(new Label("folderNames").setEscapeModelStrings(false)); add(new Label("receivedDate").setEscapeModelStrings(false)); }
From source file:org.apache.jetspeed.portlets.wicket.component.DynamicResourceLink.java
License:Apache License
public void onResourceRequested() { onClick();/*w w w. j a v a 2s . c o m*/ IResourceStream resourceStream = new IResourceStream() { { resourceProvider.open(); } /** Transient input stream to resource */ private transient InputStream inputStream = null; private transient Locale locale = null; /** * @see org.apache.wicket.util.resource.IResourceStream#close() */ public void close() throws IOException { resourceProvider.close(); } /** * @see org.apache.wicket.util.resource.IResourceStream#getContentType() */ public String getContentType() { return resourceProvider.getContentType(); } /** * @see org.apache.wicket.util.resource.IResourceStream#getInputStream() */ public InputStream getInputStream() throws ResourceStreamNotFoundException { if (inputStream == null) { try { inputStream = resourceProvider.getResource(); } catch (Exception e) { logger.error("Failed to retrieve input stream from the resource.", e); } } return inputStream; } /** * @see org.apache.wicket.util.watch.IModifiable#lastModifiedTime() */ public Time lastModifiedTime() { return Time.valueOf(resourceProvider.getLastModified()); } /** * @see org.apache.wicket.util.resource.IResourceStream#length() */ public long length() { return resourceProvider.getLength(); } /** * @see org.apache.wicket.util.resource.IResourceStream#getLocale() */ public Locale getLocale() { return locale; } /** * @see org.apache.wicket.util.resource.IResourceStream#setLocale(java.util.Locale) */ public void setLocale(Locale loc) { locale = loc; } }; // Get servlet response to use when responding with resource final Response response = getRequestCycle().getResponse(); // set not cacheable response.setLastModifiedTime(Time.valueOf(-1)); getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, WicketURLEncoder.QUERY_INSTANCE.encode(resourceProvider.getName()))); }
From source file:org.devproof.portal.core.module.common.component.InternalDownloadLink.java
License:Apache License
private IResourceStream createFileResourceStream(final File file, final FileInputStream fis) { return new IResourceStream() { private static final long serialVersionUID = 1L; public void close() throws IOException { fis.close();//from w w w .ja v a 2s . c o m } public String getContentType() { return "application/octet-stream"; } public InputStream getInputStream() throws ResourceStreamNotFoundException { return fis; } public Locale getLocale() { return null; } public long length() { return file.length(); } public void setLocale(Locale locale) { } public Time lastModifiedTime() { return Time.milliseconds(file.lastModified()); } }; }