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