parent
ea0f431a0d
commit
980a52a062
@ -1,27 +1,34 @@
|
||||
package com.luoo.comment.sensitiveword;
|
||||
package com.luoo.comment.sensitiveWord;
|
||||
|
||||
import com.github.houbb.sensitive.word.api.IWordDeny;
|
||||
import constants.SensitiveWords;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class MyDdWordDeny implements IWordDeny {
|
||||
String DENY_WORDS= SensitiveWords.DENY_WORDS;
|
||||
|
||||
@Override
|
||||
public List<String> deny() {
|
||||
List<String> list = new ArrayList<>();
|
||||
// list.add("落网");
|
||||
list.add("落网");
|
||||
Resource mySensitiveWords = new ClassPathResource("denyWords.txt");
|
||||
try {
|
||||
Path mySensitiveWordsPath = Paths.get(mySensitiveWords.getFile().getPath());
|
||||
list = Files.readAllLines(mySensitiveWordsPath, StandardCharsets.UTF_8);
|
||||
|
||||
String[] s = DENY_WORDS.split("\n");
|
||||
for(String denyWord:s) {
|
||||
list.add(denyWord);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue