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