StripHtmlSanitizer implements Sanitizer<String> { @Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; } Document document = Jsoup.parse(content); document.outputSettings().escapeMode(Entities.EscapeMode.xhtml); for (Element element : document.select("script,link,iframe,style")) { element.remove(); } return document.text(); }  @Override String execute(String content);  }
@Test public void testExecute() throws Exception { StripHtmlSanitizer sanitizer = new StripHtmlSanitizer(); String html = IOUtils.toString(getClass().getResourceAsStream("StripHtmlSanitizerTest_dirty.html")); assertEquals("SPG Flights FAQs Home Frequently Asked Questions", sanitizer.execute(html)); }
@Test @Ignore public void testSanitizeUrl() throws Exception { StripHtmlSanitizer sanitizer = new StripHtmlSanitizer(); assertEquals(URL, sanitizer.execute(URL)); }