1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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.Collections; |
26 |
|
import java.util.List; |
27 |
|
|
28 |
|
import javax.inject.Inject; |
29 |
|
import javax.inject.Named; |
30 |
|
import javax.inject.Singleton; |
31 |
|
|
32 |
|
import org.w3c.dom.Document; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
import org.xwiki.xml.html.HTMLCleaner; |
35 |
|
import org.xwiki.xml.html.HTMLCleanerConfiguration; |
36 |
|
import org.xwiki.xml.html.filter.HTMLFilter; |
37 |
|
|
38 |
|
|
39 |
|
@link |
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
44 |
|
@Component |
45 |
|
@Named("openoffice") |
46 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.33 |
|
47 |
|
public class OfficeHTMLCleaner implements HTMLCleaner |
48 |
|
{ |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@Inject |
53 |
|
private HTMLCleaner defaultHtmlCleaner; |
54 |
|
|
55 |
|
|
56 |
|
@link |
57 |
|
|
58 |
|
@Inject |
59 |
|
@Named("officeimporter/stripper") |
60 |
|
private HTMLFilter stripperFilter; |
61 |
|
|
62 |
|
|
63 |
|
@link |
64 |
|
|
65 |
|
@Inject |
66 |
|
@Named("officeimporter/style") |
67 |
|
private HTMLFilter styleFilter; |
68 |
|
|
69 |
|
|
70 |
|
@link |
71 |
|
|
72 |
|
@Inject |
73 |
|
@Named("officeimporter/redundancy") |
74 |
|
private HTMLFilter redundancyFilter; |
75 |
|
|
76 |
|
|
77 |
|
@link |
78 |
|
|
79 |
|
@Inject |
80 |
|
@Named("officeimporter/paragraph") |
81 |
|
private HTMLFilter paragraphFilter; |
82 |
|
|
83 |
|
|
84 |
|
@link |
85 |
|
|
86 |
|
@Inject |
87 |
|
@Named("officeimporter/image") |
88 |
|
private HTMLFilter imageFilter; |
89 |
|
|
90 |
|
|
91 |
|
@link |
92 |
|
|
93 |
|
@Inject |
94 |
|
@Named("officeimporter/anchor") |
95 |
|
private HTMLFilter anchorFilter; |
96 |
|
|
97 |
|
|
98 |
|
@link |
99 |
|
|
100 |
|
@Inject |
101 |
|
@Named("officeimporter/list") |
102 |
|
private HTMLFilter listFilter; |
103 |
|
|
104 |
|
|
105 |
|
@link |
106 |
|
|
107 |
|
@Inject |
108 |
|
@Named("officeimporter/table") |
109 |
|
private HTMLFilter tableFilter; |
110 |
|
|
111 |
|
|
112 |
|
@link |
113 |
|
|
114 |
|
@Inject |
115 |
|
@Named("officeimporter/linebreak") |
116 |
|
private HTMLFilter lineBreakFilter; |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
118 |
34 |
@Override... |
119 |
|
public Document clean(Reader originalHtmlContent) |
120 |
|
{ |
121 |
|
|
122 |
34 |
HTMLCleanerConfiguration configuration = getDefaultConfiguration(); |
123 |
34 |
configuration.setParameters(Collections.singletonMap("filterStyles", "strict")); |
124 |
|
|
125 |
34 |
return clean(originalHtmlContent, configuration); |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
65 |
@Override... |
129 |
|
public Document clean(Reader originalHtmlContent, HTMLCleanerConfiguration configuration) |
130 |
|
{ |
131 |
65 |
return this.defaultHtmlCleaner.clean(originalHtmlContent, configuration); |
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
134 |
66 |
@Override... |
135 |
|
public HTMLCleanerConfiguration getDefaultConfiguration() |
136 |
|
{ |
137 |
66 |
HTMLCleanerConfiguration configuration = this.defaultHtmlCleaner.getDefaultConfiguration(); |
138 |
|
|
139 |
|
|
140 |
66 |
List<HTMLFilter> filters = new ArrayList<HTMLFilter>(configuration.getFilters()); |
141 |
66 |
filters.addAll(Arrays.asList( |
142 |
|
this.stripperFilter, |
143 |
|
this.styleFilter, |
144 |
|
this.redundancyFilter, |
145 |
|
this.paragraphFilter, |
146 |
|
this.imageFilter, |
147 |
|
this.anchorFilter, |
148 |
|
this.listFilter, |
149 |
|
this.tableFilter, |
150 |
|
this.lineBreakFilter)); |
151 |
66 |
configuration.setFilters(filters); |
152 |
|
|
153 |
66 |
return configuration; |
154 |
|
} |
155 |
|
} |