org.apache.commons.text.StringEscapeUtils.unescapeHtml4()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(302)

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

StringEscapeUtils.unescapeHtml4介绍

暂无

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

while (params.hasMoreElements()) {
 String rawParam = params.nextElement();
 String param = StringEscapeUtils.unescapeHtml4(rawParam);
 String value =
  StringEscapeUtils.unescapeHtml4(req.getParameter(rawParam));
 if (value != null) {
  if (value.equals(newConf.getRaw(param)) || value.equals("default") ||

代码示例来源:origin: org.apache.commons/commons-text

@Test
public void testUnescapeHexCharsHtml() {
  // Simple easy to grok test
  assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"), "hex number unescape");
  assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"), "hex number unescape");
  // Test all Character values:
  for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
    final Character c1 = i;
    final Character c2 = (char) (i + 1);
    final String expected = c1.toString() + c2.toString();
    final String escapedC1 = "&#x" + Integer.toHexString(c1) + ";";
    final String escapedC2 = "&#x" + Integer.toHexString(c2) + ";";
    assertEquals(expected, StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2),
        "hex number unescape index " + i);
  }
}

代码示例来源:origin: org.apache.commons/commons-text

@Test
public void testLang313() {
  assertEquals("& &", StringEscapeUtils.unescapeHtml4("& &amp;"));
}

代码示例来源:origin: org.apache.commons/commons-text

@Test
public void testUnescapeHtml4() {
  for (final String[] element : HTML_ESCAPES) {
    final String message = element[0];
    final String expected = element[2];
    final String original = element[1];
    assertEquals(expected, StringEscapeUtils.unescapeHtml4(original), message);
    final StringWriter sw = new StringWriter();
    try {
      StringEscapeUtils.UNESCAPE_HTML4.translate(original, sw);
    } catch (final IOException e) {
    }
    final String actual = original == null ? null : sw.toString();
    assertEquals(expected, actual, message);
  }
  // \u00E7 is a cedilla (c with wiggle under)
  // note that the test string must be 7-bit-clean (Unicode escaped) or else it will compile incorrectly
  // on some locales
  assertEquals("Fran\u00E7ais", StringEscapeUtils.unescapeHtml4("Fran\u00E7ais"), "funny chars pass through OK");
  assertEquals("Hello&;World", StringEscapeUtils.unescapeHtml4("Hello&;World"));
  assertEquals("Hello&#;World", StringEscapeUtils.unescapeHtml4("Hello&#;World"));
  assertEquals("Hello&# ;World", StringEscapeUtils.unescapeHtml4("Hello&# ;World"));
  assertEquals("Hello&##;World", StringEscapeUtils.unescapeHtml4("Hello&##;World"));
}

代码示例来源:origin: org.apache.commons/commons-text

@Test
public void testUnescapeUnknownEntity() {
  assertEquals("&zzzz;", StringEscapeUtils.unescapeHtml4("&zzzz;"));
}

代码示例来源:origin: org.apache.commons/commons-text

/**
 * Tests // https://issues.apache.org/jira/browse/LANG-480
 */
@Test
public void testEscapeHtmlHighUnicode() {
  // this is the utf8 representation of the character:
  // COUNTING ROD UNIT DIGIT THREE
  // in Unicode
  // codepoint: U+1D362
  final byte[] data = {(byte) 0xF0, (byte) 0x9D, (byte) 0x8D, (byte) 0xA2};
  final String original = new String(data, Charset.forName("UTF8"));
  final String escaped = StringEscapeUtils.escapeHtml4(original);
  assertEquals(original, escaped, "High Unicode should not have been escaped");
  final String unescaped = StringEscapeUtils.unescapeHtml4(escaped);
  assertEquals(original, unescaped, "High Unicode should have been unchanged");
  // TODO: I think this should hold, needs further investigation
  //        String unescapedFromEntity = StringEscapeUtils.unescapeHtml4("&#119650;");
  //        assertEquals("High Unicode should have been unescaped", original, unescapedFromEntity);
}

代码示例来源:origin: org.apache.commons/commons-text

@Test
public void testStandaloneAmphersand() {
  assertEquals("<P&O>", StringEscapeUtils.unescapeHtml4("&lt;P&O&gt;"));
  assertEquals("test & <", StringEscapeUtils.unescapeHtml4("test & &lt;"));
  assertEquals("<P&O>", StringEscapeUtils.unescapeXml("&lt;P&O&gt;"));
  assertEquals("test & <", StringEscapeUtils.unescapeXml("test & &lt;"));
}

代码示例来源:origin: org.apache.commons/commons-text

@Test
public void testEscapeHtmlVersions() {
  assertEquals("&Beta;", StringEscapeUtils.escapeHtml4("\u0392"));
  assertEquals("\u0392", StringEscapeUtils.unescapeHtml4("&Beta;"));
  // TODO: refine API for escaping/unescaping specific HTML versions
}

代码示例来源:origin: org.apache.commons/commons-text

/**
 * Tests https://issues.apache.org/jira/browse/LANG-339
 */
@Test
public void testEscapeHiragana() {
  // Some random Japanese Unicode characters
  final String original = "\u304B\u304C\u3068";
  final String escaped = StringEscapeUtils.escapeHtml4(original);
  assertEquals(original, escaped,
      "Hiragana character Unicode behaviour should not be being escaped by escapeHtml4");
  final String unescaped = StringEscapeUtils.unescapeHtml4(escaped);
  assertEquals(escaped, unescaped, "Hiragana character Unicode behaviour has changed - expected no unescaping");
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage

protected String removeEntities(String string) {
  if (string.indexOf('&') >= 0) {
    string = StringEscapeUtils.unescapeHtml4(string);
  }
  return string;
}

代码示例来源:origin: fhoeben/hsac-fitnesse-fixtures

/**
 * Removes HTML preformatting (if any).
 * @param value value (possibly pre-formatted)
 * @return value without HTML preformatting.
 */
public String cleanupPreFormatted(String value) {
  String result = value;
  if (value != null) {
    Matcher matcher = PRE_FORMATTED_PATTERN.matcher(value);
    if (matcher.matches()) {
      String escapedBody = matcher.group(1);
      result = StringEscapeUtils.unescapeHtml4(escapedBody);
    }
  }
  return result;
}

代码示例来源:origin: fhoeben/hsac-fitnesse-fixtures

/**
 * Gets a URL from a wiki page value.
 * @param htmlLink link as present on wiki page.
 * @return address the link points to (if it is an 'a'), the original link otherwise.
 */
public String getUrl(String htmlLink) {
  String result = htmlLink;
  if (htmlLink != null) {
    Matcher linkMatcher = LINKPATTERN.matcher(htmlLink);
    Matcher imgMatcher = IMAGEPATTERN.matcher(htmlLink);
    if (linkMatcher.matches()) {
      String href = linkMatcher.group(2);
      href = StringEscapeUtils.unescapeHtml4(href);
      result = href + linkMatcher.group(4);
    } else if (imgMatcher.matches()) {
      String src = imgMatcher.group(2);
      result = StringEscapeUtils.unescapeHtml4(src);
    }
  }
  return result;
}

代码示例来源:origin: fhoeben/hsac-fitnesse-fixtures

/**
   * Unescapes supplied HTML content so it can be rendered inside a wiki page.
   * @param htmlSource HTML code to display (possibly surrounded by <pre></pre> tags).
   * @return unescaped content, enclosed in <div></div> so wiki will not escape it.
   */
  public String html(String htmlSource) {
    String cleanSource = htmlCleaner.cleanupPreFormatted(htmlSource);
    return "<div>" + StringEscapeUtils.unescapeHtml4(cleanSource) + "</div>";
  }
}

代码示例来源:origin: org.openestate.is24/OpenEstate-IS24-REST-Core

"The provided text " + value + " is too short (minimum is " + minLength + ")!");
val = StringEscapeUtils.unescapeHtml4(value);

