@Override public ProfanityResult checkString(String str) { ProfanityResult profResult = new ProfanityResult(); String[] wordStr = null; Pattern p = Pattern.compile("\\W"); Collection<Word> wordList = WordHome.getWordsList(); if ((str != null) && StringUtils.isNotEmpty(str) && StringUtils.isNotBlank(str)) { wordStr = p.split(str); } boolean _isSwearWords = false; int number = 0; if (wordStr != null) { for (String word : wordStr) { if (containsReferenceTo(wordList, word)) { profResult.addWord(word); _isSwearWords = true; number++; } } } profResult.setIsSwearWords(_isSwearWords); profResult.setNumberSwearWords(number); return profResult; }
@Override public ProfanityResult checkStringCounter(String str, String strResourceType) { Counter counter = CounterHome.findByResourceTypeKey(strResourceType); Pattern p = Pattern.compile("\\W"); if (counter == null) { Counter newCounter = new Counter(); newCounter.setCounter(0); newCounter.setResourceType(strResourceType); counter = CounterHome.create(newCounter); } ProfanityResult profResult = new ProfanityResult(); String[] wordStr = null; Collection<Word> wordList = WordHome.getWordsList(); if ((str != null) && StringUtils.isNotEmpty(str) && StringUtils.isNotBlank(str)) { wordStr = p.split(str); } boolean _isSwearWords = false; int number = 0; if (wordStr != null) { for (String word : wordStr) { if (containsReferenceTo(wordList, word)) { profResult.addWord(word); _isSwearWords = true; number++; counter.setCounter(counter.getCounter() + 1); CounterHome.update(counter); profResult.setCounterSwearWords(counter.getCounter()); } } } profResult.setIsSwearWords(_isSwearWords); profResult.setNumberSwearWords(number); return profResult; }