use of com.github.bordertech.wcomponents.file.FileItemWrap in project wcomponents by BorderTech.
the class WFileWidget method doHandleRequest.
/**
* {@inheritDoc}
*/
@Override
protected boolean doHandleRequest(final Request request) {
FileItemWrap value = getRequestValue(request);
FileItemWrap current = getValue();
boolean changed = value != null || current != null;
if (changed) {
setData(value);
}
return changed;
}
use of com.github.bordertech.wcomponents.file.FileItemWrap in project wcomponents by BorderTech.
the class WFileWidget method getRequestValue.
/**
* {@inheritDoc}
*/
@Override
public FileItemWrap getRequestValue(final Request request) {
if (isPresent(request)) {
FileItem value = request.getFileItem(getId());
// No file selected
if (Util.empty(value.getName()) && value.getSize() == 0) {
return null;
}
FileItemWrap wrapper = new FileItemWrap(value);
return wrapper;
} else {
return getValue();
}
}
use of com.github.bordertech.wcomponents.file.FileItemWrap in project wcomponents by BorderTech.
the class WMultiFileWidget method doHandleUploadRequest.
/**
* The request is a targeted file upload request. Upload the file and respond with the file information.
*
* @param request the request being processed.
*/
protected void doHandleUploadRequest(final Request request) {
// Protect against client-side tampering of disabled/read-only fields.
if (isDisabled() || isReadOnly()) {
throw new SystemException("File widget cannot be updated.");
}
// Only process on a POST
if (!"POST".equals(request.getMethod())) {
throw new SystemException("File widget cannot be updated by " + request.getMethod() + ".");
}
// Check only one file item in the request
FileItem[] items = request.getFileItems(getId());
if (items.length > 1) {
throw new SystemException("More than one file item received on the request.");
}
// Check the client provided a fileID
String fileId = request.getParameter(FILE_UPLOAD_MULTI_PART_ID_KEY);
if (fileId == null) {
throw new SystemException("No file id provided for file upload.");
}
// Wrap the file item
FileItemWrap wrap = new FileItemWrap(items[0]);
FileWidgetUpload file = new FileWidgetUpload(fileId, wrap);
addFile(file);
// Set the file id to be used ion the renderer
setFileUploadRequestId(fileId);
setNewUpload(true);
}
use of com.github.bordertech.wcomponents.file.FileItemWrap in project wcomponents by BorderTech.
the class WMultiFileWidgetRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
WMultiFileWidget fileUpload = new WMultiFileWidget();
assertSchemaMatch(fileUpload);
assertXpathEvaluatesTo(fileUpload.getId(), "//ui:multifileupload/@id", fileUpload);
assertXpathEvaluatesTo("10240000", "//ui:multifileupload/@maxFileSize", fileUpload);
assertXpathNotExists("//ui:multifileupload/@disabled", fileUpload);
assertXpathNotExists("//ui:multifileupload/@hidden", fileUpload);
assertXpathNotExists("//ui:multifileupload/@required", fileUpload);
assertXpathNotExists("//ui:multifileupload/@readOnly", fileUpload);
assertXpathNotExists("//ui:multifileupload/@toolTip", fileUpload);
assertXpathNotExists("//ui:multifileupload/@accessibleText", fileUpload);
assertXpathNotExists("//ui:multifileupload/@acceptedMimeTypes", fileUpload);
assertXpathNotExists("//ui:multifileupload/@maxFiles", fileUpload);
assertXpathNotExists("//ui:multifileupload/ui:file", fileUpload);
fileUpload.setDisabled(true);
assertSchemaMatch(fileUpload);
assertXpathEvaluatesTo("true", "//ui:multifileupload/@disabled", fileUpload);
setFlag(fileUpload, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(fileUpload);
assertXpathEvaluatesTo("true", "//ui:multifileupload/@hidden", fileUpload);
fileUpload.setMandatory(true);
assertSchemaMatch(fileUpload);
assertXpathEvaluatesTo("true", "//ui:multifileupload/@required", fileUpload);
fileUpload.setToolTip("tooltip");
assertSchemaMatch(fileUpload);
assertXpathEvaluatesTo(fileUpload.getToolTip(), "//ui:multifileupload/@toolTip", fileUpload);
fileUpload.setAccessibleText("accessible");
assertSchemaMatch(fileUpload);
assertXpathEvaluatesTo(fileUpload.getAccessibleText(), "//ui:multifileupload/@accessibleText", fileUpload);
fileUpload.setFileTypes(new String[] { "a/b", "c/d" });
assertXpathEvaluatesTo("a/b,c/d", "//ui:multifileupload/@acceptedMimeTypes", fileUpload);
fileUpload.setMaxFileSize(12345);
assertXpathEvaluatesTo("12345", "//ui:multifileupload/@maxFileSize", fileUpload);
fileUpload.setMaxFiles(11);
assertXpathEvaluatesTo("11", "//ui:multifileupload/@maxFiles", fileUpload);
// Test file rendering
MockFileItem fileItem = new MockFileItem();
fileItem.setName("test.bin");
fileItem.setContentType("application/octet-stream");
fileItem.set(new byte[123]);
FileWidgetUpload file = new FileWidgetUpload("X", new FileItemWrap(fileItem));
fileUpload.setData(Arrays.asList(file));
assertSchemaMatch(fileUpload);
assertXpathEvaluatesTo("1", "count(//ui:multifileupload/ui:file)", fileUpload);
assertXpathEvaluatesTo("X", "//ui:multifileupload/ui:file/@id", fileUpload);
assertXpathEvaluatesTo(fileItem.getName(), "//ui:multifileupload/ui:file/@name", fileUpload);
assertXpathEvaluatesTo(fileItem.getContentType(), "//ui:multifileupload/ui:file/@type", fileUpload);
assertXpathEvaluatesTo(String.valueOf(fileItem.getSize()), "//ui:multifileupload/ui:file/@size", fileUpload);
}
Aggregations