Search in sources :

Example 1 with WInternalLink

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

the class WInternalLinkRenderer method doRender.

/**
 * Paints the given {@link WInternalLink}.
 *
 * @param component the WInternalLink to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WInternalLink link = (WInternalLink) component;
    XmlStringBuilder xml = renderContext.getWriter();
    if (Util.empty(link.getText())) {
        return;
    }
    xml.appendTagOpen("ui:link");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("toolTip", link.getToolTip());
    xml.appendOptionalAttribute("accessibleText", link.getAccessibleText());
    xml.appendUrlAttribute("url", "#" + link.getReference().getId());
    xml.appendClose();
    xml.appendEscaped(link.getText());
    xml.appendEndTag("ui:link");
}
Also used : WInternalLink(com.github.bordertech.wcomponents.WInternalLink) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 2 with WInternalLink

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

the class WInternalLinkRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WPanel refer = new WPanel();
    WInternalLink link = new WInternalLink();
    WContainer root = new WContainer();
    root.add(refer);
    root.add(link);
    String linkText = "TEXT TEST";
    String linkTip = "TIP TEST";
    String linkAccessibleText = "ACCESS TEST";
    link.setText(linkText);
    link.setReference(refer);
    assertSchemaMatch(link);
    assertXpathEvaluatesTo(link.getId(), "//ui:link/@id", link);
    assertXpathUrlEvaluatesTo("#" + refer.getId(), "//ui:link/@url", link);
    assertXpathEvaluatesTo(linkText, "//ui:link", link);
    assertXpathNotExists("//ui:link/@type", link);
    assertXpathNotExists("//ui:link/@toolTip", link);
    assertXpathNotExists("//ui:link/@accessibleText", link);
    link.setToolTip(linkTip);
    link.setAccessibleText(linkAccessibleText);
    assertSchemaMatch(link);
    assertXpathEvaluatesTo(linkTip, "//ui:link/@toolTip", link);
    assertXpathEvaluatesTo(linkAccessibleText, "//ui:link/@accessibleText", link);
    link.setText(null);
    Assert.assertEquals("A link with no text should not render any output", "", render(link));
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WInternalLink(com.github.bordertech.wcomponents.WInternalLink) WPanel(com.github.bordertech.wcomponents.WPanel) Test(org.junit.Test)

Example 3 with WInternalLink

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

the class WInternalLinkRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WInternalLink link = new WInternalLink(getMaliciousContent(), new DefaultWComponent());
    assertSafeContent(link);
    link.setToolTip(getMaliciousAttribute("ui:link"));
    assertSafeContent(link);
    link.setAccessibleText(getMaliciousAttribute("ui:link"));
    assertSafeContent(link);
}
Also used : WInternalLink(com.github.bordertech.wcomponents.WInternalLink) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 4 with WInternalLink

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

the class WInternalLinkRenderer_Test method testRendererCorrectlyConfigured.

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

Aggregations

WInternalLink (com.github.bordertech.wcomponents.WInternalLink)4 Test (org.junit.Test)3 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WPanel (com.github.bordertech.wcomponents.WPanel)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1