Search in sources :

Example 1 with WTab

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

the class WTabRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WTabSet tabSet = new WTabSet();
    WTab tab = tabSet.addTab(new WText("dummy"), getMaliciousContent(), TabMode.CLIENT);
    assertSafeContent(tabSet);
    tab.setToolTip(getMaliciousAttribute("ui:tab"));
    assertSafeContent(tabSet);
    tab.setAccessibleText(getMaliciousAttribute("ui:tab"));
    assertSafeContent(tabSet);
}
Also used : WText(com.github.bordertech.wcomponents.WText) WTab(com.github.bordertech.wcomponents.WTab) WTabSet(com.github.bordertech.wcomponents.WTabSet) Test(org.junit.Test)

Example 2 with WTab

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

the class WTabRenderer method doRender.

/**
 * Paints the given WTab.
 *
 * @param component the WTab to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTab tab = (WTab) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:tab");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("open", tab.isOpen(), "true");
    xml.appendOptionalAttribute("disabled", tab.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", tab.isHidden(), "true");
    xml.appendOptionalAttribute("toolTip", tab.getToolTip());
    switch(tab.getMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case LAZY:
            xml.appendAttribute("mode", "lazy");
            break;
        case EAGER:
            xml.appendAttribute("mode", "eager");
            break;
        case DYNAMIC:
            xml.appendAttribute("mode", "dynamic");
            break;
        case SERVER:
            xml.appendAttribute("mode", "server");
            break;
        default:
            throw new SystemException("Unknown tab mode: " + tab.getMode());
    }
    if (tab.getAccessKey() != 0) {
        xml.appendAttribute("accessKey", String.valueOf(Character.toUpperCase(tab.getAccessKey())));
    }
    xml.appendClose();
    // Paint label
    tab.getTabLabel().paint(renderContext);
    // Paint content
    WComponent content = tab.getContent();
    xml.appendTagOpen("ui:tabcontent");
    xml.appendAttribute("id", tab.getId() + "-content");
    xml.appendClose();
    // Render content if not EAGER Mode or is EAGER and is the current AJAX trigger
    if (content != null && (TabMode.EAGER != tab.getMode() || AjaxHelper.isCurrentAjaxTrigger(tab))) {
        // Visibility of content set in prepare paint
        content.paint(renderContext);
    }
    xml.appendEndTag("ui:tabcontent");
    xml.appendEndTag("ui:tab");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) WTab(com.github.bordertech.wcomponents.WTab) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 3 with WTab

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

the class WTabRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WTabSet tabSet = new WTabSet();
    tabSet.addTab(new WText(""), "", TabMode.DYNAMIC);
    WTab tab = tabSet.getTab(0);
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(tab) instanceof WTabRenderer);
}
Also used : WText(com.github.bordertech.wcomponents.WText) WTab(com.github.bordertech.wcomponents.WTab) WTabSet(com.github.bordertech.wcomponents.WTabSet) Test(org.junit.Test)

Example 4 with WTab

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

the class WTabRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    String tabName = "WTabRenderer_Test.testDoPaint.tabName";
    String tabContent = "WTabRenderer_Test.testDoPaint.tabContent";
    WTabSet tabSet = new WTabSet();
    WTab tab = tabSet.addTab(new WText(tabContent), tabName, TabMode.CLIENT);
    assertXpathExists("//ui:tab", tabSet);
    assertXpathEvaluatesTo(tab.getId(), "//ui:tab/@id", tabSet);
    assertXpathEvaluatesTo(tabName, "normalize-space(//ui:tab/ui:decoratedlabel)", tabSet);
    assertXpathEvaluatesTo(tabContent, "normalize-space(//ui:tab/ui:tabcontent)", tabSet);
    assertXpathEvaluatesTo("true", "//ui:tab/@open", tabSet);
    assertXpathEvaluatesTo("client", "//ui:tab/@mode", tabSet);
    assertXpathNotExists("//ui:tab/@disabled", tabSet);
    assertXpathNotExists("//ui:tab/@accessKey", tabSet);
    tab.setDisabled(true);
    assertXpathEvaluatesTo("true", "//ui:tab/@disabled", tabSet);
    tabSet.remove(tab);
    tab = tabSet.addTab(new WText(tabContent), tabName, TabMode.LAZY);
    assertXpathEvaluatesTo(tab.getId(), "//ui:tab/@id", tabSet);
    assertXpathEvaluatesTo(tabName, "normalize-space(//ui:tab/ui:decoratedlabel)", tabSet);
    assertXpathEvaluatesTo(tabContent, "normalize-space(//ui:tab/ui:tabcontent)", tabSet);
    assertXpathEvaluatesTo("true", "//ui:tab/@open", tabSet);
    assertXpathEvaluatesTo("lazy", "//ui:tab/@mode", tabSet);
    assertXpathNotExists("//ui:tab/@disabled", tabSet);
    tabSet.remove(tab);
    tab = tabSet.addTab(new WText(tabContent), tabName, TabMode.EAGER);
    assertXpathEvaluatesTo("eager", "//ui:tab/@mode", tabSet);
    tabSet.remove(tab);
    tab = tabSet.addTab(new WText(tabContent), tabName, TabMode.DYNAMIC);
    assertXpathEvaluatesTo("dynamic", "//ui:tab/@mode", tabSet);
    tabSet.remove(tab);
    tab = tabSet.addTab(new WText(tabContent), tabName, TabMode.SERVER, 'X');
    assertXpathEvaluatesTo("dynamic", "//ui:tab/@mode", tabSet);
    assertXpathEvaluatesTo(String.valueOf(tab.getAccessKey()), "//ui:tab/@accessKey", tabSet);
    tabSet.remove(tab);
    tab = tabSet.addTab(new WText(tabContent), tabName, TabMode.CLIENT);
    tab.setToolTip("Title");
    assertXpathEvaluatesTo(String.valueOf(tab.getToolTip()), "//ui:tab/@toolTip", tabSet);
}
Also used : WText(com.github.bordertech.wcomponents.WText) WTab(com.github.bordertech.wcomponents.WTab) WTabSet(com.github.bordertech.wcomponents.WTabSet) Test(org.junit.Test)

Aggregations

WTab (com.github.bordertech.wcomponents.WTab)4 WTabSet (com.github.bordertech.wcomponents.WTabSet)3 WText (com.github.bordertech.wcomponents.WText)3 Test (org.junit.Test)3 WComponent (com.github.bordertech.wcomponents.WComponent)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1