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();
}
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());
}
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);
}
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();
}
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();
}
}
Aggregations