Hướng dẫn htmlutils htmlescape example - htmlutils ví dụ htmlescape

Cách sử dụng

Htmlescape

phương pháp

in

Đoạn mã Java tốt nhất bằng cách sử dụng org.springframework.web.util.htmlutils.htmlescape (hiển thị 20 kết quả hàng đầu trong số 504)htmlEscape(Showing top 20 results out of 504)













public static String htmlEscape(String input) {
  return htmlEscape(input, WebUtils.DEFAULT_CHARACTER_ENCODING);
}

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}

@Test
public void testEncodeIntoHtmlCharacterSetFromUtf8() {
  String utf8 = ("UTF-8");
  assertEquals("An empty string should be converted to an empty string",
      "", HtmlUtils.htmlEscape("", utf8));
  assertEquals("A string containing no special characters should not be affected",
      "A sentence containing no special characters.",
      HtmlUtils.htmlEscape("A sentence containing no special characters."));
  assertEquals("'< >' should be encoded to '< >'",
      "< >", HtmlUtils.htmlEscape("< >", utf8));
  assertEquals("'< >' should be encoded to '< >'",
      "< >", HtmlUtils.htmlEscapeDecimal("< >", utf8));
  assertEquals("UTF-8 supported chars should not be escaped",
      "Μερικοί Ελληνικοί "χαρακτήρες"",
      HtmlUtils.htmlEscape("Μερικοί Ελληνικοί \"χαρακτήρες\"", utf8));
}








public String getMessage(MessageSourceResolvable resolvable, boolean htmlEscape) throws NoSuchMessageException {
  String msg = this.messageSource.getMessage(resolvable, this.locale);
  return (htmlEscape ? HtmlUtils.htmlEscape(msg) : msg);
}

@Test
public void testEncodeIntoHtmlCharacterSet() {
  assertEquals("An empty string should be converted to an empty string",
      "", HtmlUtils.htmlEscape(""));
  assertEquals("A string containing no special characters should not be affected",
      "A sentence containing no special characters.",
      HtmlUtils.htmlEscape("A sentence containing no special characters."));
  assertEquals("'< >' should be encoded to '< >'",
      "< >", HtmlUtils.htmlEscape("< >"));
  assertEquals("'< >' should be encoded to '< >'",
      "< >", HtmlUtils.htmlEscapeDecimal("< >"));
  assertEquals("The special character 8709 should be encoded to '∅'",
      "∅", HtmlUtils.htmlEscape("" + (char) 8709));
  assertEquals("The special character 8709 should be encoded to '∅'",
      "∅", HtmlUtils.htmlEscapeDecimal("" + (char) 8709));
  assertEquals("The special character 977 should be encoded to 'ϑ'",
      "ϑ", HtmlUtils.htmlEscape("" + (char) 977));
  assertEquals("The special character 977 should be encoded to 'ϑ'",
      "ϑ", HtmlUtils.htmlEscapeDecimal("" + (char) 977));
}









public String getMessage(String code, @Nullable Object[] args, boolean htmlEscape) throws NoSuchMessageException {
  String msg = this.messageSource.getMessage(code, args, this.locale);
  return (htmlEscape ? HtmlUtils.htmlEscape(msg) : msg);
}









public String getMessage(String code, @Nullable Object[] args, String defaultMessage, boolean htmlEscape) {
  String msg = this.messageSource.getMessage(code, args, defaultMessage, this.locale);
  if (msg == null) {
    return "";
  }
  return (htmlEscape ? HtmlUtils.htmlEscape(msg) : msg);
}








public String getDisplayValue() {
  if (this.value instanceof String) {
    return (String) this.value;
  }
  if (this.value != null) {
    return (this.htmlEscape ? HtmlUtils.htmlEscape(this.value.toString()) : this.value.toString());
  }
  return "";
}








public String getDisplayValue() {
  if (this.value instanceof String) {
    return (String) this.value;
  }
  if (this.value != null) {
    return (this.htmlEscape ?
        HtmlUtils.htmlEscape(this.value.toString()) : this.value.toString());
  }
  return "";
}

@Override
@Nullable
public Object getFieldValue(String field) {
  Object value = this.source.getFieldValue(field);
  return (value instanceof String ? HtmlUtils.htmlEscape((String) value) : value);
}

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}
0

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}
1

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}
2

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}
3

@Override
@Nullable
public Object getFieldValue(String field) {
  Object value = this.source.getFieldValue(field);
  return (value instanceof String ? HtmlUtils.htmlEscape((String) value) : value);
}

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}
5

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}
0

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}
7

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}
5

@Test
public void testHtmlEscape() {
  String unescaped = "\"This is a quote'";
  String escaped = HtmlUtils.htmlEscape(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeDecimal(unescaped);
  assertEquals(""This is a quote'", escaped);
  escaped = HtmlUtils.htmlEscapeHex(unescaped);
  assertEquals(""This is a quote'", escaped);
}
9