Search in sources :

Example 1 with WMultiFileWidget

use of com.github.bordertech.wcomponents.WMultiFileWidget in project wcomponents by BorderTech.

the class WMultiFileWidgetRenderer_Test method testReadOnly.

@Test
public void testReadOnly() throws IOException, SAXException, XpathException {
    WMultiFileWidget fileUpload = new WMultiFileWidget();
    fileUpload.setReadOnly(true);
    assertSchemaMatch(fileUpload);
    assertXpathEvaluatesTo("true", "//ui:multifileupload/@readOnly", fileUpload);
}
Also used : WMultiFileWidget(com.github.bordertech.wcomponents.WMultiFileWidget) Test(org.junit.Test)

Example 2 with WMultiFileWidget

use of com.github.bordertech.wcomponents.WMultiFileWidget in project wcomponents by BorderTech.

the class WMultiFileWidgetRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WMultiFileWidget fileUpload = new WMultiFileWidget();
    fileUpload.setFileTypes(new String[] { getMaliciousAttribute("ui:multifileupload") });
    assertSafeContent(fileUpload);
    fileUpload.setToolTip(getMaliciousAttribute("ui:multifileupload"));
    assertSafeContent(fileUpload);
    fileUpload.setAccessibleText(getMaliciousAttribute("ui:multifileupload"));
    assertSafeContent(fileUpload);
}
Also used : WMultiFileWidget(com.github.bordertech.wcomponents.WMultiFileWidget) Test(org.junit.Test)

Example 3 with WMultiFileWidget

use of com.github.bordertech.wcomponents.WMultiFileWidget in project wcomponents by BorderTech.

the class WMultiFileWidgetRenderer method doRender.

/**
 * Paints the given WMultiFileWidget.
 *
 * @param component the WMultiFileWidget to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMultiFileWidget widget = (WMultiFileWidget) component;
    XmlStringBuilder xml = renderContext.getWriter();
    // Check if rendering a file upload response
    String uploadId = widget.getFileUploadRequestId();
    if (uploadId != null) {
        handleFileUploadRequest(widget, xml, uploadId);
        return;
    }
    boolean readOnly = widget.isReadOnly();
    xml.appendTagOpen(TAG_NAME);
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", widget.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        long maxFileSize = widget.getMaxFileSize();
        int maxFiles = widget.getMaxFiles();
        WComponent dropzone = widget.getDropzone();
        WImageEditor editor = widget.getEditor();
        xml.appendOptionalAttribute("disabled", widget.isDisabled(), "true");
        xml.appendOptionalAttribute("required", widget.isMandatory(), "true");
        xml.appendOptionalAttribute("toolTip", widget.getToolTip());
        xml.appendOptionalAttribute("accessibleText", widget.getAccessibleText());
        xml.appendOptionalAttribute("acceptedMimeTypes", typesToString(widget.getFileTypes()));
        xml.appendOptionalAttribute("maxFileSize", maxFileSize > 0, maxFileSize);
        xml.appendOptionalAttribute("maxFiles", maxFiles > 0, maxFiles);
        if (dropzone != null) {
            xml.appendAttribute("dropzone", dropzone.getId());
        }
        if (editor != null) {
            xml.appendAttribute("editor", editor.getId());
            if (editor.getUseCamera()) {
                xml.appendAttribute("camera", true);
            }
        }
    }
    if (widget.getColumns() != null) {
        xml.appendAttribute("cols", widget.getColumns());
    }
    if (widget.getFileAjaxAction() != null) {
        xml.appendAttribute("ajax", "true");
    }
    List<Diagnostic> diags = readOnly ? null : widget.getDiagnostics(Diagnostic.ERROR);
    if (widget.getFiles().isEmpty()) {
        if (readOnly || diags == null || diags.isEmpty()) {
            xml.appendEnd();
            return;
        }
        xml.appendClose();
    } else {
        xml.appendClose();
        // Render files
        int i = 0;
        for (FileWidgetUpload file : widget.getFiles()) {
            FileWidgetRendererUtil.renderFileElement(widget, xml, file, i++);
        }
    }
    if (!readOnly && diags != null && !diags.isEmpty()) {
        DiagnosticRenderUtil.renderDiagnostics(widget, renderContext);
    }
    xml.appendEndTag(TAG_NAME);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WImageEditor(com.github.bordertech.wcomponents.WImageEditor) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WMultiFileWidget(com.github.bordertech.wcomponents.WMultiFileWidget) FileWidgetUpload(com.github.bordertech.wcomponents.WMultiFileWidget.FileWidgetUpload) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 4 with WMultiFileWidget

use of com.github.bordertech.wcomponents.WMultiFileWidget in project wcomponents by BorderTech.

the class WLabelRenderer_Test method testWhatForGroup7.

@Test
public void testWhatForGroup7() throws IOException, SAXException, XpathException {
    WMultiFileWidget comp = new WMultiFileWidget();
    WLabel label = new WLabel("label", comp);
    assertSchemaMatch(label);
    assertXpathEvaluatesTo("group", "//ui:label/@what", label);
}
Also used : WMultiFileWidget(com.github.bordertech.wcomponents.WMultiFileWidget) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 5 with WMultiFileWidget

use of com.github.bordertech.wcomponents.WMultiFileWidget in project wcomponents by BorderTech.

the class WMultiFileWidgetRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WMultiFileWidget fileUpload = new WMultiFileWidget();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(fileUpload) instanceof WMultiFileWidgetRenderer);
}
Also used : WMultiFileWidget(com.github.bordertech.wcomponents.WMultiFileWidget) Test(org.junit.Test)

Aggregations

WMultiFileWidget (com.github.bordertech.wcomponents.WMultiFileWidget)6 Test (org.junit.Test)5 FileWidgetUpload (com.github.bordertech.wcomponents.WMultiFileWidget.FileWidgetUpload)2 WComponent (com.github.bordertech.wcomponents.WComponent)1 WImageEditor (com.github.bordertech.wcomponents.WImageEditor)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 FileItemWrap (com.github.bordertech.wcomponents.file.FileItemWrap)1 MockFileItem (com.github.bordertech.wcomponents.util.mock.MockFileItem)1 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)1