Search in sources :

Example 1 with HTMLCleaner

use of org.xwiki.xml.html.HTMLCleaner in project xwiki-platform by xwiki.

the class PdfExportImpl method convertToStrictXHtml.

/**
 * Cleans up an HTML document, turning it into valid XHTML.
 *
 * @param input the source HTML to process
 * @return the cleaned up source
 */
private String convertToStrictXHtml(String input) {
    LOGGER.debug("Cleaning HTML:\n{}", input);
    HTMLCleaner cleaner = Utils.getComponent(HTMLCleaner.class);
    HTMLCleanerConfiguration config = cleaner.getDefaultConfiguration();
    List<HTMLFilter> filters = new ArrayList<HTMLFilter>(config.getFilters());
    filters.add(Utils.getComponent(HTMLFilter.class, "uniqueId"));
    config.setFilters(filters);
    String result = HTMLUtils.toString(cleaner.clean(new StringReader(input), config));
    LOGGER.debug("Cleaned XHTML:\n{}", result);
    return result;
}
Also used : ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) HTMLFilter(org.xwiki.xml.html.filter.HTMLFilter) HTMLCleaner(org.xwiki.xml.html.HTMLCleaner) HTMLCleanerConfiguration(org.xwiki.xml.html.HTMLCleanerConfiguration)

Aggregations

StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HTMLCleaner (org.xwiki.xml.html.HTMLCleaner)1 HTMLCleanerConfiguration (org.xwiki.xml.html.HTMLCleanerConfiguration)1 HTMLFilter (org.xwiki.xml.html.filter.HTMLFilter)1