|
|
@ -1,9 +1,8 @@ |
|
|
|
package com.fr.design.actions.replace.utils; |
|
|
|
package com.fr.design.actions.replace.utils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.design.actions.replace.info.Info; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.design.actions.replace.ui.ITReplaceMainDialog; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.collections.combination.Pair; |
|
|
|
import com.fr.stable.collections.combination.Pair; |
|
|
|
|
|
|
|
|
|
|
@ -30,6 +29,20 @@ public class ShowValueUtils { |
|
|
|
public static final String ANY_THING_REGEX = "."; |
|
|
|
public static final String ANY_THING_REGEX = "."; |
|
|
|
public static final String NUMBER_REGEX = "[0-9]"; |
|
|
|
public static final String NUMBER_REGEX = "[0-9]"; |
|
|
|
public static final String ENGLISH_REGEX = "[a-zA-Z]"; |
|
|
|
public static final String ENGLISH_REGEX = "[a-zA-Z]"; |
|
|
|
|
|
|
|
private static List<String> specialCharList = new ArrayList<>(); |
|
|
|
|
|
|
|
static { |
|
|
|
|
|
|
|
//正则特殊字符:? * () [] {} ^ $
|
|
|
|
|
|
|
|
//如果是? 并采用通配符 ,会自动转成“.” 所以 ? 不用处理
|
|
|
|
|
|
|
|
//$同理
|
|
|
|
|
|
|
|
specialCharList.add("*"); |
|
|
|
|
|
|
|
specialCharList.add("("); |
|
|
|
|
|
|
|
specialCharList.add(")"); |
|
|
|
|
|
|
|
specialCharList.add("["); |
|
|
|
|
|
|
|
specialCharList.add("]"); |
|
|
|
|
|
|
|
specialCharList.add("{"); |
|
|
|
|
|
|
|
specialCharList.add("}"); |
|
|
|
|
|
|
|
specialCharList.add("^"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取除内容外其他一次性展示所有的内容(名称、水印...) |
|
|
|
* 获取除内容外其他一次性展示所有的内容(名称、水印...) |
|
|
@ -42,9 +55,7 @@ public class ShowValueUtils { |
|
|
|
if (StringUtils.isEmpty(searchStr)) { |
|
|
|
if (StringUtils.isEmpty(searchStr)) { |
|
|
|
return str; |
|
|
|
return str; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return "<html><body><div><nobr>" + |
|
|
|
return updateHighlight(str, searchStr); |
|
|
|
replaceAll(str, searchStr, "<font color = 'rgb(61,153,249)'>" + searchStr + "</font>") + |
|
|
|
|
|
|
|
"</nobr></div></body></html>"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -57,7 +68,11 @@ public class ShowValueUtils { |
|
|
|
* @return 替换后的字符串 |
|
|
|
* @return 替换后的字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static String replaceAll(String str, String regex, String replacement) { |
|
|
|
public static String replaceAll(String str, String regex, String replacement) { |
|
|
|
return str.replace(regex, replacement); |
|
|
|
if (ITReplaceMainDialog.isMatched()) { |
|
|
|
|
|
|
|
return str.replaceAll(changeRegex(regex), replacement); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return str.replace(regex, replacement); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -70,6 +85,10 @@ public class ShowValueUtils { |
|
|
|
regex = regex.replace(NUMBER, NUMBER_REGEX); |
|
|
|
regex = regex.replace(NUMBER, NUMBER_REGEX); |
|
|
|
regex = regex.replace(ENGLISH, ENGLISH_REGEX); |
|
|
|
regex = regex.replace(ENGLISH, ENGLISH_REGEX); |
|
|
|
regex = regex.replace(ANY_THING, ANY_THING_REGEX); |
|
|
|
regex = regex.replace(ANY_THING, ANY_THING_REGEX); |
|
|
|
|
|
|
|
String change = "\\"; |
|
|
|
|
|
|
|
for (int i = 0 ; i < specialCharList.size() ; i ++){ |
|
|
|
|
|
|
|
regex = regex.replace(specialCharList.get(i),change + specialCharList.get(i)); |
|
|
|
|
|
|
|
} |
|
|
|
return regex; |
|
|
|
return regex; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -101,18 +120,36 @@ public class ShowValueUtils { |
|
|
|
return pairs; |
|
|
|
return pairs; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 更新高亮状态 |
|
|
|
* 更新高亮 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param info |
|
|
|
* @param str |
|
|
|
* @param replaceStr |
|
|
|
* @param searchStr |
|
|
|
|
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void updateHighlight(Info info, String replaceStr) { |
|
|
|
public static String updateHighlight(String str, String searchStr) { |
|
|
|
String s = info.getInfoShowStr(info); |
|
|
|
if (ITReplaceMainDialog.isMatched()) { |
|
|
|
s = s.replace(info.getContent().getLastSearchStr(), "<font color = 'rgb(61,153,249)'>" + replaceStr + "</font>"); |
|
|
|
String result = str; |
|
|
|
info.getContent().setShowStr( |
|
|
|
Pattern pattern = Pattern.compile(changeRegex(searchStr)); |
|
|
|
"<html><body><div><nobr>" + s + "</nobr></div></body></html>" |
|
|
|
Matcher matcher = pattern.matcher(str); |
|
|
|
); |
|
|
|
String head = "<font color = 'rgb(61,153,249)'>"; |
|
|
|
|
|
|
|
String tail = "</font>"; |
|
|
|
|
|
|
|
int size = head.length() + tail.length(); |
|
|
|
|
|
|
|
int index = 0; |
|
|
|
|
|
|
|
StringBuilder builder = new StringBuilder(str); |
|
|
|
|
|
|
|
while (matcher.find()) { |
|
|
|
|
|
|
|
builder.replace(matcher.start() + index, matcher.end() + index, head + matcher.group() + tail); |
|
|
|
|
|
|
|
index += size; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return "<html><body><div><nobr>" + |
|
|
|
|
|
|
|
builder.toString() + |
|
|
|
|
|
|
|
"</nobr></div></body></html>"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return "<html><body><div><nobr>" + |
|
|
|
|
|
|
|
replaceAll(str, searchStr, "<font color = 'rgb(61,153,249)'>" + searchStr + "</font>") + |
|
|
|
|
|
|
|
"</nobr></div></body></html>"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -146,4 +183,16 @@ public class ShowValueUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
return failReturn; |
|
|
|
return failReturn; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean contains(String originStr, String matchStr) { |
|
|
|
|
|
|
|
if (ITReplaceMainDialog.isMatched()) { |
|
|
|
|
|
|
|
String str = changeRegex(matchStr); |
|
|
|
|
|
|
|
Pattern pattern = Pattern.compile(str); |
|
|
|
|
|
|
|
Matcher matcher = pattern.matcher(originStr); |
|
|
|
|
|
|
|
return matcher.find(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return originStr.contains(matchStr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|