MCPcopy Create free account
hub / github.com/0opslab/opslabJutil / WebHelper

Class WebHelper

src/main/java/com/opslab/helper/WebHelper.java:12–200  ·  view source on GitHub ↗

web相关的一些操作方法

Source from the content-addressed store, hash-verified

10 * web相关的一些操作方法
11 */
12public 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 * 空格 &nbsp;
49 * < 小于号 &lt;
50 * > 大于号 &gt;
51 * & 和号 &amp;
52 * " 引号 &quot;
53 * ' 撇号 &apos;
54 * ¢ 分 &cent;
55 * £ 镑 &pound;
56 * ¥ 日圆 &yen;
57 * € 欧元 &euro;
58 * § 小节 &sect;
59 * © 版权 &copy;
60 * ® 注册商标 &reg;
61 * ™ 商标 &trade;
62 * × 乘号 &times;
63 * ÷ 除号 &divide;
64 */
65 public static String unhtml(String content) {
66 if (StringUtil.isEmpty(content)) {
67 return "";
68 }
69 String html = content;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected