1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wysiwyg.server.internal.cleaner; |
21 |
|
|
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
import javax.xml.transform.TransformerException; |
28 |
|
|
29 |
|
import org.apache.xpath.XPathAPI; |
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.w3c.dom.Attr; |
32 |
|
import org.w3c.dom.Document; |
33 |
|
import org.w3c.dom.NodeList; |
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
|
42 |
|
@Component(roles = { HTMLFilter.class }) |
43 |
|
@Named("emptyAttribute") |
44 |
|
@Singleton |
|
|
| 55.6% |
Uncovered Elements: 4 (9) |
Complexity: 3 |
Complexity Density: 0.5 |
|
45 |
|
public class EmptyAttributeFilter extends AbstractHTMLFilter |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@Inject |
51 |
|
private Logger logger; |
52 |
|
|
|
|
| 50% |
Uncovered Elements: 4 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
53 |
13 |
@Override... |
54 |
|
public void filter(Document document, Map<String, String> parameters) |
55 |
|
{ |
56 |
13 |
try { |
57 |
13 |
NodeList emptyAttributes = XPathAPI.selectNodeList(document, "//@*[. = '']"); |
58 |
13 |
for (int i = emptyAttributes.getLength() - 1; i >= 0; i--) { |
59 |
0 |
Attr emptyAttribute = (Attr) emptyAttributes.item(i); |
60 |
0 |
emptyAttribute.getOwnerElement().removeAttributeNode(emptyAttribute); |
61 |
|
} |
62 |
|
} catch (TransformerException e) { |
63 |
0 |
logger.error("Exception while filtering empty attributes.", e); |
64 |
|
} |
65 |
|
} |
66 |
|
} |