/** * URL encode the passed value using the passed character encoding, or if the encoding doesn't exist, the system * encoding. * * @param value the value to encode. * @param encoding the character encoding to use * @param spacesEncodedasHexValue if true spaces are encoded with the the hex value '%20', otherwise if false then the character '+'. * @return the encoded value. */ @HtmlSafe public static String encode(String value, String encoding, boolean spacesEncodedasHexValue) { try { return URLCodec.encode(value, encoding, spacesEncodedasHexValue); } catch (UnsupportedEncodingException e) { log.warn("Unable to encode '" + value + "' with encoding '" + encoding + "'. Encoding with system defaults."); return systemDefaultEncoding(value, spacesEncodedasHexValue); } }