代码示例来源:origin: JavaChat/OakBot

String name = StringEscapeUtils.unescapeHtml4(nameBuffer.toString());
if (trigger != null) {
  if (!name.startsWith(trigger)) {

代码示例来源:origin: JavaChat/OakBot

markdown = StringEscapeUtils.unescapeHtml4(markdown);

代码示例来源:origin: infiniteautomation/ma-core-public

String messageString = StringEscapeUtils.unescapeHtml4(messageStringHTML);

代码示例来源:origin: infiniteautomation/ma-core-public

alias = StringEscapeUtils.unescapeHtml4(alias);

代码示例来源:origin: JavaChat/OakBot

private ChatResponse deleteCat(ChatCommand chatCommand, BotContext context, String cat) {
  if (!context.isAuthorAdmin() && chatCommand.getMessage().getUserId() != hans) {
    return reply("Only Hans can delete.", chatCommand);
  }
  if (cat == null) {
    //@formatter:off
    return new ChatResponse(new ChatBuilder()
      .reply(chatCommand)
      .append("Specify the URL of the cat you want to delete: ")
      .code()
      .append(context.getTrigger())
      .append(name())
      .append(" delete URL")
      .code()
    );
    //@formatter:on
  }
  /*
   * Just unescape the HTML entities. Do not convert to Markdown because
   * this will escape special characters like underscores, which will
   * break the URL.
   */
  cat = StringEscapeUtils.unescapeHtml4(cat);
  boolean removed = cats.remove(cat);
  if (!removed) {
    return reply("404 cat not found.", chatCommand);
  }
  save();
  return reply("Deleted.", chatCommand);
}

代码示例来源:origin: JavaChat/OakBot

private ChatResponse addCat(ChatCommand chatCommand, BotContext context, String cat) {
  if (!context.isAuthorAdmin() && chatCommand.getMessage().getUserId() != hans) {
    return reply("Only Hans can add.", chatCommand);
  }
  if (cat == null) {
    //@formatter:off
    return new ChatResponse(new ChatBuilder()
      .reply(chatCommand)
      .append("Specify the URL of the cat you want to add: ")
      .code()
      .append(context.getTrigger())
      .append(name())
      .append(" add URL")
      .code()
    );
    //@formatter:on
  }
  /*
   * Just unescape the HTML entities. Do not convert to Markdown because
   * this will escape special characters like underscores, which will
   * break the URL.
   */
  cat = StringEscapeUtils.unescapeHtml4(cat);
  if (cats.contains(cat)) {
    return reply("Cat already added.", chatCommand);
  }
  Conversation conversation = new Conversation(chatCommand.getMessage().getRoomId(), chatCommand.getMessage().getUserId(), cat);
  conversations.add(conversation);
  return reply("Is cat fat? (y/n)", chatCommand);
}

相关文章