|
|
@ -8,6 +8,9 @@ import javafx.concurrent.Task; |
|
|
|
import javafx.scene.web.WebEngine; |
|
|
|
import javafx.scene.web.WebEngine; |
|
|
|
import netscape.javascript.JSObject; |
|
|
|
import netscape.javascript.JSObject; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by ibm on 2017/5/27. |
|
|
|
* Created by ibm on 2017/5/27. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -57,7 +60,7 @@ public class JSCallback<T> extends Task<T> { |
|
|
|
* 这边建议去除所有的html标签 |
|
|
|
* 这边建议去除所有的html标签 |
|
|
|
* 字符\在java中实际存储的是\\,替换字符串\\n, 需要用\\\\n |
|
|
|
* 字符\在java中实际存储的是\\,替换字符串\\n, 需要用\\\\n |
|
|
|
* "\t"和"\n" 都要转义成" " 不然会解析出错 |
|
|
|
* "\t"和"\n" 都要转义成" " 不然会解析出错 |
|
|
|
* "\\"需要转换成"\" |
|
|
|
* "\\"需要转换成"\\\" |
|
|
|
* 过滤掉html标签及内容 |
|
|
|
* 过滤掉html标签及内容 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param old 原始字符串 |
|
|
|
* @param old 原始字符串 |
|
|
@ -65,9 +68,8 @@ public class JSCallback<T> extends Task<T> { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String trimText(String old) { |
|
|
|
private String trimText(String old) { |
|
|
|
if (StringUtils.isNotBlank(old)) { |
|
|
|
if (StringUtils.isNotBlank(old)) { |
|
|
|
String a = filterHtmlTag(old, "a"); |
|
|
|
String b = filterHtmlTag(old); |
|
|
|
String b = filterHtmlTag(a, "font"); |
|
|
|
return b.replaceAll("\\\\n", "").replaceAll("\\\\t", "").replaceAll("\"", "\\\\\"").replaceAll("\'", "\\\\\'").replaceAll("\\\\\\\\", "\\\\\\\\\\\\"); |
|
|
|
return b.replaceAll("\\\\n", "").replaceAll("\\\\t", "").replaceAll("\"", "\\\\\"").replaceAll("\'", "\\\\\'").replaceAll("\\\\\\\\", "\\\\"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return StringUtils.EMPTY; |
|
|
|
return StringUtils.EMPTY; |
|
|
|
} |
|
|
|
} |
|
|
@ -75,21 +77,16 @@ public class JSCallback<T> extends Task<T> { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 进行html标签过滤 |
|
|
|
* 进行html标签过滤 |
|
|
|
* @param origin 原始字符串 |
|
|
|
* @param origin 原始字符串 |
|
|
|
* @param tag html标签 |
|
|
|
|
|
|
|
* @return 处理之后的字符串 |
|
|
|
* @return 处理之后的字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String filterHtmlTag(String origin, String tag) { |
|
|
|
private String filterHtmlTag(String origin) { |
|
|
|
String matter1 = "<" + tag; |
|
|
|
String regEx_html = "<[^>]+>"; |
|
|
|
String matter2 = tag + ">"; |
|
|
|
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE); |
|
|
|
int a = origin.indexOf(matter1); |
|
|
|
Matcher m_html = p_html.matcher(origin); |
|
|
|
int b = origin.indexOf(matter2); |
|
|
|
origin = m_html.replaceAll(""); |
|
|
|
while (a != -1 && b != -1) { |
|
|
|
|
|
|
|
origin = origin.substring(0, a) + origin.substring(b + matter2.length(), origin.length()); |
|
|
|
|
|
|
|
a = origin.indexOf(matter1); |
|
|
|
|
|
|
|
b = origin.indexOf(matter2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return origin; |
|
|
|
return origin; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|