use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class HtmlFileLoader method loadResource.
@Override
public HttpCacheObject loadResource(HttpCacheKey cacheKey) throws IOException {
String pathInfo = cacheKey.getResourcePath();
BinaryResource content = loadResource(pathInfo);
if (content == null) {
return null;
}
// no cache-control, only E-Tag checks to make sure that a session with timeout is correctly
// forwarded to the login using a GET request BEFORE the first json POST request
HttpCacheObject httpCacheObject = new HttpCacheObject(cacheKey, content);
// Suppress automatic "compatibility mode" in IE in intranet zone
httpCacheObject.addHttpResponseInterceptor(new HttpResponseHeaderContributor("X-UA-Compatible", "IE=edge") {
private static final long serialVersionUID = 1L;
@Override
public void intercept(HttpServletRequest req, HttpServletResponse resp) {
HttpClientInfo httpClientInfo = HttpClientInfo.get(req);
if (httpClientInfo.isMshtml()) {
// Send headers only for IE
super.intercept(req, resp);
}
}
});
return httpCacheObject;
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class JsonBrowserField method getLocation.
protected String getLocation() {
String location = getModel().getLocation();
BinaryResource binaryResource = getModel().getBinaryResource();
if (location == null && binaryResource != null) {
location = BinaryResourceUrlUtility.createDynamicAdapterResourceUrl(this, binaryResource);
}
return location;
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class JsonImageField method extractBinaryResource.
protected BinaryResource extractBinaryResource(Object raw) {
if (raw instanceof BinaryResource) {
return (BinaryResource) raw;
}
if (raw instanceof byte[]) {
Adler32 crc = new Adler32();
crc.update((byte[]) raw);
return new BinaryResource("image-" + (crc.getValue()) + "-" + (((byte[]) raw).length) + ".jpg", (byte[]) raw);
}
return null;
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class AbstractResourceLoader method loadResource.
@Override
public HttpCacheObject loadResource(HttpCacheKey cacheKey) throws IOException {
String pathInfo = cacheKey.getResourcePath();
BinaryResource content = loadResource(pathInfo);
if (content == null) {
return null;
}
return new HttpCacheObject(cacheKey, content);
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class DownloadHandlerStorageTest method testGet.
@Test
public void testGet() {
final CountDownLatch secondGet = new CountDownLatch(1);
final CountDownLatch elementRemoved = new CountDownLatch(1);
DownloadHandlerStorage storage = new DownloadHandlerStorage() {
@Override
protected long getTTLForResource(BinaryResource res) {
return 50L;
}
@Override
protected void removeOnTimeout(String key) {
waitFor(secondGet);
super.removeOnTimeout(key);
elementRemoved.countDown();
}
};
BinaryResource res = new BinaryResource("bar.txt", null);
BinaryResourceHolder holder = new BinaryResourceHolder(res);
storage.put(KEY, holder, OpenUriAction.NEW_WINDOW);
assertEquals(1, storage.futureMap().size());
BinaryResourceHolderWithAction holderWithAction = storage.get(KEY);
assertEquals(OpenUriAction.NEW_WINDOW, holderWithAction.getOpenUriAction());
assertEquals(res, holderWithAction.getHolder().get());
assertFalse("Must not contain download interceptor.", containsDownloadInterceptor(holderWithAction.getHolder()));
holderWithAction = storage.get(KEY);
assertEquals(res, holderWithAction.getHolder().get());
assertTrue("Must contain download interceptor.", containsDownloadInterceptor(holderWithAction.getHolder()));
secondGet.countDown();
waitFor(elementRemoved);
assertNull(storage.get(KEY));
assertEquals("futureMap must be cleared after timeout", 0, storage.futureMap().size());
}
Aggregations