Example usage for org.springframework.web.util HtmlCharacterEntityDecoder HtmlCharacterEntityDecoder

List of usage examples for org.springframework.web.util HtmlCharacterEntityDecoder HtmlCharacterEntityDecoder

Introduction

In this page you can find the example usage for org.springframework.web.util HtmlCharacterEntityDecoder HtmlCharacterEntityDecoder.

Prototype

public HtmlCharacterEntityDecoder(HtmlCharacterEntityReferences characterEntityReferences, String original) 

Source Link

Usage

From source file:org.springframework.web.util.HtmlUtils.java

/**
 * Turn HTML character references into their plain text UNICODE equivalent.
 * <p>Handles complete character set defined in HTML 4.01 recommendation
 * and all reference types (decimal, hex, and entity).
 * <p>Correctly converts the following formats:
 * <blockquote>/*from ww  w . ja v  a 2 s  .co  m*/
 * &amp;#<i>Entity</i>; - <i>(Example: &amp;amp;) case sensitive</i>
 * &amp;#<i>Decimal</i>; - <i>(Example: &amp;#68;)</i><br>
 * &amp;#x<i>Hex</i>; - <i>(Example: &amp;#xE5;) case insensitive</i><br>
 * </blockquote>
 * Gracefully handles malformed character references by copying original
 * characters as is when encountered.<p>
 * <p>Reference:
 * <a href="http://www.w3.org/TR/html4/sgml/entities.html">
 * http://www.w3.org/TR/html4/sgml/entities.html
 * </a>
 * @param input the (escaped) input string
 * @return the unescaped string
 */
public static String htmlUnescape(String input) {
    if (input == null) {
        return null;
    }
    return new HtmlCharacterEntityDecoder(characterEntityReferences, input).decode();
}