Browse Source

新增JsoupUtils.text工具方法

woody 1 year ago
parent
commit
96b2578253

+ 22 - 12
framework-base/src/main/java/com/chelvc/framework/base/util/JsoupUtils.java

@@ -37,27 +37,37 @@ public final class JsoupUtils {
     /**
      * 清理数据
      *
-     * @param value 数据值
-     * @return 清理后的数据值
+     * @param text 文本内容
+     * @return 文本内容
      */
-    public static String clean(String value) {
-        return StringUtils.isEmpty(value) ? value : Jsoup.clean(value, StringUtils.EMPTY, WHITELIST, OUTPUT_SETTINGS);
+    public static String clean(String text) {
+        return StringUtils.isEmpty(text) ? text : Jsoup.clean(text, StringUtils.EMPTY, WHITELIST, OUTPUT_SETTINGS);
     }
 
     /**
      * 清理数据
      *
-     * @param values 数据值数组
-     * @return 清理后的数据值数组
+     * @param texts 文本内容数组
+     * @return 文本内容数组
      */
-    public static String[] clean(String[] values) {
-        if (values == null || values.length == 0) {
-            return values;
+    public static String[] clean(String[] texts) {
+        if (texts == null || texts.length == 0) {
+            return texts;
         }
-        String[] cleans = new String[values.length];
-        for (int i = 0, size = values.length; i < size; i++) {
-            cleans[i] = clean(values[i]);
+        String[] cleans = new String[texts.length];
+        for (int i = 0, size = texts.length; i < size; i++) {
+            cleans[i] = clean(texts[i]);
         }
         return cleans;
     }
+
+    /**
+     * 过滤html标签
+     *
+     * @param text 文本内容
+     * @return 文本内容
+     */
+    public static String text(String text) {
+        return StringUtils.isEmpty(text) ? text : Jsoup.parse(text).text();
+    }
 }