public String sanitiseValue(final Object value) { String sanitisedValue; if (value instanceof String) { sanitisedValue = new HtmlToPlainText().getPlainText(Jsoup.parse(value.toString())); } else { sanitisedValue = value.toString(); } if (sanitisedValue == null) { sanitisedValue = ""; } return sanitisedValue; }
public String checkHtmlContent(String htmlContent) { AnnotatedText markup = makeAnnotatedText(htmlContent); StringBuilder bf = new StringBuilder(htmlContent); langTool.getAllActiveRules().stream().filter(rule -> rule instanceof SpellingCheckRule).forEach(rule -> ((SpellingCheckRule) rule).acceptPhrases(wordsToIgnore)); List<RuleMatch> matches = new ArrayList<>(); try { matches = langTool.check(markup); } catch (Exception e) { log.error(e.getMessage(), e); } int offset = 0; for (RuleMatch match : matches) { String desc = match.getMessage(); desc = new HtmlToPlainText().getPlainText(Jsoup.parse(desc)); if (!match.getSuggestedReplacements().isEmpty()) { desc += Configuration.getBundle().getString("ui.alert.correction.tooltip.suggestion") + match.getSuggestedReplacements(); } String before = "<span class=\"error-french\" title=\"" + desc + "\">"; bf.insert(match.getFromPos() + offset, before); offset += before.length(); String after = "</span> "; bf.insert(match.getToPos() + offset, after); offset += after.length(); } return bf.toString(); }
@Override public String operate(Element element) { return new HtmlToPlainText().getPlainText(element); }