1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.officeimporter.internal.cleaner

File WysiwygHTMLCleaner.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart2.png
81% of files have more coverage

Code metrics

0
7
3
1
134
68
3
0.43
2.33
3
1

Classes

Class Line # Actions
WysiwygHTMLCleaner 46 7 0% 3 8
0.220%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.officeimporter.internal.cleaner;
21   
22    import java.io.Reader;
23    import java.util.ArrayList;
24    import java.util.Arrays;
25    import java.util.List;
26   
27    import javax.inject.Inject;
28    import javax.inject.Named;
29    import javax.inject.Singleton;
30   
31    import org.w3c.dom.Document;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.xml.html.HTMLCleaner;
34    import org.xwiki.xml.html.HTMLCleanerConfiguration;
35    import org.xwiki.xml.html.filter.HTMLFilter;
36   
37    /**
38    * {@link HTMLCleaner} for cleaning HTML coming from an wysiwyg office importer plugin.
39    *
40    * @version $Id: be31f22bc5d41739c8ab14ceb72347fd3edaa5a1 $
41    * @since 1.8M1
42    */
43    @Component
44    @Named("wysiwyg")
45    @Singleton
 
46    public class WysiwygHTMLCleaner implements HTMLCleaner
47    {
48    /**
49    * Default html cleaner component used internally.
50    */
51    @Inject
52    private HTMLCleaner defaultHtmlCleaner;
53   
54    /**
55    * {@link HTMLFilter} for stripping various tags.
56    */
57    @Inject
58    @Named("officeimporter/stripper")
59    private HTMLFilter stripperFilter;
60   
61    /**
62    * {@link HTMLFilter} filtering styles.
63    */
64    @Inject
65    @Named("officeimporter/style")
66    private HTMLFilter styleFilter;
67   
68    /**
69    * {@link HTMLFilter} for stripping redundant tags.
70    */
71    @Inject
72    @Named("officeimporter/redundancy")
73    private HTMLFilter redundancyFilter;
74   
75    /**
76    * {@link HTMLFilter} for cleaning empty paragraphs.
77    */
78    @Inject
79    @Named("officeimporter/paragraph")
80    private HTMLFilter paragraphFilter;
81   
82    /**
83    * {@link HTMLFilter} for filtering image tags.
84    */
85    @Inject
86    @Named("officeimporter/image")
87    private HTMLFilter imageFilter;
88   
89    /**
90    * {@link HTMLFilter} for filtering lists.
91    */
92    @Inject
93    @Named("officeimporter/list")
94    private HTMLFilter listFilter;
95   
96    /**
97    * {@link HTMLFilter} for filtering tables.
98    */
99    @Inject
100    @Named("officeimporter/table")
101    private HTMLFilter tableFilter;
102   
 
103  0 toggle @Override
104    public Document clean(Reader originalHtmlContent)
105    {
106  0 return clean(originalHtmlContent, getDefaultConfiguration());
107    }
108   
 
109  1 toggle @Override
110    public Document clean(Reader originalHtmlContent, HTMLCleanerConfiguration configuration)
111    {
112  1 return this.defaultHtmlCleaner.clean(originalHtmlContent, configuration);
113    }
114   
 
115  0 toggle @Override
116    public HTMLCleanerConfiguration getDefaultConfiguration()
117    {
118  0 HTMLCleanerConfiguration configuration = this.defaultHtmlCleaner.getDefaultConfiguration();
119   
120    // Add office cleaning filters after the default filters.
121  0 List<HTMLFilter> filters = new ArrayList<HTMLFilter>(configuration.getFilters());
122  0 filters.addAll(Arrays.asList(
123    this.stripperFilter,
124    this.styleFilter,
125    this.redundancyFilter,
126    this.paragraphFilter,
127    this.imageFilter,
128    this.listFilter,
129    this.tableFilter));
130  0 configuration.setFilters(filters);
131   
132  0 return configuration;
133    }
134    }