@Override public HTMLCleanerConfiguration getDefaultConfiguration() { HTMLCleanerConfiguration configuration = new DefaultHTMLCleanerConfiguration(); configuration.setFilters( Arrays.asList( this.bodyFilter, this.listItemFilter, this.listFilter, this.fontFilter, this.attributeFilter)); return configuration; }
/** Test {@link UniqueIdFilter}. */ @Test public void duplicateIds() throws Exception { String actual = "<p id=\"x\">1</p><p id=\"xy\">2</p><p id=\"x\">3</p>"; String expected = "<p id=\"x\">1</p><p id=\"xy\">2</p><p id=\"x0\">3</p>"; HTMLCleanerConfiguration config = this.mocker.getComponentUnderTest().getDefaultConfiguration(); List<HTMLFilter> filters = new ArrayList<HTMLFilter>(config.getFilters()); filters.add(this.mocker.<HTMLFilter>getInstance(HTMLFilter.class, "uniqueId")); config.setFilters(filters); Assert.assertEquals( HEADER_FULL + expected + FOOTER, HTMLUtils.toString( this.mocker.getComponentUnderTest().clean(new StringReader(actual), config))); }
/** Verify that we can control what filters are used for cleaning. */ @Test public void explicitFilterList() throws ComponentLookupException { HTMLCleanerConfiguration configuration = this.mocker.getComponentUnderTest().getDefaultConfiguration(); configuration.setFilters(Collections.<HTMLFilter>emptyList()); String result = HTMLUtils.toString( this.mocker .getComponentUnderTest() .clean(new StringReader("something"), configuration)); // Note that if the default Body filter had been executed the result would have been: // <p>something</p>. Assert.assertEquals(HEADER_FULL + "something" + FOOTER, result); }