gpt4 book ai didi

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

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

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

WebUtilities.encode介绍

[英]Encode all the special characters found in the given string to their escape sequences according to the XML specification, and returns the resultant string. Eg. "cat&dog > ant" becomes "cat&dog > ant".
[中]根据XML规范将给定字符串中的所有特殊字符编码为其转义序列,并返回结果字符串。例如,“猫和狗>蚂蚁”变成“猫和狗>蚂蚁”。

代码示例

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

/**
   * @param uic the current user context
   * @return the xml declaration with the theme processing instruction
   */
  public static String getXMLDeclarationWithThemeXslt(final UIContext uic) {
    String theme = WebUtilities.encode(ThemeUtil.getThemeXslt(uic));
    String dec = XML_DECLARATION + "\n<?xml-stylesheet type=\"text/xsl\" href=\"" + theme + "\"?>";
    return dec;
  }
}

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

/**
   * Sets the source code to be displayed in the panel.
   *
   * @param sourceText the source code to display.
   */
  public void setSource(final String sourceText) {
    String formattedSource;

    if (sourceText == null) {
      formattedSource = "";
    } else {
      formattedSource = WebUtilities.encode(sourceText); // XML escape content
    }

    source.setText(formattedSource);
  }
}

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

/**
   * Override in order to paint the component. Real applications should not emit HTML directly.
   *
   * @param renderContext the renderContext to send output to.
   */
  @Override
  protected void afterPaint(final RenderContext renderContext) {
    if (renderContext instanceof WebXmlRenderContext) {
      PrintWriter writer = ((WebXmlRenderContext) renderContext).getWriter();
      writer.println(WebUtilities.encode(message));

      if (error != null) {
        writer.println("\n<br/>\n<pre>\n");

        StringWriter buf = new StringWriter();
        error.printStackTrace(new PrintWriter(buf));
        writer.println(WebUtilities.encode(buf.toString()));

        writer.println("\n</pre>");
      }
    }
  }
}

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

/**
 * {@inheritDoc}
 */
@Override
public void renderInline(final String templateInline, final Map<String, Object> context, final Map<String, WComponent> taggedComponents,
    final Writer writer, final Map<String, Object> options) {
  LOG.debug("Rendering inline plain text template.");
  boolean xmlEncode = options.containsKey(XML_ENCODE);
  try {
    String output = templateInline;
    if (xmlEncode) {
      output = WebUtilities.encode(output);
    }
    writer.write(output);
  } catch (Exception e) {
    throw new SystemException("Problems with inline plain text template. " + e.getMessage(), e);
  }
}

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

/**
 * {@inheritDoc}
 */
@Override
public void openDoc(final PrintWriter writer) {
  UIContext uic = UIContextHolder.getCurrent();
  String title = getApplicationTitle(uic);
  writer.write(XMLUtil.getXMLDeclarationWithThemeXslt(uic));
  StringBuilder rootElement = new StringBuilder();
  rootElement.append("\n<ui:root title=\"");
  rootElement.append(WebUtilities.encode(title));
  rootElement.append("\" ");
  Locale locale = I18nUtilities.getEffectiveLocale();
  if (locale != null) {
    String lang = locale.toLanguageTag();
    if (lang != null) {
      rootElement.append("lang=\"");
      rootElement.append(WebUtilities.encode(locale.toLanguageTag()));
      rootElement.append("\" ");
    }
  }
  rootElement.append(XMLUtil.STANDARD_NAMESPACES);
  rootElement.append(">");
  writer.write(rootElement.toString());
}

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

/**
 * Encode URL for XML.
 *
 * @param urlStr the URL to escape
 * @return the URL percent encoded
 */
public static String encodeUrl(final String urlStr) {
  if (Util.empty(urlStr)) {
    return urlStr;
  }
  // Percent Encode
  String percentEncode = percentEncodeUrl(urlStr);
  // XML Enocde
  return encode(percentEncode);
}

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

@Test
public void testEncode() {
  Assert.assertEquals("Incorrectly encoded null string", null, WebUtilities.encode(null));
  Assert.assertEquals("Incorrectly encoded empty string", "", WebUtilities.encode(""));
  Assert.assertEquals("Incorrectly encoded 1 char string", "x", WebUtilities.encode("x"));
  Assert.assertEquals("Incorrectly encoded 1 special char string", "&amp;", WebUtilities.
      encode("&"));
  Assert.assertEquals("Incorrectly encoded open bracket", "&#123;", WebUtilities.encode("{"));
  Assert.assertEquals("Incorrectly encoded close bracket", "&#125;", WebUtilities.encode("}"));
  String in = "Hello world greater> less< amper& quote\"\t\r\n";
  String expected = "Hello world greater&gt; less&lt; amper&amp; quote&quot;\t\r\n";
  Assert.assertEquals("Incorrectly encoded value", expected, WebUtilities.encode(in));
  in = characterRange(0, 32);
  Assert.assertEquals("Encode should blat special characters", "\t\n\r ", WebUtilities.encode(in));
}

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

