List of usage examples for org.apache.wicket.request.resource ContentDisposition INLINE
ContentDisposition INLINE
To view the source code for org.apache.wicket.request.resource ContentDisposition INLINE.
Click Source Link
From source file:org.apache.openmeetings.web.util.RecordingResourceReference.java
License:Apache License
@Override public IResource getResource() { return new AbstractResource() { private static final long serialVersionUID = 1L; private final static String ACCEPT_RANGES_HEADER = "Accept-Ranges"; private final static String RANGE_HEADER = "Range"; private final static String CONTENT_RANGE_HEADER = "Content-Range"; private final static String RANGES_BYTES = "bytes"; private File file; private boolean isRange = false; private long start = 0; private long end = 0; private long getChunkLength() { return isRange ? end - start + 1 : (file == null ? -1 : file.length()); }/*from ww w . j a v a 2 s. c o m*/ private IResourceStream getResourceStream() { return file == null ? null : new FileResourceStream(file) { private static final long serialVersionUID = 2546785247219805747L; private transient BoundedInputStream bi; @Override public InputStream getInputStream() throws ResourceStreamNotFoundException { if (bi == null) { //bi = new BoundedInputStream(super.getInputStream(), end + 1); bi = new BoundedInputStream(super.getInputStream(), isRange ? end + 1 : (file == null ? -1 : file.length())); try { bi.skip(start); } catch (IOException e) { throw new ResourceStreamNotFoundException(e); } } return bi; } @Override public Bytes length() { return Bytes.bytes(getChunkLength()); } @Override public void close() throws IOException { if (bi != null) { bi.close(); //also will close original stream bi = null; } } @Override public String getContentType() { return RecordingResourceReference.this.getContentType(); } }; } @Override protected void setResponseHeaders(ResourceResponse data, Attributes attributes) { Response response = attributes.getResponse(); if (response instanceof WebResponse) { WebResponse webResponse = (WebResponse) response; webResponse.setStatus( isRange ? HttpServletResponse.SC_PARTIAL_CONTENT : HttpServletResponse.SC_OK); } super.setResponseHeaders(data, attributes); } @Override protected ResourceResponse newResourceResponse(Attributes attributes) { ResourceResponse rr = new ResourceResponse(); FlvRecording r = getRecording(attributes); if (r != null) { isRange = false; file = getFile(r); rr.setFileName(getFileName(r)); rr.setContentType(RecordingResourceReference.this.getContentType()); rr.setContentDisposition(ContentDisposition.INLINE); rr.setLastModified(Time.millis(file.lastModified())); rr.getHeaders().addHeader(ACCEPT_RANGES_HEADER, RANGES_BYTES); String range = ((HttpServletRequest) attributes.getRequest().getContainerRequest()) .getHeader(RANGE_HEADER); if (range != null && range.startsWith(RANGES_BYTES)) { String[] bounds = range.substring(RANGES_BYTES.length() + 1).split("-"); if (bounds != null && bounds.length > 0) { long length = file.length(); isRange = true; start = Long.parseLong(bounds[0]); end = bounds.length > 1 ? Long.parseLong(bounds[1]) : length - 1; //Content-Range: bytes 229376-232468/232469 rr.getHeaders().addHeader(CONTENT_RANGE_HEADER, String.format("%s %d-%d/%d", RANGES_BYTES, start, end, length)); } } rr.setContentLength(getChunkLength()); rr.setWriteCallback(new WriteCallback() { @Override public void writeData(Attributes attributes) throws IOException { IResourceStream rStream = getResourceStream(); try { writeStream(attributes, rStream.getInputStream()); } catch (ResourceStreamNotFoundException e1) { } catch (ResponseIOException e) { // in case of range operations we expecting such exceptions if (!isRange) { log.error("Error while playing the stream", e); } } finally { rStream.close(); } } }); } else { rr.setError(HttpServletResponse.SC_NOT_FOUND); } return rr; } }; }
From source file:org.cast.cwm.data.component.WavResource.java
License:Open Source License
@Override protected ResourceResponse newResourceResponse(Attributes attributes) { final ResourceResponse response = new ResourceResponse(); response.setContentType("audio/wave"); response.setLastModified(Time.valueOf(mResponseData.getObject().getCreateDate())); if (response.dataNeedsToBeWritten(attributes)) { response.setContentDisposition(ContentDisposition.INLINE); final byte[] audioData = getConverted(); if (audioData == null) { response.setError(HttpServletResponse.SC_NOT_FOUND); } else {// w w w . j a v a2 s. co m response.setWriteCallback(new WriteCallback() { @Override public void writeData(final Attributes attributes) { attributes.getResponse().write(audioData); } }); } } return response; }
From source file:org.cast.cwm.data.resource.UploadedFileResource.java
License:Open Source License
@Override protected ResourceResponse newResourceResponse(final Attributes attributes) { final ResourceResponse response = new ResourceResponse(); long id = attributes.getParameters().get("id").toLong(); IModel<BinaryFileData> mBfd = cwmService.getById(BinaryFileData.class, id); if (mBfd == null || mBfd.getObject() == null) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Data not found [id=" + id + "]"); BinaryFileData bfd = mBfd.getObject(); response.setLastModified(Time.valueOf(bfd.getLastModified())); if (response.dataNeedsToBeWritten(attributes)) { final byte[] data = bfd.getData(); if (data == null) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Data not found [id=" + id + "]"); response.setContentType(bfd.getMimeType()); response.setContentLength(data.length); response.setContentDisposition(ContentDisposition.INLINE); response.setCacheDuration(Duration.days(1)); response.setCacheScope(WebResponse.CacheScope.PUBLIC); response.setWriteCallback(new WriteCallback() { @Override/*from w w w.j av a2 s. c o m*/ public void writeData(final Attributes attributes) { attributes.getResponse().write(data); } }); } return response; }
From source file:org.cast.cwm.data.resource.UserResponseDataResource.java
License:Open Source License
@Override protected ResourceResponse newResourceResponse(final Attributes attributes) { ResourceResponse response = new ResourceResponse(); cwmResponse = cwmService.getById(Response.class, id).getObject(); // if there is no user response, return an error if (cwmResponse == null) { throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Data not found [id=" + id + "]"); }/*from w ww . j a v a 2 s. co m*/ response.setLastModified(Time.valueOf(cwmResponse.getLastUpdated())); if (response.dataNeedsToBeWritten(attributes)) { response.setContentDisposition(ContentDisposition.INLINE); if (cwmResponse.getText() == null) { response.setError(HttpServletResponse.SC_NOT_FOUND); } else { response.setWriteCallback(new WriteCallback() { @Override public void writeData(final Attributes attributes) { attributes.getResponse().write(cwmResponse.getText()); } }); response.setContentType(contentType); response.setTextEncoding(textEncoding); } } return response; }
From source file:org.opensingular.form.wicket.link.FileDownloadLink.java
License:Apache License
@Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); if (ContentDisposition.INLINE == contentDisposition) { tag.put("target", "_blank"); }/*from w w w.j ava2 s. c o m*/ }
From source file:org.opensingular.form.wicket.mapper.attachment.DownloadSupportedBehavior.java
License:Apache License
public DownloadSupportedBehavior(IModel<? extends SInstance> model) { this(model, ContentDisposition.INLINE); }
From source file:org.yes.cart.web.resource.AbstractDynamicResource.java
License:Apache License
@Override protected ResourceResponse newResourceResponse(final Attributes attributes) { final ResourceResponse response = new ResourceResponse(); if (lastModifiedTime != null) { response.setLastModified(lastModifiedTime); } else {//from w w w . j a va2 s . com response.setLastModified(Time.now()); } if (response.dataNeedsToBeWritten(attributes)) { response.setContentType(getFormat()); response.setContentDisposition(ContentDisposition.INLINE); final byte[] imageData = getData(attributes); if (imageData == null) { response.setError(HttpServletResponse.SC_NOT_FOUND); } else { response.setWriteCallback(new WriteCallback() { @Override public void writeData(final Attributes attributes) { attributes.getResponse().write(imageData); } }); configureResponse(response, attributes); } } return response; }