Search in sources :

Example 11 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class HttpResourceCacheTest method testPutCachable.

@Test
public void testPutCachable() throws Exception {
    BinaryResource res = BinaryResources.create().withFilename("a.html").withContent("<html></html>".getBytes("UTF-8")).withCachingAllowed(true).build();
    HttpCacheObject obj = new HttpCacheObject(new HttpCacheKey("/"), res);
    boolean b = rc.put(obj);
    Assert.assertTrue(b);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HttpCacheKey(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey) HttpCacheObject(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject) Test(org.junit.Test)

Example 12 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class HttpResourceCacheTest method testPutGet.

@Test
public void testPutGet() throws Exception {
    BinaryResource res = BinaryResources.create().withFilename("a.html").withContent("<html></html>".getBytes("UTF-8")).withCachingAllowed(true).build();
    HttpCacheObject obj = new HttpCacheObject(new HttpCacheKey("/"), res);
    boolean b = rc.put(obj);
    Assert.assertTrue(b);
    HttpCacheObject obj2 = rc.get(new HttpCacheKey("/"));
    Assert.assertEquals(obj.getCacheKey(), obj2.getCacheKey());
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HttpCacheKey(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey) HttpCacheObject(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject) Test(org.junit.Test)

Example 13 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class AbstractHtmlField method setAttachments.

@Override
public void setAttachments(Collection<? extends BinaryResource> attachments) {
    if (attachments == null) {
        m_attachments = new HashMap<>(0);
    } else {
        HashMap<String, BinaryResource> newMap = new HashMap<>(attachments.size());
        for (BinaryResource attachment : attachments) {
            if (attachment != null) {
                newMap.put(attachment.getFilename(), attachment);
            }
        }
        m_attachments = newMap;
    }
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HashMap(java.util.HashMap)

Example 14 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class BinaryResourceUrlUtilityTest method testGetFilenameWithFingerprint_WithoutContent.

@Test
public void testGetFilenameWithFingerprint_WithoutContent() {
    BinaryResource binaryResource = new BinaryResource("foo.txt", null);
    assertEquals("foo.txt", BinaryResourceUrlUtility.getFilenameWithFingerprint(binaryResource));
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) Test(org.junit.Test)

Example 15 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class DefaultWizardStatusHtmlProvider method loadIcon.

/**
 * To load an icon into the given attachments live list
 */
protected void loadIcon(List<BinaryResource> attachments, String iconName) {
    if (attachments == null || iconName == null) {
        return;
    }
    String tempIconName = iconName;
    try {
        int index;
        // determine file format
        index = tempIconName.lastIndexOf('.');
        if (index > 0) {
            tempIconName = tempIconName.substring(0, index);
        }
        // determine icon base name
        String baseIconName = tempIconName;
        index = tempIconName.lastIndexOf('_');
        if (index > 0) {
            baseIconName = tempIconName.substring(0, index);
        }
        // load icon
        IconSpec iconSpec = IconLocator.instance().getIconSpec(tempIconName);
        if (iconSpec == null && !tempIconName.equals(baseIconName)) {
            iconSpec = IconLocator.instance().getIconSpec(baseIconName);
        }
        if (iconSpec != null) {
            attachments.add(new BinaryResource(iconSpec.getName(), iconSpec.getContent()));
        }
    } catch (Exception t) {
        LOG.warn("Failed to load icon '{}'", tempIconName, t);
    }
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HTML.imgByBinaryResource(org.eclipse.scout.rt.platform.html.HTML.imgByBinaryResource) IconSpec(org.eclipse.scout.rt.client.services.common.icon.IconSpec) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)46 Test (org.junit.Test)26 HttpCacheObject (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)19 HttpCacheKey (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey)15 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)4 BinaryResourceHolder (org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder)4 InputStream (java.io.InputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 JSONObject (org.json.JSONObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Field (java.lang.reflect.Field)1