List of usage examples for org.springframework.web.util HtmlCharacterEntityReferences DECIMAL_REFERENCE_START
String DECIMAL_REFERENCE_START
To view the source code for org.springframework.web.util HtmlCharacterEntityReferences DECIMAL_REFERENCE_START.
Click Source Link
From source file:org.springframework.web.util.HtmlUtils.java
/** * Turn special characters into HTML character references. * Handles complete character set defined in HTML 4.01 recommendation. * <p>Escapes all special characters to their corresponding numeric * reference in decimal format (&#<i>Decimal</i>;) at least as required by the * specified encoding. In other words, if a special character does * not have to be escaped for the given encoding, it may not be. * <p>Reference:/*from ww w. jav a 2 s .c om*/ * <a href="http://www.w3.org/TR/html4/sgml/entities.html"> * http://www.w3.org/TR/html4/sgml/entities.html * </a> * @param input the (unescaped) input string * @param encoding The name of a supported {@link java.nio.charset.Charset charset} * @return the escaped string * @since 4.1.2 */ public static String htmlEscapeDecimal(String input, String encoding) { Assert.notNull(encoding, "Encoding is required"); if (input == null) { return null; } StringBuilder escaped = new StringBuilder(input.length() * 2); for (int i = 0; i < input.length(); i++) { char character = input.charAt(i); if (characterEntityReferences.isMappedToReference(character, encoding)) { escaped.append(HtmlCharacterEntityReferences.DECIMAL_REFERENCE_START); escaped.append((int) character); escaped.append(HtmlCharacterEntityReferences.REFERENCE_END); } else { escaped.append(character); } } return escaped.toString(); }