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.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.w3c.dom.Document; |
30 |
|
import org.w3c.dom.Element; |
31 |
|
import org.w3c.dom.Node; |
32 |
|
import org.w3c.dom.NodeList; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
|
43 |
|
@Component(roles = {HTMLFilter.class }) |
44 |
|
@Named("standAloneMacro") |
45 |
|
@Singleton |
|
|
| 53.3% |
Uncovered Elements: 14 (30) |
Complexity: 12 |
Complexity Density: 0.67 |
|
46 |
|
public class StandAloneMacroFilter extends AbstractHTMLFilter |
47 |
|
{ |
|
|
| 37.5% |
Uncovered Elements: 5 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
48 |
13 |
@Override... |
49 |
|
public void filter(Document document, Map<String, String> parameters) |
50 |
|
{ |
51 |
13 |
List<Element> wrappers = getStandAloneMacroWrappers(document); |
52 |
13 |
for (int i = 0; i < wrappers.size(); i++) { |
53 |
0 |
Element paragraph = wrappers.get(i); |
54 |
|
|
55 |
0 |
paragraph.getParentNode().insertBefore(paragraph.getFirstChild(), paragraph); |
56 |
0 |
paragraph.getParentNode().insertBefore(paragraph.getLastChild(), paragraph); |
57 |
0 |
paragraph.getParentNode().removeChild(paragraph); |
58 |
|
} |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
@param |
63 |
|
@return |
64 |
|
|
|
|
| 55% |
Uncovered Elements: 9 (20) |
Complexity: 10 |
Complexity Density: 0.83 |
|
65 |
13 |
private List<Element> getStandAloneMacroWrappers(Document document)... |
66 |
|
{ |
67 |
13 |
NodeList paragraphs = document.getElementsByTagName("p"); |
68 |
13 |
List<Element> wrappers = new ArrayList<Element>(); |
69 |
16 |
for (int i = 0; i < paragraphs.getLength(); i++) { |
70 |
3 |
Element paragraph = (Element) paragraphs.item(i); |
71 |
|
|
72 |
|
|
73 |
3 |
Node child = paragraph.getFirstChild(); |
74 |
3 |
if (child == null || child.getNodeType() != Node.COMMENT_NODE |
75 |
|
|| !child.getNodeValue().startsWith("startmacro:")) { |
76 |
3 |
continue; |
77 |
|
} |
78 |
|
|
79 |
0 |
do { |
80 |
0 |
child = child.getNextSibling(); |
81 |
0 |
} while (child != null |
82 |
|
&& !(child.getNodeType() == Node.COMMENT_NODE && child.getNodeValue().equals("stopmacro"))); |
83 |
|
|
84 |
0 |
if (child != null && child.getNextSibling() == null) { |
85 |
0 |
wrappers.add(paragraph); |
86 |
|
} |
87 |
|
} |
88 |
13 |
return wrappers; |
89 |
|
} |
90 |
|
} |