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.Named; |
24 |
|
import javax.inject.Provider; |
25 |
|
|
26 |
|
import org.apache.commons.lang3.StringUtils; |
27 |
|
import org.slf4j.Logger; |
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
30 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
32 |
|
import org.xwiki.component.manager.ComponentManager; |
33 |
|
import org.xwiki.filter.FilterEventParameters; |
34 |
|
import org.xwiki.filter.FilterException; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWikiException; |
37 |
|
import com.xpn.xwiki.internal.objects.classes.PropertyClassProvider; |
38 |
|
import com.xpn.xwiki.internal.objects.meta.PropertyMetaClassInterface; |
39 |
|
import com.xpn.xwiki.objects.BaseProperty; |
40 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
41 |
|
import com.xpn.xwiki.objects.classes.PropertyClass; |
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
47 |
|
@Component |
48 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 88.6% |
Uncovered Elements: 5 (44) |
Complexity: 12 |
Complexity Density: 0.43 |
|
49 |
|
public class PropertyClassOutputFilterStream extends AbstractEntityOutputFilterStream<PropertyClass> |
50 |
|
{ |
51 |
|
@Inject |
52 |
|
@Named("context") |
53 |
|
private Provider<ComponentManager> componentManagerProvider; |
54 |
|
|
55 |
|
@Inject |
56 |
|
private Logger logger; |
57 |
|
|
58 |
|
private BaseClass currentXClass; |
59 |
|
|
60 |
|
private PropertyMetaClassInterface currentClassPropertyMeta; |
61 |
|
|
62 |
|
|
63 |
|
@param@link |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
13311 |
public void setCurrentXClass(BaseClass currentXClass)... |
66 |
|
{ |
67 |
13310 |
this.currentXClass = currentXClass; |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
|
|
| 84.6% |
Uncovered Elements: 4 (26) |
Complexity: 6 |
Complexity Density: 0.33 |
|
72 |
51887 |
@Override... |
73 |
|
public void beginWikiClassProperty(String name, String type, FilterEventParameters parameters) |
74 |
|
throws FilterException |
75 |
|
{ |
76 |
51888 |
if (this.enabled) { |
77 |
37533 |
ComponentManager componentManager = this.componentManagerProvider.get(); |
78 |
|
|
79 |
37531 |
this.currentClassPropertyMeta = null; |
80 |
|
|
81 |
37530 |
PropertyClassProvider provider; |
82 |
|
|
83 |
|
|
84 |
37531 |
try { |
85 |
37532 |
if (componentManager.hasComponent(PropertyClassProvider.class, type)) { |
86 |
0 |
provider = componentManager.getInstance(PropertyClassProvider.class, type); |
87 |
|
} else { |
88 |
|
|
89 |
|
|
90 |
37532 |
String classType = StringUtils.removeEnd(StringUtils.substringAfterLast(type, "."), "Class"); |
91 |
37533 |
if (componentManager.hasComponent(PropertyClassProvider.class, classType)) { |
92 |
37532 |
provider = componentManager.getInstance(PropertyClassProvider.class, classType); |
93 |
|
} else { |
94 |
1 |
this.logger.warn("Unknown property type [{}]", type); |
95 |
|
|
96 |
1 |
return; |
97 |
|
} |
98 |
|
} |
99 |
|
} catch (ComponentLookupException e) { |
100 |
0 |
throw new FilterException( |
101 |
|
String.format("Failed to get instance of the property class provider for type [%s]", type), e); |
102 |
|
} |
103 |
|
|
104 |
37532 |
this.currentClassPropertyMeta = provider.getDefinition(); |
105 |
|
|
106 |
37532 |
if (this.entity == null) { |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
37532 |
this.entity = (PropertyClass) provider.getInstance(); |
111 |
|
} |
112 |
|
|
113 |
37531 |
this.entity.setName(name); |
114 |
37532 |
this.entity.setObject(this.currentXClass); |
115 |
|
} |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
118 |
51888 |
@Override... |
119 |
|
public void endWikiClassProperty(String name, String type, FilterEventParameters parameters) throws FilterException |
120 |
|
{ |
121 |
51890 |
if (this.enabled) { |
122 |
37530 |
this.currentClassPropertyMeta = null; |
123 |
|
} |
124 |
|
} |
125 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
126 |
445879 |
@Override... |
127 |
|
public void onWikiClassPropertyField(String name, String value, FilterEventParameters parameters) |
128 |
|
throws FilterException |
129 |
|
{ |
130 |
445887 |
if (this.entity != null) { |
131 |
315871 |
PropertyClass propertyClass; |
132 |
315873 |
try { |
133 |
315876 |
propertyClass = (PropertyClass) this.currentClassPropertyMeta.get(name); |
134 |
|
} catch (XWikiException e) { |
135 |
0 |
throw new FilterException(String.format("Failed to get definition of field [%s] for property type [%s]", |
136 |
|
name, this.entity.getClassType()), e); |
137 |
|
} |
138 |
|
|
139 |
315896 |
BaseProperty<?> field = propertyClass.fromString(value); |
140 |
|
|
141 |
315884 |
this.entity.safeput(name, field); |
142 |
|
} |
143 |
|
} |
144 |
|
} |