1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.configuration.internal; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
import java.util.Iterator; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Provider; |
28 |
|
|
29 |
|
import org.xwiki.configuration.ConfigurationSource; |
30 |
|
import org.xwiki.model.reference.DocumentReference; |
31 |
|
import org.xwiki.model.reference.SpaceReference; |
32 |
|
|
33 |
|
import com.xpn.xwiki.XWikiContext; |
34 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.5 |
|
42 |
|
public abstract class AbstractSpacesConfigurationSource extends AbstractCompositeConfigurationSource |
43 |
|
{ |
44 |
|
@Inject |
45 |
|
private Provider<XWikiContext> xcontextProvider; |
46 |
|
|
|
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 6 |
Complexity Density: 0.6 |
|
47 |
|
private class SpaceIterator implements Iterator<ConfigurationSource> |
48 |
|
{ |
49 |
|
private SpaceReference reference; |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
86902 |
SpaceIterator(SpaceReference reference)... |
52 |
|
{ |
53 |
86893 |
this.reference = reference; |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
183997 |
@Override... |
57 |
|
public boolean hasNext() |
58 |
|
{ |
59 |
183996 |
return this.reference != null; |
60 |
|
} |
61 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
62 |
97090 |
@Override... |
63 |
|
public ConfigurationSource next() |
64 |
|
{ |
65 |
97102 |
SpaceReference next = this.reference; |
66 |
|
|
67 |
97113 |
if (this.reference != null) { |
68 |
|
|
69 |
97123 |
if (this.reference.getParent() instanceof SpaceReference) { |
70 |
10231 |
this.reference = (SpaceReference) this.reference.getParent(); |
71 |
|
} else { |
72 |
86893 |
this.reference = null; |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
97115 |
return new SpaceConfigurationSource(next); |
77 |
|
} |
78 |
|
|
79 |
0 |
return null; |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
@Override... |
83 |
|
public void remove() |
84 |
|
{ |
85 |
0 |
throw new UnsupportedOperationException(); |
86 |
|
} |
87 |
|
|
88 |
|
} |
89 |
|
|
|
|
| 95.7% |
Uncovered Elements: 2 (47) |
Complexity: 11 |
Complexity Density: 0.32 |
|
90 |
|
private class SpaceConfigurationSource implements ConfigurationSource |
91 |
|
{ |
92 |
|
private SpaceReference reference; |
93 |
|
|
94 |
|
private XWikiDocument document; |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
97110 |
SpaceConfigurationSource(SpaceReference reference)... |
97 |
|
{ |
98 |
97118 |
this.reference = reference; |
99 |
|
} |
100 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
101 |
194269 |
private XWikiDocument setCurrentDocument(XWikiDocument document)... |
102 |
|
{ |
103 |
194275 |
XWikiContext xcontext = xcontextProvider.get(); |
104 |
194300 |
if (xcontext != null) { |
105 |
194289 |
XWikiDocument currentDocument = xcontext.getDoc(); |
106 |
194292 |
xcontext.setDoc(document); |
107 |
194293 |
return currentDocument; |
108 |
|
} |
109 |
|
|
110 |
0 |
return null; |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
113 |
97104 |
public XWikiDocument getDocument()... |
114 |
|
{ |
115 |
97114 |
if (this.document == null) { |
116 |
97097 |
this.document = new XWikiDocument( |
117 |
|
new DocumentReference(SpacePreferencesConfigurationSource.DOCUMENT_NAME, this.reference)); |
118 |
|
} |
119 |
|
|
120 |
97146 |
return this.document; |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
123 |
2 |
@Override... |
124 |
|
public <T> T getProperty(String key, T defaultValue) |
125 |
|
{ |
126 |
2 |
XWikiDocument currentDocument = setCurrentDocument(getDocument()); |
127 |
2 |
try { |
128 |
2 |
return getSpaceConfigurationSource().getProperty(key, defaultValue); |
129 |
|
} finally { |
130 |
2 |
setCurrentDocument(currentDocument); |
131 |
|
} |
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
134 |
2 |
@Override... |
135 |
|
public <T> T getProperty(String key, Class<T> valueClass) |
136 |
|
{ |
137 |
2 |
XWikiDocument currentDocument = setCurrentDocument(getDocument()); |
138 |
2 |
try { |
139 |
2 |
return getSpaceConfigurationSource().getProperty(key, valueClass); |
140 |
|
} finally { |
141 |
2 |
setCurrentDocument(currentDocument); |
142 |
|
} |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
145 |
5 |
@Override... |
146 |
|
public <T> T getProperty(String key) |
147 |
|
{ |
148 |
5 |
XWikiDocument currentDocument = setCurrentDocument(getDocument()); |
149 |
5 |
try { |
150 |
5 |
return getSpaceConfigurationSource().getProperty(key); |
151 |
|
} finally { |
152 |
5 |
setCurrentDocument(currentDocument); |
153 |
|
} |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
156 |
3 |
@Override... |
157 |
|
public List<String> getKeys() |
158 |
|
{ |
159 |
3 |
XWikiDocument currentDocument = setCurrentDocument(getDocument()); |
160 |
3 |
try { |
161 |
3 |
return getSpaceConfigurationSource().getKeys(); |
162 |
|
} finally { |
163 |
3 |
setCurrentDocument(currentDocument); |
164 |
|
} |
165 |
|
} |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
167 |
97097 |
@Override... |
168 |
|
public boolean containsKey(String key) |
169 |
|
{ |
170 |
97105 |
XWikiDocument currentDocument = setCurrentDocument(getDocument()); |
171 |
97118 |
try { |
172 |
97127 |
return getSpaceConfigurationSource().containsKey(key); |
173 |
|
} finally { |
174 |
97129 |
setCurrentDocument(currentDocument); |
175 |
|
} |
176 |
|
} |
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
178 |
2 |
@Override... |
179 |
|
public boolean isEmpty() |
180 |
|
{ |
181 |
2 |
XWikiDocument currentDocument = setCurrentDocument(getDocument()); |
182 |
2 |
try { |
183 |
2 |
return getSpaceConfigurationSource().isEmpty(); |
184 |
|
} finally { |
185 |
2 |
setCurrentDocument(currentDocument); |
186 |
|
} |
187 |
|
} |
188 |
|
} |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
190 |
212646 |
@Override... |
191 |
|
public Iterator<ConfigurationSource> iterator() |
192 |
|
{ |
193 |
212628 |
XWikiContext xcontext = this.xcontextProvider.get(); |
194 |
|
|
195 |
212634 |
if (xcontext != null) { |
196 |
146055 |
XWikiDocument currentDocument = xcontext.getDoc(); |
197 |
146037 |
if (currentDocument != null) { |
198 |
86897 |
return new SpaceIterator(currentDocument.getDocumentReference().getLastSpaceReference()); |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
125717 |
return Collections.<ConfigurationSource>emptyList().iterator(); |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
@return |
207 |
|
|
208 |
|
protected abstract ConfigurationSource getSpaceConfigurationSource(); |
209 |
|
} |