1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.xar.internal.input; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Singleton; |
27 |
|
import javax.xml.stream.XMLStreamException; |
28 |
|
import javax.xml.stream.XMLStreamReader; |
29 |
|
|
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.filter.FilterEventParameters; |
32 |
|
import org.xwiki.filter.FilterException; |
33 |
|
import org.xwiki.filter.event.model.WikiObjectFilter; |
34 |
|
import org.xwiki.filter.xar.input.XARInputProperties; |
35 |
|
import org.xwiki.filter.xar.internal.XARClassModel; |
36 |
|
import org.xwiki.filter.xar.internal.XARFilterUtils.EventParameter; |
37 |
|
import org.xwiki.filter.xar.internal.XARObjectModel; |
38 |
|
import org.xwiki.filter.xar.internal.XARObjectPropertyModel; |
39 |
|
import org.xwiki.filter.xar.internal.input.ClassReader.WikiClass; |
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Singleton |
|
|
| 92% |
Uncovered Elements: 2 (25) |
Complexity: 6 |
Complexity Density: 0.43 |
|
47 |
|
public class WikiObjectReader extends AbstractWikiObjectPropertyReader |
48 |
|
implements XARXMLReader<WikiObjectReader.WikiObject> |
49 |
|
{ |
50 |
|
@Inject |
51 |
|
private XARXMLReader<ClassReader.WikiClass> classReader; |
52 |
|
|
|
|
| 90.5% |
Uncovered Elements: 2 (21) |
Complexity: 4 |
Complexity Density: 0.29 |
|
53 |
|
public static class WikiObject |
54 |
|
{ |
55 |
|
public WikiClass wikiClass; |
56 |
|
|
57 |
|
public FilterEventParameters parameters = new FilterEventParameters(); |
58 |
|
|
59 |
|
private List<WikiObjectProperty> properties = new ArrayList<WikiObjectProperty>(); |
60 |
|
|
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
61 |
2958 |
public void send(XARInputFilter proxyFilter) throws FilterException... |
62 |
|
{ |
63 |
2958 |
String name = null; |
64 |
|
|
65 |
2958 |
if (this.parameters.containsKey(WikiObjectFilter.PARAMETER_CLASS_REFERENCE)) { |
66 |
2958 |
StringBuilder nameBuilder = |
67 |
|
new StringBuilder(this.parameters.get(WikiObjectFilter.PARAMETER_CLASS_REFERENCE).toString()); |
68 |
|
|
69 |
2958 |
if (this.parameters.containsKey(WikiObjectFilter.PARAMETER_NUMBER)) { |
70 |
2958 |
nameBuilder.append('['); |
71 |
2958 |
nameBuilder.append(this.parameters.get(WikiObjectFilter.PARAMETER_NUMBER)); |
72 |
2958 |
nameBuilder.append(']'); |
73 |
|
} |
74 |
|
|
75 |
2958 |
name = nameBuilder.toString(); |
76 |
|
} |
77 |
|
|
78 |
2958 |
proxyFilter.beginWikiObject(name, this.parameters); |
79 |
|
|
80 |
2958 |
if (this.wikiClass != null) { |
81 |
2956 |
this.wikiClass.send(proxyFilter); |
82 |
|
} |
83 |
|
|
84 |
2958 |
for (WikiObjectProperty property : this.properties) { |
85 |
12325 |
property.send(proxyFilter); |
86 |
|
} |
87 |
|
|
88 |
2958 |
proxyFilter.endWikiObject(name, this.parameters); |
89 |
|
} |
90 |
|
} |
91 |
|
|
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 6 |
Complexity Density: 0.43 |
|
92 |
2958 |
@Override... |
93 |
|
public WikiObject read(XMLStreamReader xmlReader, XARInputProperties properties) |
94 |
|
throws XMLStreamException, FilterException |
95 |
|
{ |
96 |
2958 |
WikiObject wikiObject = new WikiObject(); |
97 |
|
|
98 |
30064 |
for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { |
99 |
27106 |
String elementName = xmlReader.getLocalName(); |
100 |
27106 |
if (elementName.equals(XARClassModel.ELEMENT_CLASS)) { |
101 |
2956 |
wikiObject.wikiClass = this.classReader.read(xmlReader, properties); |
102 |
24150 |
} else if (elementName.equals(XARObjectPropertyModel.ELEMENT_PROPERTY)) { |
103 |
12325 |
wikiObject.properties.add(readObjectProperty(xmlReader, properties, wikiObject.wikiClass)); |
104 |
|
} else { |
105 |
11825 |
String value = xmlReader.getElementText(); |
106 |
|
|
107 |
11825 |
EventParameter parameter = XARObjectModel.OBJECT_PARAMETERS.get(elementName); |
108 |
|
|
109 |
11825 |
if (parameter != null) { |
110 |
11825 |
Object wsValue = convert(parameter.type, value); |
111 |
11825 |
if (wsValue != null) { |
112 |
11825 |
wikiObject.parameters.put(parameter.name, wsValue); |
113 |
|
} |
114 |
|
} |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
2958 |
return wikiObject; |
119 |
|
} |
120 |
|
} |