Search in sources :

Example 31 with BinaryResource

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

the class AbstractBrowserField method setBinaryResource.

@Override
public void setBinaryResource(BinaryResource binaryResource, BinaryResource... attachments) {
    setLocationInternal(null);
    setBinaryResourceInternal(binaryResource);
    if (attachments == null) {
        setAttachmentsInternal(null);
    } else {
        Set<BinaryResource> attachmentSet = new HashSet<>();
        for (BinaryResource attachment : attachments) {
            if (attachment != null) {
                attachmentSet.add(attachment);
            }
        }
        setAttachmentsInternal(attachmentSet);
    }
    fireContentChanged();
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HashSet(java.util.HashSet)

Example 32 with BinaryResource

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

the class AbstractBrowserFieldTest method testImportFormData.

@Test
public void testImportFormData() {
    // location only
    AbstractBrowserFieldTestData formData = new AbstractBrowserFieldTestData();
    formData.setLocation("http://www.example.org");
    importFormFieldData(formData, false);
    Assert.assertEquals("http://www.example.org", getLocation());
    Assert.assertNull(getBinaryResource());
    Assert.assertTrue(CollectionUtility.isEmpty(getAttachments()));
    final BinaryResource resource = new BinaryResource("document.txt", "Welcome".getBytes(StandardCharsets.UTF_8));
    // resource only
    formData = new AbstractBrowserFieldTestData();
    formData.setBinaryResource(resource);
    importFormFieldData(formData, false);
    Assert.assertNull(getLocation());
    Assert.assertEquals(resource, getBinaryResource());
    Assert.assertTrue(CollectionUtility.isEmpty(getAttachments()));
    final Set<BinaryResource> attachments = new HashSet<>();
    attachments.add(new BinaryResource("attachment.txt", "Content".getBytes(StandardCharsets.UTF_8)));
    attachments.add(new BinaryResource("image.png", new byte[] { 12, 43, 12, 71, 73, 12, 51 }));
    // resource and attachment
    formData = new AbstractBrowserFieldTestData();
    formData.setBinaryResource(resource);
    formData.setAttachments(attachments);
    importFormFieldData(formData, false);
    Assert.assertNull(getLocation());
    Assert.assertEquals(resource, getBinaryResource());
    Assert.assertEquals(attachments, getAttachments());
    // set all three (not a valid case, but import form data will import was is provided)
    formData = new AbstractBrowserFieldTestData();
    formData.setLocation("http://www.example.org");
    formData.setBinaryResource(resource);
    formData.setAttachments(attachments);
    importFormFieldData(formData, false);
    Assert.assertEquals("http://www.example.org", getLocation());
    Assert.assertEquals(resource, getBinaryResource());
    Assert.assertEquals(attachments, getAttachments());
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 33 with BinaryResource

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

the class MalwareScannerTest method testNull.

@Test
public void testNull() {
    BinaryResource res = null;
    new MalwareScanner().scan(res);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) Test(org.junit.Test)

Example 34 with BinaryResource

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

the class HtmlScoutClipboardService method setTextContents.

@Override
public void setTextContents(String textContents) {
    ClipboardForm form = new ClipboardForm();
    form.setMimeTypes(MimeType.TXT);
    // anonymous text paste, no filename
    BinaryResource binaryResource = BinaryResources.create().withContentType(MimeType.TXT.getType()).withContent(StringUtility.emptyIfNull(textContents)).build();
    form.getClipboardField().setValue(Collections.singleton(binaryResource));
    execInitClipboardForm(form);
    form.startCopy();
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) ClipboardForm(org.eclipse.scout.rt.client.ui.form.clipboard.ClipboardForm)

Example 35 with BinaryResource

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

the class UploadRequestHandler method handleUploadFileRequest.

protected void handleUploadFileRequest(IUiSession uiSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String targetAdapterId) throws IOException, FileUploadException {
    // If client sent ACK#, cleanup response history accordingly
    uiSession.confirmResponseProcessed(getAckSequenceNo(httpServletRequest));
    IBinaryResourceConsumer binaryResourceConsumer = resolveJsonAdapter(uiSession, targetAdapterId);
    if (binaryResourceConsumer == null) {
        // Request was already processed and adapter does not exist anymore
        return;
    }
    if (httpServletRequest.getParameter("legacy") != null) {
        httpServletResponse.setContentType("text/plain");
    }
    // Read uploaded data
    Map<String, String> uploadProperties = new HashMap<String, String>();
    List<BinaryResource> uploadResources = new ArrayList<>();
    try {
        readUploadData(httpServletRequest, binaryResourceConsumer.getMaximumBinaryResourceUploadSize(), uploadProperties, uploadResources);
    } catch (PlatformException ex) {
        // NOSONAR
        writeJsonResponse(httpServletResponse, m_jsonRequestHelper.createUnsafeUploadResponse());
        return;
    }
    // GUI requests for the same session must be processed consecutively
    final ReentrantLock uiSessionLock = uiSession.uiSessionLock();
    uiSessionLock.lock();
    try {
        if (uiSession.isDisposed()) {
            writeJsonResponse(httpServletResponse, m_jsonRequestHelper.createSessionTimeoutResponse());
            return;
        }
        JSONObject jsonResp = uiSession.processFileUpload(httpServletRequest, httpServletResponse, binaryResourceConsumer, uploadResources, uploadProperties);
        if (jsonResp == null) {
            jsonResp = m_jsonRequestHelper.createEmptyResponse();
        }
        writeJsonResponse(httpServletResponse, jsonResp);
    } finally {
        uiSessionLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ArrayList(java.util.ArrayList) IBinaryResourceConsumer(org.eclipse.scout.rt.ui.html.res.IBinaryResourceConsumer)

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