/** * @param margin the margin to include on the panel. * @return the panel with a margin. */ private WPanel createPanel(final Margin margin) { WText text = new WText(DUMMY_TEXT); text.setEncodeText(false); WPanel panel = new WPanel(WPanel.Type.BOX); panel.add(text); panel.setMargin(margin); return panel; } }
/** * Convenience method to create a WPanel with the given title and text. * * @param title the panel title. * @param text the panel text. * @return a new WPanel with the given title and text. */ private WPanel createPanelWithText(final String title, final String text) { WPanel panel = new WPanel(WPanel.Type.CHROME); panel.setTitleText(title); WText textComponent = new WText(text); textComponent.setEncodeText(false); panel.add(textComponent); return panel; } }
/** * @param content the test content */ public TestComp(final String content) { WText text = new WText(content); text.setEncodeText(false); add(text); } }
/** * Construct example. */ public WSessionExample() { WMessages messages = new WMessages(true); messages .info("If \"ui:session\" is supported by the theme, wait 180 seconds to see a warning message and then a session expired message."); add(messages); WText txtSession = new WText() { @Override public String getText() { return "<ui:session timeout=\"180\" />"; } }; txtSession.setEncodeText(false); add(txtSession); } }
@Test public void testRenderWithXML() { WText text = new WText(TransformXMLTestHelper.TEST_XML); text.setEncodeText(false); String output = WebUtilities.render(text); Assert.assertEquals("Invalid output with XML", TransformXMLTestHelper.TEST_XML, output); }
@Test public void testNoSanitizeOnOutput() { String input = "<form>content</form>"; WText text = new WText(input); text.setEncodeText(false); Assert.assertEquals("Expect output to not be sanitized", input, text.getText()); }
/** * Creates a SourcePanel. */ public SourcePanel() { source.setEncodeText(false); WTemplate template = new WTemplate("/com/github/bordertech/wcomponents/examples/picker/sourceView.vm", TemplateRendererFactory.TemplateEngine.VELOCITY); add(template); template.addTaggedComponent("src", source); template.addTaggedComponent("script1", script1Url); template.addTaggedComponent("script2", script2Url); template.addTaggedComponent("css", cssUrl); }
@Test public void testSanitizeOnOutput() { WText text = new WText("<form>content</form>"); text.setSanitizeOnOutput(true); text.setEncodeText(false); Assert.assertEquals("Expect output to be sanitized", "content", text.getText()); } }
@Test public void testEncodeText() throws IOException, SAXException, XpathException { String value = "T1<b>T2</b>T3"; String encoded = WebUtilities.encode(value); WText text = new WText(); text.setText(value); // Encoded (default) String xml = toXHtml(text); Assert.assertTrue("XML should have encoded text", xml.contains(encoded)); // Not encoded text.setEncodeText(false); xml = toXHtml(text); Assert.assertTrue("XML should have not encoded text", xml.contains(value)); }
@Test public void testRenderToHtmlWithXML() { WText text = new WText(TransformXMLTestHelper.TEST_XML); text.setEncodeText(false); // Dont use PageShell as it wraps the XML with ui:root and test xslt does not pass the other tags String output = WebUtilities.renderWithTransformToHTML(new MockRequest(), text, false); Assert.assertEquals("Invalid html output with XML", TransformXMLTestHelper.EXPECTED, output); } @Test
/** * Adds a tab. * * @param card the tab content. * @param name the tab name. */ public void addTab(final WComponent card, final String name) { WContainer titledCard = new WContainer(); WText title = new WText("<b>[" + name + "]:</b><br/>"); title.setEncodeText(false); titledCard.add(title); titledCard.add(card); deck.add(titledCard); final TabButton button = new TabButton(name, titledCard); button.setAction(new Action() { @Override public void execute(final ActionEvent event) { deck.makeVisible(button.getAssociatedCard()); } }); btnPanel.add(button); }
/** * Creates a HtmlInjector. */ public HtmlInjector() { final WTextArea htmlEditor = new WTextArea(); htmlEditor.setRows(8); htmlEditor.setColumns(80); final WText injectedHtml = new WText(); injectedHtml.setEncodeText(false); // This disables text escaping, and can lead to XSS attacks WButton injectBtn = new WButton("Inject"); injectBtn.setAction(new Action() { @Override public void execute(final ActionEvent event) { String html = htmlEditor.getText(); injectedHtml.setText(html); } }); WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED); add(layout); layout.addField("Enter HTML", htmlEditor); layout.addField(injectBtn); WPanel injectedHtmlPanel = new WPanel(WPanel.Type.BOX); injectedHtmlPanel.add(injectedHtml); add(injectedHtmlPanel); } }
/** * Creates a WPanelExample. */ public WPanelExample() { int index = 0; for (WPanel.Type panelType : WPanel.Type.values()) { if (index++ > 0) { add(new WHorizontalRule()); } add(new WHeading(WHeading.SECTION, panelType.toString())); WPanel panel = new WPanel(panelType); panel.setTitleText("Panel title"); // This is bad - use a layout instead WText text = new WText("Panel text<br />"); text.setEncodeText(false); panel.add(text); WButton button = new WButton("Panel button"); button.setRenderAsLink(true); panel.add(button); panel.setDefaultSubmitButton(button); add(panel); } } }
/** * Creates a WDropdownSubmitOnChangeExample. */ public WDropdownSubmitOnChangeExample() { actMessage.setEncodeText(false); add(new ExplanatoryText("Any form control component which is not a WButton will show a visible warning in its label if its " + "submitOnChange property is set true.")); WFieldLayout flay = new WFieldLayout(); add(flay); flay.setLabelWidth(25); flay.setMargin(new Margin(null, null, Size.LARGE, null)); flay.addField("State", stateSelector).getLabel().setHint("Selecting a state will update the available regions."); flay.addField("Region", regionSelector); // Used to test control of visibility as part of submit on change. add(actMessage); actMessage.setVisible(false); stateSelector.setOptions(new String[]{null, STATE_ACT, STATE_NSW, STATE_VIC}); //This is the flag which causes accessibility problems. It may be removed completely in future versions of WComponents. //you should use AJAX instead stateSelector.setSubmitOnChange(true); stateSelector.setActionOnChange(new Action() { @Override public void execute(final ActionEvent event) { updateRegion(); regionSelector.resetData(); } }); regionSelector.setSubmitOnChange(true); }
/** * Creates a WTabAndCollapsibleExample. */ public WTabAndCollapsibleExample() { setLayout(new FlowLayout(Alignment.VERTICAL)); WContainer tab0 = new WContainer(); tab0.add(new WCollapsible(new WText("The first collapsed content."), "Client Collapsed Content 1")); tab0.add(newVisibilityToggleForTab(1)); // This is bad - use a layout instead WText lineBreak = new WText("<br />"); lineBreak.setEncodeText(false); tab0.add(lineBreak); tab0.add(newVisibilityToggleForTab(3)); WComponent tab1 = new WCollapsible(new WText("The second collapsed content."), "Client Collapsed Content 2"); WComponent tab2 = new WText("Three"); WComponent tab3 = new WText("Four"); tabset = new WTabSet(); tabset.addTab(tab0, "First tab", WTabSet.TAB_MODE_SERVER); tabset.addTab(tab1, "Second tab", WTabSet.TAB_MODE_SERVER); tabset.addTab(tab2, "Third tab", WTabSet.TAB_MODE_SERVER); tabset.addTab(tab3, "Fourth tab", WTabSet.TAB_MODE_SERVER); // Default the last tab to invisible. tabset.setTabVisible(tab3, false); add(tabset); }
cssText.setEncodeText(false); add(cssText); add(new WHorizontalRule());
add(new WHeading(HeadingLevel.H2, "Unencoded text containing a HTML character entity")); WText unescapedWithEntity = new WText("•"); unescapedWithEntity.setEncodeText(false); add(unescapedWithEntity);
+ " <li>Date Field 2 must be a valid date (lenient) and must be after or equal to Date Field 1.</li>" + "</ul>"); overview.setEncodeText(false); add(overview);
setDefaultSubmitButton(button); WText cssText = new WText("<style type='text/css'>.bigText{font-size:3em;}</style>"); cssText.setEncodeText(false); add(cssText);