This commit is contained in:
wenc000 2020-06-18 16:57:51 +08:00
parent da3477d87d
commit def99a7d69
2 changed files with 29 additions and 1 deletions

View File

@ -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();
}

View File

@ -22,6 +22,7 @@
<dependency>
<groupId>it.sauronsoftware</groupId>
<artifactId>jave</artifactId>
<version>1.0.2</version>
</dependency>
<!-- sauronsoftware end -->
</dependencies>