use of com.github.bordertech.wcomponents.WLink in project wcomponents by BorderTech.
the class LinkOptionsExample method applySettings.
/**
* this is were the majority of the work is done for building the link. Note that it is in a container that is
* reset, effectively creating a new link. this is only done to enable to dynamically change the link to a button
* and back.
*/
private void applySettings() {
linkContainer.reset();
WLink exampleLink = new WLink();
exampleLink.setText(tfLinkLabel.getText());
final String url = tfUrlField.getValue();
if ("".equals(url) || !isValidUrl(url)) {
tfUrlField.setText(URL);
exampleLink.setUrl(URL);
} else {
exampleLink.setUrl(url);
}
exampleLink.setRenderAsButton(cbRenderAsButton.isSelected());
exampleLink.setText(tfLinkLabel.getText());
if (cbSetImage.isSelected()) {
WImage linkImage = new WImage("/image/attachment.png", "Add attachment");
exampleLink.setImage(linkImage.getImage());
exampleLink.setImagePosition((ImagePosition) ddImagePosition.getSelected());
}
exampleLink.setDisabled(cbDisabled.isSelected());
if (tfAccesskey.getText() != null && tfAccesskey.getText().length() > 0) {
exampleLink.setAccessKey(tfAccesskey.getText().toCharArray()[0]);
}
if (cbOpenNew.isSelected()) {
exampleLink.setOpenNewWindow(true);
exampleLink.setTargetWindowName("_blank");
} else {
exampleLink.setOpenNewWindow(false);
}
linkContainer.add(exampleLink);
}
use of com.github.bordertech.wcomponents.WLink in project wcomponents by BorderTech.
the class WLinkRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WLink link = new WLink(getMaliciousContent(), "#");
link.setRel(getMaliciousAttribute("ui:link"));
assertSafeContent(link);
link.setToolTip(getMaliciousAttribute("ui:link"));
assertSafeContent(link);
link.setAccessibleText(getMaliciousAttribute("ui:link"));
assertSafeContent(link);
link.setUrl(getMaliciousAttribute());
assertSafeContent(link);
}
use of com.github.bordertech.wcomponents.WLink in project wcomponents by BorderTech.
the class WLinkRenderer_Test method testWindowFlags.
@Test
public void testWindowFlags() throws IOException, SAXException, XpathException {
WLink link = new WLink.Builder(TEXT, LINK_URL).build();
assertSchemaMatch(link);
assertXpathEvaluatesTo(TEXT, "normalize-space(//ui:link)", link);
assertXpathUrlEvaluatesTo(LINK_URL, "//ui:link/@url", link);
assertXpathNotExists("//ui:link/ui:windowAttributes/@resizable", link);
assertXpathNotExists("//ui:link/ui:windowAttributes/@showMenubar", link);
assertXpathNotExists("//ui:link/ui:windowAttributes/@showToolbar", link);
assertXpathNotExists("//ui:link/ui:windowAttributes/@showLocation", link);
assertXpathNotExists("//ui:link/ui:windowAttributes/@showStatus", link);
assertXpathNotExists("//ui:link/ui:windowAttributes/@showScrollbars", link);
assertXpathNotExists("//ui:link/ui:windowAttributes/@showDirectories", link);
link = new WLink.Builder(TEXT, LINK_URL).resizable(true).menubar(true).toolbar(true).location(true).status(true).scrollbars(true).directories(true).build();
assertSchemaMatch(link);
assertXpathEvaluatesTo(TEXT, "normalize-space(//ui:link)", link);
assertXpathUrlEvaluatesTo(LINK_URL, "//ui:link/@url", link);
assertXpathEvaluatesTo("true", "//ui:link/ui:windowAttributes/@resizable", link);
assertXpathEvaluatesTo("true", "//ui:link/ui:windowAttributes/@showMenubar", link);
assertXpathEvaluatesTo("true", "//ui:link/ui:windowAttributes/@showToolbar", link);
assertXpathEvaluatesTo("true", "//ui:link/ui:windowAttributes/@showLocation", link);
assertXpathEvaluatesTo("true", "//ui:link/ui:windowAttributes/@showStatus", link);
assertXpathEvaluatesTo("true", "//ui:link/ui:windowAttributes/@showScrollbars", link);
assertXpathEvaluatesTo("true", "//ui:link/ui:windowAttributes/@showDirectories", link);
}
use of com.github.bordertech.wcomponents.WLink in project wcomponents by BorderTech.
the class WLinkRenderer_Test method testDoPaintWithAction.
@Test
public void testDoPaintWithAction() throws IOException, SAXException, XpathException {
WContainer root = new WContainer();
WLink link = new WLink("test", "http://test");
WPanel target1 = new WPanel();
WPanel target2 = new WPanel();
root.add(link);
root.add(target1);
root.add(target2);
// No Targets (target itself)
link.setAction(new TestAction());
assertSchemaMatch(root);
assertXpathEvaluatesTo(link.getId(), "//ui:ajaxtrigger/@triggerId", root);
assertXpathEvaluatesTo("1", "count(//ui:ajaxtrigger/ui:ajaxtargetid)", root);
assertXpathEvaluatesTo(link.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[1]/@targetId", root);
// With Targets
link.setAction(new TestAction(), target1, target2);
assertSchemaMatch(root);
assertXpathEvaluatesTo(link.getId(), "//ui:ajaxtrigger/@triggerId", root);
assertXpathEvaluatesTo("2", "count(//ui:ajaxtrigger/ui:ajaxtargetid)", root);
assertXpathEvaluatesTo(target1.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[1]/@targetId", root);
assertXpathEvaluatesTo(target2.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[2]/@targetId", root);
}
Aggregations