调整
This commit is contained in:
parent
da3477d87d
commit
def99a7d69
@ -1,5 +1,6 @@
|
||||
package com.cm.plugin.manager;
|
||||
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -120,7 +121,7 @@ public class SensitiveWordsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回敏感结果,替换成相应字符
|
||||
* 返回敏感过滤结果,替换成相应字符
|
||||
*
|
||||
* @param content
|
||||
* @param replace
|
||||
@ -146,6 +147,32 @@ public class SensitiveWordsManager {
|
||||
return sensitiveResult.getSensitive();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回敏感过滤结果,替换成相应字符
|
||||
*
|
||||
* @param content
|
||||
* @param replace
|
||||
* @param sensitiveWords
|
||||
* @return
|
||||
*/
|
||||
public String getSensitiveWordsResultWithReplace(String content, char replace, List<String> sensitiveWords) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
return null;
|
||||
}
|
||||
if (sensitiveWords == null || sensitiveWords.isEmpty()) {
|
||||
return content;
|
||||
}
|
||||
String result = content;
|
||||
for (String sensitiveWord : sensitiveWords) {
|
||||
StringBuilder replaceSB = new StringBuilder();
|
||||
for (int i = 0; i < sensitiveWord.length(); i++) {
|
||||
replaceSB.append(replace);
|
||||
}
|
||||
result = result.replaceAll(sensitiveWord, replaceSB.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class SensitiveWordsManagerBuilder {
|
||||
public static SensitiveWordsManager sensitiveWordsManager = new SensitiveWordsManager();
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
<dependency>
|
||||
<groupId>it.sauronsoftware</groupId>
|
||||
<artifactId>jave</artifactId>
|
||||
<version>1.0.2</version>
|
||||
</dependency>
|
||||
<!-- sauronsoftware end -->
|
||||
</dependencies>
|
||||
|
Loading…
Reference in New Issue
Block a user