gpt4 book ai didi

com.github.bordertech.wcomponents.WText.setEncodeText()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-25 16:51:05 28 4
gpt4 key购买 nike

本文整理了Java中com.github.bordertech.wcomponents.WText.setEncodeText()方法的一些代码示例,展示了WText.setEncodeText()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WText.setEncodeText()方法的具体详情如下:
包路径:com.github.bordertech.wcomponents.WText
类名称:WText
方法名:setEncodeText

WText.setEncodeText介绍

[英]Sets whether the text needs to be encoded.

When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

WARNING: If you are using WText to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

WARNING: Avoid using WText to add excessive amounts of HTML mark-up to the UI. Embedded mark-up is more likely to break in future WComponent releases. If you are attempting to use WText for layout purposes, consider using a com.github.bordertech.wcomponents.layout.LayoutManager instead. For example, new WText("<br>") could be rewritten to use the com.github.bordertech.wcomponents.layout.FlowLayout layout with a vertical layout direction.
[中]设置文本是否需要编码。
当将encodeText设置为false时,应用程序将负责确保文本不包含任何需要转义的字符。
警告:如果使用WText显示“用户输入的”或不受信任的数据,在encodeText设置为false的情况下使用此方法可能会导致安全问题。
警告:避免使用WText在UI中添加过多的HTML标记。嵌入式标记更有可能在未来的WComponent版本中被打破。如果您试图使用WTEX进行布局,请考虑使用COM。github。博德科技。wcomponents。布局而不是经理。例如,new WText("<br>")可以重写以使用com。github。博德科技。wcomponents。布局具有垂直布局方向的FlowLayout布局。

代码示例

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

/**
   * @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;
  }
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

/**
   * 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;
  }
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

/**
   * @param content the test content
   */
  public TestComp(final String content) {
    WText text = new WText(content);
    text.setEncodeText(false);
    add(text);
  }
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

/**
   * 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);
  }
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

@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);
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

@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());
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

/**
 * 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);
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

@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());
  }
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

@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));
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

@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

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

/**
 * 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);
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

lineBreak.setEncodeText(false);

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

/**
   * 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);
  }
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

/**
   * 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);
    }
  }
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

/**
 * 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);
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

/**
 * 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);
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

cssText.setEncodeText(false);
add(cssText);
add(new WHorizontalRule());

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

add(new WHeading(HeadingLevel.H2, "Unencoded text containing a HTML character entity"));
WText unescapedWithEntity = new WText("&bull;");
unescapedWithEntity.setEncodeText(false);
add(unescapedWithEntity);

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

+ " <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);

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

setDefaultSubmitButton(button);
WText cssText = new WText("<style type='text/css'>.bigText{font-size:3em;}</style>");
cssText.setEncodeText(false);
add(cssText);

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com