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.parser; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
|
25 |
|
import org.dom4j.io.SAXContentHandler; |
26 |
|
import org.xml.sax.Attributes; |
27 |
|
import org.xml.sax.SAXException; |
28 |
|
import org.xml.sax.helpers.DefaultHandler; |
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
31 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
32 |
|
import org.xwiki.component.manager.ComponentLookupException; |
33 |
|
import org.xwiki.component.manager.ComponentManager; |
34 |
|
import org.xwiki.rendering.listener.Listener; |
35 |
|
import org.xwiki.rendering.parser.xml.ContentHandlerStreamParser; |
36 |
|
import org.xwiki.rendering.syntax.Syntax; |
37 |
|
import org.xwiki.rendering.xdomxml10.internal.XDOMXMLConstants; |
38 |
|
|
39 |
|
@Component |
40 |
|
@Named("xdom+xml/1.0") |
41 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 80.6% |
Uncovered Elements: 7 (36) |
Complexity: 13 |
Complexity Density: 0.59 |
|
42 |
|
public class XDOMXMLContentHandlerStreamParser extends DefaultHandler implements ContentHandlerStreamParser |
43 |
|
{ |
44 |
|
private Listener listener; |
45 |
|
|
46 |
|
private BlockParser documentParser; |
47 |
|
|
48 |
|
@Inject |
49 |
|
private ComponentManager componentManager; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
public SAXContentHandler currentDOMBuilder = new SAXContentHandler(); |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
0 |
@Override... |
57 |
|
public Syntax getSyntax() |
58 |
|
{ |
59 |
0 |
return Syntax.XDOMXML_1_0; |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
2 |
@Override... |
63 |
|
public void setListener(Listener listener) |
64 |
|
{ |
65 |
2 |
this.listener = listener; |
66 |
|
} |
67 |
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
68 |
18 |
@Override... |
69 |
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException |
70 |
|
{ |
71 |
18 |
if (this.documentParser != null) { |
72 |
16 |
this.documentParser.startElement(uri, localName, qName, attributes); |
73 |
2 |
} else if (XDOMXMLConstants.ELEM_BLOCK.equals(qName)) { |
74 |
2 |
try { |
75 |
2 |
this.documentParser = getDocumentBlockParser(); |
76 |
|
|
77 |
2 |
this.documentParser.setListener(this.listener); |
78 |
2 |
this.documentParser.setVersion(Syntax.XDOMXML_1_0.getVersion()); |
79 |
|
|
80 |
2 |
this.documentParser.startElement(uri, localName, qName, attributes); |
81 |
|
} catch (ComponentLookupException e) { |
82 |
0 |
throw new SAXException("Failed to find a document block parser", e); |
83 |
|
} |
84 |
|
} |
85 |
|
} |
86 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
87 |
8 |
@Override... |
88 |
|
public void characters(char[] ch, int start, int length) throws SAXException |
89 |
|
{ |
90 |
8 |
if (this.documentParser != null) { |
91 |
8 |
this.documentParser.characters(ch, start, length); |
92 |
|
} |
93 |
|
} |
94 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
95 |
18 |
@Override... |
96 |
|
public void endElement(String uri, String localName, String qName) throws SAXException |
97 |
|
{ |
98 |
18 |
if (this.documentParser != null) { |
99 |
18 |
this.documentParser.endElement(uri, localName, qName); |
100 |
|
} |
101 |
|
} |
102 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.43 |
|
103 |
2 |
protected BlockParser getDocumentBlockParser() throws ComponentLookupException... |
104 |
|
{ |
105 |
2 |
BlockParser blockParser; |
106 |
2 |
try { |
107 |
2 |
blockParser = |
108 |
|
this.componentManager.getInstance(BlockParser.class, "document/" + Syntax.XDOMXML_1_0.getVersion()); |
109 |
|
} catch (ComponentLookupException e1) { |
110 |
2 |
try { |
111 |
2 |
blockParser = this.componentManager.getInstance(BlockParser.class, "document"); |
112 |
|
} catch (ComponentLookupException e2) { |
113 |
0 |
blockParser = this.componentManager.getInstance(BlockParser.class); |
114 |
|
} |
115 |
|
} |
116 |
|
|
117 |
2 |
return blockParser; |
118 |
|
} |
119 |
|
} |