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");
}
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));
}
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);
}
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);
}
Aggregations