1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.filter.output; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Provider; |
24 |
|
|
25 |
|
import org.apache.commons.lang3.StringUtils; |
26 |
|
import org.xwiki.component.annotation.Component; |
27 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
28 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
29 |
|
import org.xwiki.component.phase.Initializable; |
30 |
|
import org.xwiki.component.phase.InitializationException; |
31 |
|
import org.xwiki.filter.FilterEventParameters; |
32 |
|
import org.xwiki.filter.FilterException; |
33 |
|
import org.xwiki.filter.event.model.WikiObjectFilter; |
34 |
|
import org.xwiki.model.reference.EntityReference; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWikiContext; |
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
import com.xpn.xwiki.objects.BaseObject; |
39 |
|
import com.xpn.xwiki.objects.BaseObjectReference; |
40 |
|
import com.xpn.xwiki.objects.BaseProperty; |
41 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
47 |
|
@Component |
48 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 86.1% |
Uncovered Elements: 10 (72) |
Complexity: 21 |
Complexity Density: 0.48 |
|
49 |
|
public class BaseObjectOutputFilterStream extends AbstractEntityOutputFilterStream<BaseObject> implements Initializable |
50 |
|
{ |
51 |
|
@Inject |
52 |
|
private EntityOutputFilterStream<BaseClass> classFilter; |
53 |
|
|
54 |
|
@Inject |
55 |
|
private EntityOutputFilterStream<BaseProperty> propertyFilter; |
56 |
|
|
57 |
|
@Inject |
58 |
|
private Provider<XWikiContext> xcontextProvider; |
59 |
|
|
60 |
|
private BaseObject externalEntity; |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
2537 |
@Override... |
63 |
|
public void initialize() throws InitializationException |
64 |
|
{ |
65 |
2537 |
initialize(this.classFilter, this.propertyFilter); |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
68 |
2948 |
@Override... |
69 |
|
public void setEntity(BaseObject entity) |
70 |
|
{ |
71 |
2948 |
super.setEntity(entity); |
72 |
|
|
73 |
2948 |
this.externalEntity = entity; |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
14740 |
private BaseClassOutputFilterStream getBaseClassOutputFilterStream()... |
77 |
|
{ |
78 |
14740 |
return (BaseClassOutputFilterStream) this.classFilter; |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
42723 |
private BasePropertyOutputFilterStream getBasePropertyOutputFilterStream()... |
82 |
|
{ |
83 |
42723 |
return (BasePropertyOutputFilterStream) this.propertyFilter; |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
|
|
|
| 70% |
Uncovered Elements: 6 (20) |
Complexity: 6 |
Complexity Density: 0.43 |
|
88 |
3275 |
@Override... |
89 |
|
public void endWikiClass(FilterEventParameters parameters) throws FilterException |
90 |
|
{ |
91 |
3275 |
if (this.entity != null) { |
92 |
2948 |
BaseClass xclass = getBaseClassOutputFilterStream().getEntity(); |
93 |
|
|
94 |
2948 |
if (xclass != null) { |
95 |
|
|
96 |
2948 |
if (this.externalEntity == null && StringUtils.isNotEmpty(xclass.getCustomClass())) { |
97 |
10 |
BaseObject customObject; |
98 |
10 |
try { |
99 |
10 |
customObject = xclass.newCustomClassInstance(this.xcontextProvider.get()); |
100 |
0 |
customObject.setDocumentReference(this.entity.getDocumentReference()); |
101 |
0 |
customObject.setXClassReference(this.entity.getXClassReference()); |
102 |
0 |
customObject.setOwnerDocument(this.entity.getOwnerDocument()); |
103 |
|
|
104 |
0 |
customObject.apply(this.entity, false); |
105 |
|
|
106 |
0 |
this.entity = customObject; |
107 |
|
} catch (XWikiException e) { |
108 |
|
|
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
2948 |
getBasePropertyOutputFilterStream().setCurrentXClass(xclass); |
113 |
2948 |
getBaseClassOutputFilterStream().setEntity(null); |
114 |
|
} |
115 |
|
} |
116 |
|
} |
117 |
|
|
|
|
| 89.3% |
Uncovered Elements: 3 (28) |
Complexity: 7 |
Complexity Density: 0.39 |
|
118 |
2948 |
@Override... |
119 |
|
public void beginWikiObject(String name, FilterEventParameters parameters) throws FilterException |
120 |
|
{ |
121 |
2948 |
super.beginWikiObject(name, parameters); |
122 |
|
|
123 |
2948 |
if (this.enabled) { |
124 |
2948 |
if (this.entity == null) { |
125 |
2948 |
this.entity = new BaseObject(); |
126 |
|
} |
127 |
|
|
128 |
2948 |
if (parameters.containsKey(WikiObjectFilter.PARAMETER_NAME)) { |
129 |
2944 |
this.entity |
130 |
|
.setDocumentReference(getDocumentReference(WikiObjectFilter.PARAMETER_NAME, parameters, null)); |
131 |
|
} |
132 |
|
|
133 |
2948 |
int number = getInt(WikiObjectFilter.PARAMETER_NUMBER, parameters, -1); |
134 |
|
|
135 |
2948 |
EntityReference classReference = |
136 |
|
getEntityReference(WikiObjectFilter.PARAMETER_CLASS_REFERENCE, parameters, null); |
137 |
2948 |
if (classReference == null) { |
138 |
2 |
BaseObjectReference reference = new BaseObjectReference(this.currentEntityReference); |
139 |
|
|
140 |
2 |
classReference = reference.getXClassReference(); |
141 |
|
|
142 |
2 |
if (number < 0 && reference.getObjectNumber() != null) { |
143 |
2 |
number = reference.getObjectNumber(); |
144 |
|
} |
145 |
|
} |
146 |
2948 |
this.entity.setXClassReference(classReference); |
147 |
|
|
148 |
2948 |
this.entity.setNumber(number); |
149 |
|
|
150 |
2948 |
this.entity.setGuid(getString(WikiObjectFilter.PARAMETER_GUID, parameters, null)); |
151 |
|
|
152 |
2948 |
getBaseClassOutputFilterStream().enable(); |
153 |
2948 |
getBasePropertyOutputFilterStream().enable(); |
154 |
|
} |
155 |
|
} |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
157 |
2948 |
@Override... |
158 |
|
public void endWikiObject(String name, FilterEventParameters parameters) throws FilterException |
159 |
|
{ |
160 |
2948 |
super.endWikiObject(name, parameters); |
161 |
|
|
162 |
2948 |
getBaseClassOutputFilterStream().disable(); |
163 |
2948 |
getBaseClassOutputFilterStream().disable(); |
164 |
|
} |
165 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
166 |
12301 |
@Override... |
167 |
|
public void onWikiObjectProperty(String name, Object value, FilterEventParameters parameters) throws FilterException |
168 |
|
{ |
169 |
12301 |
if (this.enabled) { |
170 |
12301 |
if (getBasePropertyOutputFilterStream().getEntity() != null) { |
171 |
12263 |
this.entity.safeput(name, getBasePropertyOutputFilterStream().getEntity()); |
172 |
|
|
173 |
12263 |
getBasePropertyOutputFilterStream().setEntity(null); |
174 |
|
} |
175 |
|
} |
176 |
|
} |
177 |
|
} |