Search in sources :

Example 1 with WFileWidget

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

the class WFileWidgetRenderer method doRender.

/**
 * Paints the given WFileWidget.
 *
 * @param component the WFileWidget to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WFileWidget fileWidget = (WFileWidget) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = fileWidget.isReadOnly();
    xml.appendTagOpen(TAG_NAME);
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
        xml.appendEnd();
        return;
    }
    xml.appendOptionalAttribute("disabled", fileWidget.isDisabled(), "true");
    xml.appendOptionalAttribute("required", fileWidget.isMandatory(), "true");
    xml.appendOptionalAttribute("toolTip", fileWidget.getToolTip());
    xml.appendOptionalAttribute("accessibleText", fileWidget.getAccessibleText());
    xml.appendOptionalAttribute("acceptedMimeTypes", typesToString(fileWidget.getFileTypes()));
    long maxFileSize = fileWidget.getMaxFileSize();
    xml.appendOptionalAttribute("maxFileSize", maxFileSize > 0, maxFileSize);
    List<Diagnostic> diags = fileWidget.getDiagnostics(Diagnostic.ERROR);
    if (diags == null || diags.isEmpty()) {
        xml.appendEnd();
        return;
    }
    xml.appendClose();
    DiagnosticRenderUtil.renderDiagnostics(fileWidget, renderContext);
    xml.appendEndTag(TAG_NAME);
}
Also used : WFileWidget(com.github.bordertech.wcomponents.WFileWidget) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 2 with WFileWidget

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

the class WFileWidgetRenderer_Test method testRendererCorrectlyConfigured.

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

Example 3 with WFileWidget

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

the class WFileWidgetRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WFileWidget fileUpload = new WFileWidget();
    assertSchemaMatch(fileUpload);
    assertXpathEvaluatesTo(fileUpload.getId(), "//ui:fileupload/@id", fileUpload);
    assertXpathNotExists("//ui:fileupload/@disabled", fileUpload);
    assertXpathNotExists("//ui:fileupload/@hidden", fileUpload);
    assertXpathNotExists("//ui:fileupload/@required", fileUpload);
    assertXpathNotExists("//ui:fileupload/@readOnly", fileUpload);
    assertXpathNotExists("//ui:fileupload/@toolTip", fileUpload);
    assertXpathNotExists("//ui:fileupload/@accessibleText", fileUpload);
    assertXpathNotExists("//ui:fileupload/@acceptedMimeTypes", fileUpload);
    assertXpathNotExists("//ui:fileupload/@maxFileSize", fileUpload);
    fileUpload.setDisabled(true);
    assertSchemaMatch(fileUpload);
    assertXpathEvaluatesTo("true", "//ui:fileupload/@disabled", fileUpload);
    setFlag(fileUpload, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(fileUpload);
    assertXpathEvaluatesTo("true", "//ui:fileupload/@hidden", fileUpload);
    fileUpload.setMandatory(true);
    assertSchemaMatch(fileUpload);
    assertXpathEvaluatesTo("true", "//ui:fileupload/@required", fileUpload);
    fileUpload.setToolTip("tooltip");
    assertSchemaMatch(fileUpload);
    assertXpathEvaluatesTo(fileUpload.getToolTip(), "//ui:fileupload/@toolTip", fileUpload);
    fileUpload.setAccessibleText("accessible");
    assertSchemaMatch(fileUpload);
    assertXpathEvaluatesTo(fileUpload.getAccessibleText(), "//ui:fileupload/@accessibleText", fileUpload);
    fileUpload.setFileTypes(new String[] { "a/b", "c/d" });
    assertXpathEvaluatesTo("a/b,c/d", "//ui:fileupload/@acceptedMimeTypes", fileUpload);
    fileUpload.setMaxFileSize(12345);
    assertXpathEvaluatesTo("12345", "//ui:fileupload/@maxFileSize", fileUpload);
}
Also used : WFileWidget(com.github.bordertech.wcomponents.WFileWidget) Test(org.junit.Test)

Example 4 with WFileWidget

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

the class WFileWidgetRenderer_Test method testXssEscaping.

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

Example 5 with WFileWidget

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

the class WFileWidgetRenderer_Test method testReadOnly.

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

Aggregations

WFileWidget (com.github.bordertech.wcomponents.WFileWidget)5 Test (org.junit.Test)4 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)1