use of org.eclipse.scout.rt.server.commons.servlet.cache.DownloadHttpResponseInterceptor in project scout.rt by eclipse.
the class DownloadHandlerStorage method get.
/**
* Retrieve a downloadable item from the storage.
* <p>
* Items with {@link OpenUriAction#DOWNLOAD} are automatically removed after a certain TTL
* ({@link #getRemovalTimeoutAfterFirstRequest()}).
*/
public BinaryResourceHolderWithAction get(String key) {
BinaryResourceHolderWithAction resHolderWithAction;
synchronized (m_valueMap) {
resHolderWithAction = m_valueMap.get(key);
}
if (resHolderWithAction != null) {
if (resHolderWithAction.getOpenUriAction() == OpenUriAction.DOWNLOAD) {
scheduleRemoval(key, getRemovalTimeoutAfterFirstRequest());
} else {
if (!containsDownloadInterceptor(resHolderWithAction.getHolder())) {
BinaryResourceHolder holder = new BinaryResourceHolder(resHolderWithAction.getHolder().get());
holder.addHttpResponseInterceptor(new DownloadHttpResponseInterceptor(holder.get().getFilename()));
put(key, holder, resHolderWithAction.getOpenUriAction());
}
}
}
return resHolderWithAction;
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.DownloadHttpResponseInterceptor in project scout.rt by eclipse.
the class JsonDesktop method handleModelOpenUri.
protected void handleModelOpenUri(BinaryResource res, IOpenUriAction openUriAction) {
String filename = ObjectUtility.nvl(res.getFilename(), "binaryData");
String filenameEncoded = IOUtility.urlEncode(filename);
// add another path segment to filename to distinguish between different resources
// with the same filename (also makes hash collisions irrelevant).
long counter = RESOURCE_COUNTER.getAndIncrement();
filenameEncoded = counter + "/" + filenameEncoded;
BinaryResourceHolder holder = new BinaryResourceHolder(res);
if (openUriAction == OpenUriAction.DOWNLOAD) {
holder.addHttpResponseInterceptor(new DownloadHttpResponseInterceptor(res.getFilename()));
}
m_downloads.put(filenameEncoded, holder, openUriAction);
String downloadUrl = BinaryResourceUrlUtility.createDynamicAdapterResourceUrl(this, filenameEncoded);
handleModelOpenUri(downloadUrl, openUriAction);
}
Aggregations