1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.xdomxml10.internal.renderer.parameter; |
21 |
|
|
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import org.xml.sax.Attributes; |
25 |
|
import org.xml.sax.ContentHandler; |
26 |
|
import org.xml.sax.SAXException; |
27 |
|
import org.xml.sax.helpers.AttributesImpl; |
28 |
|
import org.xwiki.rendering.xdomxml10.internal.XDOMXMLConstants; |
29 |
|
|
|
|
| 70.2% |
Uncovered Elements: 17 (57) |
Complexity: 17 |
Complexity Density: 0.43 |
|
30 |
|
public abstract class AbstractSerializer |
31 |
|
{ |
32 |
|
public static final Attributes EMPTY_ATTRIBUTES = new AttributesImpl(); |
33 |
|
|
34 |
|
|
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
35 |
2 |
public void serializeParameter(String name, Map< ? , ? > map, boolean type, ContentHandler contentHandler)... |
36 |
|
{ |
37 |
2 |
Attributes attributes; |
38 |
|
|
39 |
2 |
if (type) { |
40 |
2 |
AttributesImpl attributesImpl = new AttributesImpl(); |
41 |
2 |
attributesImpl.addAttribute(null, null, "type", null, "stringmap"); |
42 |
2 |
attributes = attributesImpl; |
43 |
|
} else { |
44 |
0 |
attributes = EMPTY_ATTRIBUTES; |
45 |
|
} |
46 |
|
|
47 |
2 |
startElement(name, attributes, contentHandler); |
48 |
2 |
for (Map.Entry< ? , ? > entry : map.entrySet()) { |
49 |
2 |
if (entry.getValue() != null && entry.getKey() != null) { |
50 |
2 |
serializeParameter(entry.getKey().toString(), entry.getValue().toString(), null, contentHandler); |
51 |
|
} |
52 |
|
} |
53 |
2 |
endElement(name, contentHandler); |
54 |
|
} |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
0 |
public void serializeParameter(String name, char value, boolean type, ContentHandler contentHandler)... |
57 |
|
{ |
58 |
0 |
serializeParameter(name, String.valueOf(value), "char", contentHandler); |
59 |
|
} |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
0 |
public void serializeParameter(String name, int value, boolean type, ContentHandler contentHandler)... |
62 |
|
{ |
63 |
0 |
serializeParameter(name, String.valueOf(value), "int", contentHandler); |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
public void serializeParameter(String name, boolean value, boolean type, ContentHandler contentHandler)... |
67 |
|
{ |
68 |
0 |
serializeParameter(name, String.valueOf(value), "bool", contentHandler); |
69 |
|
} |
70 |
|
|
|
|
| 75% |
Uncovered Elements: 5 (20) |
Complexity: 3 |
Complexity Density: 0.19 |
|
71 |
8 |
public void serializeParameter(String name, String value, String type, ContentHandler contentHandler)... |
72 |
|
{ |
73 |
8 |
String nodeName; |
74 |
8 |
Attributes attributes; |
75 |
|
|
76 |
8 |
if (isValidNodeName(name)) { |
77 |
8 |
nodeName = name; |
78 |
8 |
if (type == null) { |
79 |
6 |
attributes = EMPTY_ATTRIBUTES; |
80 |
|
} else { |
81 |
2 |
AttributesImpl attributesImpl = new AttributesImpl(); |
82 |
2 |
attributesImpl.addAttribute(null, null, "type", null, type); |
83 |
2 |
attributes = attributesImpl; |
84 |
|
} |
85 |
|
} else { |
86 |
0 |
nodeName = "entry"; |
87 |
0 |
AttributesImpl attributesImpl = new AttributesImpl(); |
88 |
0 |
attributesImpl.addAttribute(null, null, "name", null, name); |
89 |
0 |
attributes = attributesImpl; |
90 |
|
} |
91 |
|
|
92 |
8 |
startElement(nodeName, attributes, contentHandler); |
93 |
8 |
characters(value, contentHandler); |
94 |
8 |
endElement(nodeName, contentHandler); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
8 |
public boolean isValidNodeName(String name)... |
98 |
|
{ |
99 |
8 |
return XDOMXMLConstants.VALID_ELEMENTNAME.matcher(name).matches(); |
100 |
|
} |
101 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
102 |
18 |
public void startElement(String elementName, Attributes attributes, ContentHandler contentHandler)... |
103 |
|
{ |
104 |
18 |
try { |
105 |
18 |
contentHandler.startElement("", elementName, elementName, attributes); |
106 |
|
} catch (SAXException e) { |
107 |
0 |
throw new RuntimeException("Failed to send sax event", e); |
108 |
|
} |
109 |
|
} |
110 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
111 |
8 |
public void characters(String str, ContentHandler contentHandler)... |
112 |
|
{ |
113 |
8 |
try { |
114 |
8 |
contentHandler.characters(str.toCharArray(), 0, str.length()); |
115 |
|
} catch (SAXException e) { |
116 |
0 |
throw new RuntimeException("Failed to send sax event", e); |
117 |
|
} |
118 |
|
} |
119 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
120 |
18 |
public void endElement(String elementName, ContentHandler contentHandler)... |
121 |
|
{ |
122 |
18 |
try { |
123 |
18 |
contentHandler.endElement("", elementName, elementName); |
124 |
|
} catch (SAXException e) { |
125 |
0 |
throw new RuntimeException("Failed to send sax event", e); |
126 |
|
} |
127 |
|
} |
128 |
|
} |