/**
 * Retrieves the list of messages.
 *
 * @return the messages for the current context.
 */
public List<String> getMessages() {
  MessageModel model = getComponentModel();
  List<String> messages = new ArrayList<>(model.messages.size());
  for (Duplet<Serializable, Boolean> message : model.messages) {
    String text = I18nUtilities.format(null, message.getFirst());
    // If we are outputting unencoded content it must be XML valid.
    boolean encode = message.getSecond();
    messages.add(encode ? WebUtilities.encode(text) : HtmlToXMLUtil.unescapeToXML(text));
  }
  return Collections.unmodifiableList(messages);
}

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

primitiveString = WebUtilities.encode(primitiveString);
xml.append(" value=\"").append(primitiveString).append('"');

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

/**
 * Appends the string to this XmlStringBuilder. XML values are not escaped.
 *
 * @param string the String to append.
 * @param encode true to encode the string before output, false to output as is
 */
public void append(final String string, final boolean encode) {
  if (encode) {
    appendOptional(WebUtilities.encode(string));
  } else {
    // unescaped content still has to be XML compliant.
    write(HtmlToXMLUtil.unescapeToXML(string));
  }
}

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

output = WebUtilities.encode(output);

代码示例来源: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-test-lib

return value.equals(((WRadioButton) component).getValue()) ? current : null;
} else {
  return current.findElement(By.xpath(".//*[@value='" + WebUtilities.encode(String.valueOf(value)) + "']"));

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

@Test
public void testDecode() {
  Assert.assertEquals("Incorrectly decoded null string", null, WebUtilities.decode(null));
  Assert.assertEquals("Incorrectly decoded empty string", "", WebUtilities.decode(""));
  Assert.assertEquals("Incorrectly decoded 1 char string", "x", WebUtilities.decode("x"));
  Assert.assertEquals("Incorrectly decoded 1 special char string", "&", WebUtilities.decode(
      "&amp;"));
  Assert.assertEquals("Incorrectly decoded open bracket", "{", WebUtilities.decode("&#123;"));
  Assert.assertEquals("Incorrectly decoded close bracket", "}", WebUtilities.decode("&#125;"));
  String in = "Hello world greater&gt; less&lt; amper&amp; quote&quot;";
  String expected = "Hello world greater> less< amper& quote\"";
  Assert.assertEquals("Incorrectly decoded value", expected, WebUtilities.decode(in));
  // Finally, check a encode/decode pair
  String encoded = WebUtilities.encode(expected);
  Assert.assertEquals("Incorrectly encoded/decoded value", expected, WebUtilities.decode(
      encoded));
}

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

/**
   * Paints the given WText.
   *
   * @param component the WText to paint.
   * @param renderContext the RenderContext to paint to.
   */
  @Override
  public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WText text = (WText) component;
    XmlStringBuilder xml = renderContext.getWriter();

    String textString = text.getText();

    if (textString != null) {
      if (text.isEncodeText()) {
        xml.print(WebUtilities.encode(textString));
      } else {
        // If we are outputting unencoded content it must be XML valid.
        xml.print(HtmlToXMLUtil.unescapeToXML(textString));
      }
    }
  }
}

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

writer.println(WebUtilities.encode(buf.toString()));
writer.println("\n</pre>");

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

@Test
public void testEncodeText() throws IOException, SAXException, XpathException {
  String text = "T1<b>T2</b>T3";
  String encoded = WebUtilities.encode(text);
  WMessageBox messageBox = new WMessageBox(WMessageBox.INFO);
  messageBox.addMessage(text);
  // Encoded (default)
  assertSchemaMatch(messageBox);
  String xml = toXHtml(messageBox);
  Assert.assertTrue("XML should have encoded message", xml.contains(encoded));
  // Not encoded
  messageBox.reset();
  messageBox.addMessage(false, text);
  assertSchemaMatch(messageBox);
  xml = toXHtml(messageBox);
  Assert.assertTrue("XML should have not encoded message", xml.contains(text));
}

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

@Test
  public void testExample() {
    // Launch the web browser to the LDE
    SeleniumWComponentsWebDriver driver = getDriver();

    String divText = "Hello world&";
    String html = "<div id='HtmlInjector_Test.id'>" + WebUtilities.encode(divText) + "</div>";

    driver.findWTextArea(byWComponentPath("WTextArea")).sendKeys(html);
    driver.findElement(byWComponentPath("WButton")).click();

    Assert.assertEquals("Incorrect div text", divText, driver.findElement(By.id("HtmlInjector_Test.id")).getText());
  }
}

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

xml.appendOptionalAttribute("isNull", isNull, "true");
xml.appendClose();
xml.append(WebUtilities.encode(LOOKUP_TABLE.getDescription(table, item)));
xml.appendEndTag("ui:option");

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

xml.appendOptionalAttribute("hidden", button.isHidden(), "true");
xml.appendAttribute("groupName", button.getGroupName());
xml.appendAttribute("value", WebUtilities.encode(value));
if (readOnly) {
  xml.appendAttribute("readOnly", "true");

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