web相关的一些操作方法
| 10 | * web相关的一些操作方法 |
| 11 | */ |
| 12 | public class WebHelper { |
| 13 | |
| 14 | |
| 15 | /** |
| 16 | * 对字符串进行编码 |
| 17 | * |
| 18 | * @param str 需要处理的字符串 |
| 19 | * @param encoding 编码方式 |
| 20 | * @return 编码后的字符串 |
| 21 | */ |
| 22 | public static String escape(String str, String encoding) throws UnsupportedEncodingException { |
| 23 | if (StringUtil.isEmpty(str)) { |
| 24 | return ""; |
| 25 | } |
| 26 | char[] chars = ConvertHepler.bytesToChars(ConvertHepler.encodeBytes(str.getBytes(encoding), '%')); |
| 27 | return new String(chars); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * 对字符串进行解码 |
| 32 | * |
| 33 | * @param str 需要处理的字符串 |
| 34 | * @param encoding 解码方式 |
| 35 | * @return 解码后的字符串 |
| 36 | */ |
| 37 | public static String unescape(String str, String encoding) { |
| 38 | if (StringUtil.isEmpty(str)) { |
| 39 | return ""; |
| 40 | } |
| 41 | return UrlHelper.decodeQuery(str, encoding); |
| 42 | } |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * HTML标签转义方法 |
| 47 | * <p> |
| 48 | * 空格 |
| 49 | * < 小于号 < |
| 50 | * > 大于号 > |
| 51 | * & 和号 & |
| 52 | * " 引号 " |
| 53 | * ' 撇号 ' |
| 54 | * ¢ 分 ¢ |
| 55 | * £ 镑 £ |
| 56 | * ¥ 日圆 ¥ |
| 57 | * € 欧元 € |
| 58 | * § 小节 § |
| 59 | * © 版权 © |
| 60 | * ® 注册商标 ® |
| 61 | * ™ 商标 ™ |
| 62 | * × 乘号 × |
| 63 | * ÷ 除号 ÷ |
| 64 | */ |
| 65 | public static String unhtml(String content) { |
| 66 | if (StringUtil.isEmpty(content)) { |
| 67 | return ""; |
| 68 | } |
| 69 | String html = content; |
nothing calls this directly
no outgoing calls
no test coverage detected