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 |
|
|
24 |
|
import org.xml.sax.Attributes; |
25 |
|
import org.xml.sax.ContentHandler; |
26 |
|
import org.xml.sax.SAXException; |
27 |
|
import org.xml.sax.helpers.DefaultHandler; |
28 |
|
import org.xwiki.component.manager.ComponentLookupException; |
29 |
|
import org.xwiki.component.manager.ComponentManager; |
30 |
|
import org.xwiki.rendering.listener.Listener; |
31 |
|
import org.xwiki.rendering.xdomxml10.internal.XDOMXMLConstants; |
32 |
|
|
|
|
| 79.3% |
Uncovered Elements: 19 (92) |
Complexity: 33 |
Complexity Density: 0.61 |
|
33 |
|
public abstract class AbstractBlockParser extends DefaultHandler implements BlockParser |
34 |
|
{ |
35 |
|
@Inject |
36 |
|
private ComponentManager componentManager; |
37 |
|
|
38 |
|
private String blockName; |
39 |
|
|
40 |
|
private ContentHandler currentHandler; |
41 |
|
|
42 |
|
private int currentHandlerLevel; |
43 |
|
|
44 |
|
private int level = 0; |
45 |
|
|
46 |
|
private String blockVersion; |
47 |
|
|
48 |
|
private boolean beginBlockFlushed; |
49 |
|
|
50 |
|
private Listener listener; |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0 |
public void setComponentManager(ComponentManager componentManager)... |
53 |
|
{ |
54 |
0 |
this.componentManager = componentManager; |
55 |
|
} |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
0 |
public ComponentManager getComponentManager()... |
58 |
|
{ |
59 |
0 |
return componentManager; |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
10 |
@Override... |
63 |
|
public Listener getListener() |
64 |
|
{ |
65 |
10 |
return this.listener; |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
4 |
@Override... |
69 |
|
public void setListener(Listener listener) |
70 |
|
{ |
71 |
4 |
this.listener = listener; |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
4 |
@Override... |
75 |
|
public String getVersion() |
76 |
|
{ |
77 |
4 |
return this.blockVersion; |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
4 |
@Override... |
81 |
|
public void setVersion(String version) |
82 |
|
{ |
83 |
4 |
this.blockVersion = version; |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0 |
public String getBlockName()... |
87 |
|
{ |
88 |
0 |
return this.blockName; |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
10 |
public int getLevel()... |
92 |
|
{ |
93 |
10 |
return this.level; |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
|
|
| 96.3% |
Uncovered Elements: 1 (27) |
Complexity: 7 |
Complexity Density: 0.37 |
|
98 |
28 |
@Override... |
99 |
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException |
100 |
|
{ |
101 |
28 |
if (this.currentHandler != null) { |
102 |
18 |
this.currentHandler.startElement(uri, localName, qName, attributes); |
103 |
|
} else { |
104 |
10 |
if (qName.equals(XDOMXMLConstants.ELEM_BLOCK)) { |
105 |
6 |
String name = attributes.getValue(XDOMXMLConstants.ATT_BLOCK_NAME); |
106 |
6 |
String version = attributes.getValue(XDOMXMLConstants.ATT_BLOCK_VERSION); |
107 |
|
|
108 |
6 |
if (this.level == 0 && this.blockName == null) { |
109 |
4 |
this.blockName = name; |
110 |
4 |
this.blockVersion = version; |
111 |
|
} else { |
112 |
2 |
flushBeginBlock(); |
113 |
|
|
114 |
|
|
115 |
2 |
try { |
116 |
2 |
BlockParser blockParser = getBlockParser(name); |
117 |
|
|
118 |
2 |
blockParser.setListener(getListener()); |
119 |
2 |
blockParser.setVersion(getVersion()); |
120 |
|
|
121 |
2 |
setCurrentHandler(blockParser); |
122 |
|
} catch (ComponentLookupException e) { |
123 |
0 |
throw new SAXException("Failed to find a block parser for [" + name + "]", e); |
124 |
|
} |
125 |
|
} |
126 |
|
} else { |
127 |
4 |
startElementInternal(uri, localName, qName, attributes); |
128 |
|
} |
129 |
|
|
130 |
10 |
if (this.currentHandler != null) { |
131 |
6 |
this.currentHandler.startElement(uri, localName, qName, attributes); |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
28 |
++this.level; |
136 |
|
} |
137 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
138 |
12 |
@Override... |
139 |
|
public void characters(char[] ch, int start, int length) throws SAXException |
140 |
|
{ |
141 |
12 |
if (this.currentHandler != null) { |
142 |
12 |
this.currentHandler.characters(ch, start, length); |
143 |
|
} else { |
144 |
0 |
charactersInternal(ch, start, length); |
145 |
|
} |
146 |
|
} |
147 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
148 |
28 |
@Override... |
149 |
|
public void endElement(String uri, String localName, String qName) throws SAXException |
150 |
|
{ |
151 |
28 |
--this.level; |
152 |
|
|
153 |
28 |
if (this.currentHandler != null) { |
154 |
24 |
this.currentHandler.endElement(uri, localName, qName); |
155 |
|
|
156 |
24 |
if (this.level == this.currentHandlerLevel) { |
157 |
6 |
endElementInternal(uri, localName, qName); |
158 |
6 |
this.currentHandler = null; |
159 |
|
} |
160 |
|
} else { |
161 |
4 |
if (this.level == 0) { |
162 |
4 |
flushBeginBlock(); |
163 |
4 |
endElementInternal(uri, localName, qName); |
164 |
4 |
endBlock(); |
165 |
|
} else { |
166 |
0 |
endElementInternal(uri, localName, qName); |
167 |
|
} |
168 |
|
} |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
173 |
0 |
protected void startElementInternal(String uri, String localName, String qName, Attributes attributes)... |
174 |
|
throws SAXException |
175 |
|
{ |
176 |
|
|
177 |
|
} |
178 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
179 |
0 |
protected void charactersInternal(char[] ch, int start, int length) throws SAXException... |
180 |
|
{ |
181 |
|
|
182 |
|
} |
183 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
184 |
0 |
protected void endElementInternal(String uri, String localName, String qName) throws SAXException... |
185 |
|
{ |
186 |
|
|
187 |
|
} |
188 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
189 |
0 |
protected void beginBlock() throws SAXException... |
190 |
|
{ |
191 |
|
|
192 |
|
} |
193 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
194 |
0 |
protected void endBlock() throws SAXException... |
195 |
|
{ |
196 |
|
|
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
201 |
6 |
protected void flushBeginBlock() throws SAXException... |
202 |
|
{ |
203 |
6 |
if (!this.beginBlockFlushed) { |
204 |
4 |
beginBlock(); |
205 |
4 |
this.beginBlockFlushed = true; |
206 |
|
} |
207 |
|
} |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
209 |
6 |
protected void setCurrentHandler(ContentHandler currentHandler)... |
210 |
|
{ |
211 |
6 |
this.currentHandler = currentHandler; |
212 |
6 |
this.currentHandlerLevel = this.level; |
213 |
|
} |
214 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
215 |
0 |
public ContentHandler getCurrentHandler()... |
216 |
|
{ |
217 |
0 |
return this.currentHandler; |
218 |
|
} |
219 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.43 |
|
220 |
2 |
protected BlockParser getBlockParser(String name) throws ComponentLookupException... |
221 |
|
{ |
222 |
2 |
BlockParser blockParser; |
223 |
2 |
try { |
224 |
2 |
blockParser = this.componentManager.getInstance(BlockParser.class, name.toLowerCase() + "/" + getVersion()); |
225 |
|
} catch (ComponentLookupException e1) { |
226 |
2 |
try { |
227 |
2 |
blockParser = this.componentManager.getInstance(BlockParser.class, name.toLowerCase()); |
228 |
|
} catch (ComponentLookupException e2) { |
229 |
0 |
blockParser = this.componentManager.getInstance(BlockParser.class); |
230 |
|
} |
231 |
|
} |
232 |
|
|
233 |
2 |
return blockParser; |
234 |
|
} |
235 |
|
} |