| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.rendering.xdomxml.internal.renderer.parameters; |
| 21 |
|
|
| 22 |
|
import java.util.Map; |
| 23 |
|
import java.util.regex.Pattern; |
| 24 |
|
|
| 25 |
|
import org.xml.sax.Attributes; |
| 26 |
|
import org.xml.sax.ContentHandler; |
| 27 |
|
import org.xml.sax.SAXException; |
| 28 |
|
import org.xml.sax.helpers.AttributesImpl; |
| 29 |
|
|
|
|
|
| 65% |
Uncovered Elements: 14 (40) |
Complexity: 13 |
Complexity Density: 0.45 |
|
| 30 |
|
public abstract class AbstractSerializer |
| 31 |
|
{ |
| 32 |
|
public static final Pattern VALIDNAME = Pattern.compile("[A-Za-z][A-Za-z0-9:_.-]*"); |
| 33 |
|
|
| 34 |
|
public static final Attributes EMPTY_ATTRIBUTES = new AttributesImpl(); |
| 35 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 36 |
2
|
public void serializeParameter(String name, Map<String, String> map, ContentHandler contentHandler)... |
| 37 |
|
{ |
| 38 |
2
|
startElement(name, EMPTY_ATTRIBUTES, contentHandler); |
| 39 |
2
|
for (Map.Entry<String, String> entry : map.entrySet()) { |
| 40 |
4
|
serializeParameter(entry.getKey(), entry.getValue(), contentHandler); |
| 41 |
|
} |
| 42 |
2
|
endElement(name, contentHandler); |
| 43 |
|
} |
| 44 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 45 |
0
|
public void serializeParameter(String name, char value, ContentHandler contentHandler)... |
| 46 |
|
{ |
| 47 |
0
|
serializeParameter(name, String.valueOf(value), contentHandler); |
| 48 |
|
} |
| 49 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 50 |
0
|
public void serializeParameter(String name, int value, ContentHandler contentHandler)... |
| 51 |
|
{ |
| 52 |
0
|
serializeParameter(name, String.valueOf(value), contentHandler); |
| 53 |
|
} |
| 54 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 55 |
0
|
public void serializeParameter(String name, boolean value, ContentHandler contentHandler)... |
| 56 |
|
{ |
| 57 |
0
|
serializeParameter(name, String.valueOf(value), contentHandler); |
| 58 |
|
} |
| 59 |
|
|
|
|
|
| 64.3% |
Uncovered Elements: 5 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
| 60 |
75
|
public void serializeParameter(String name, String value, ContentHandler contentHandler)... |
| 61 |
|
{ |
| 62 |
75
|
String nodeName; |
| 63 |
75
|
Attributes attributes; |
| 64 |
|
|
| 65 |
75
|
if (isValidNodeName(name)) { |
| 66 |
75
|
nodeName = name; |
| 67 |
75
|
attributes = EMPTY_ATTRIBUTES; |
| 68 |
|
} else { |
| 69 |
0
|
nodeName = "entry"; |
| 70 |
0
|
AttributesImpl attributesImpl = new AttributesImpl(); |
| 71 |
0
|
attributesImpl.addAttribute(null, null, "name", null, name); |
| 72 |
0
|
attributes = attributesImpl; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
75
|
startElement(nodeName, attributes, contentHandler); |
| 76 |
75
|
characters(value, contentHandler); |
| 77 |
75
|
endElement(nodeName, contentHandler); |
| 78 |
|
} |
| 79 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 80 |
75
|
public boolean isValidNodeName(String name)... |
| 81 |
|
{ |
| 82 |
75
|
return VALIDNAME.matcher(name).matches(); |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 85 |
189
|
public void startElement(String elementName, Attributes attributes, ContentHandler contentHandler)... |
| 86 |
|
{ |
| 87 |
189
|
try { |
| 88 |
189
|
contentHandler.startElement("", elementName, elementName, attributes); |
| 89 |
|
} catch (SAXException e) { |
| 90 |
0
|
throw new RuntimeException("Failed to send sax event", e); |
| 91 |
|
} |
| 92 |
|
} |
| 93 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 94 |
75
|
public void characters(String str, ContentHandler contentHandler)... |
| 95 |
|
{ |
| 96 |
75
|
try { |
| 97 |
75
|
contentHandler.characters(str.toCharArray(), 0, str.length()); |
| 98 |
|
} catch (SAXException e) { |
| 99 |
0
|
throw new RuntimeException("Failed to send sax event", e); |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 103 |
189
|
public void endElement(String elementName, ContentHandler contentHandler)... |
| 104 |
|
{ |
| 105 |
189
|
try { |
| 106 |
189
|
contentHandler.endElement("", elementName, elementName); |
| 107 |
|
} catch (SAXException e) { |
| 108 |
0
|
throw new RuntimeException("Failed to send sax event", e); |
| 109 |
|
} |
| 110 |
|
} |
| 111 |
|
} |