Search in sources :

Example 1 with HTMLFilter

use of org.xwiki.xml.html.filter.HTMLFilter 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)

Example 2 with HTMLFilter

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

the class OfficeHTMLCleaner method getDefaultConfiguration.

@Override
public HTMLCleanerConfiguration getDefaultConfiguration() {
    HTMLCleanerConfiguration configuration = this.defaultHtmlCleaner.getDefaultConfiguration();
    // Add office cleaning filters after the default filters.
    List<HTMLFilter> filters = new ArrayList<HTMLFilter>(configuration.getFilters());
    filters.addAll(Arrays.asList(this.stripperFilter, this.styleFilter, this.redundancyFilter, this.paragraphFilter, this.imageFilter, this.anchorFilter, this.listFilter, this.tableFilter, this.lineBreakFilter));
    configuration.setFilters(filters);
    return configuration;
}
Also used : ArrayList(java.util.ArrayList) HTMLFilter(org.xwiki.xml.html.filter.HTMLFilter) HTMLCleanerConfiguration(org.xwiki.xml.html.HTMLCleanerConfiguration)

Example 3 with HTMLFilter

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

the class WysiwygHTMLCleaner method getDefaultConfiguration.

@Override
public HTMLCleanerConfiguration getDefaultConfiguration() {
    HTMLCleanerConfiguration configuration = this.defaultHtmlCleaner.getDefaultConfiguration();
    // Add office cleaning filters after the default filters.
    List<HTMLFilter> filters = new ArrayList<HTMLFilter>(configuration.getFilters());
    filters.addAll(Arrays.asList(this.stripperFilter, this.styleFilter, this.redundancyFilter, this.paragraphFilter, this.imageFilter, this.listFilter, this.tableFilter));
    configuration.setFilters(filters);
    return configuration;
}
Also used : ArrayList(java.util.ArrayList) HTMLFilter(org.xwiki.xml.html.filter.HTMLFilter) HTMLCleanerConfiguration(org.xwiki.xml.html.HTMLCleanerConfiguration)

Aggregations

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