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 org.xwiki.model.reference.DocumentReference; |
23 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
24 |
|
import org.xwiki.model.reference.SpaceReference; |
25 |
|
|
26 |
|
import com.xpn.xwiki.XWikiContext; |
27 |
|
import com.xpn.xwiki.XWikiException; |
28 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
29 |
|
import com.xpn.xwiki.objects.BaseObject; |
30 |
|
import com.xpn.xwiki.objects.BaseProperty; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
@since |
37 |
|
|
|
|
| 83.1% |
Uncovered Elements: 13 (77) |
Complexity: 26 |
Complexity Density: 0.6 |
|
38 |
|
public abstract class AbstractXWikiPreferencesConfigurationSource extends AbstractDocumentConfigurationSource |
39 |
|
{ |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
protected static final String CLASS_SPACE_NAME = "XWiki"; |
44 |
|
|
45 |
|
protected static final String CLASS_PAGE_NAME = "XWikiPreferences"; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
protected static final LocalDocumentReference CLASS_REFERENCE = new LocalDocumentReference(CLASS_SPACE_NAME, |
51 |
|
CLASS_PAGE_NAME); |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
53 |
0 |
@Override... |
54 |
|
protected String getCacheKeyPrefix() |
55 |
|
{ |
56 |
0 |
DocumentReference currentDocumentReference = getDocumentReference(); |
57 |
0 |
if (currentDocumentReference != null) { |
58 |
0 |
return this.referenceSerializer.serialize(currentDocumentReference.getParent()); |
59 |
|
} |
60 |
|
|
61 |
0 |
return null; |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
52127 |
@Override... |
65 |
|
protected LocalDocumentReference getClassReference() |
66 |
|
{ |
67 |
52132 |
return CLASS_REFERENCE; |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
@Override... |
71 |
|
protected DocumentReference getDocumentReference() |
72 |
|
{ |
73 |
0 |
return new DocumentReference(CLASS_REFERENCE.getName(), new SpaceReference(CLASS_SPACE_NAME, |
74 |
|
getCurrentWikiReference())); |
75 |
|
} |
76 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 5 |
Complexity Density: 0.62 |
|
77 |
26065 |
protected BaseObject getBaseObject(String language) throws XWikiException... |
78 |
|
{ |
79 |
26062 |
XWikiContext xcontext = this.xcontextProvider.get(); |
80 |
|
|
81 |
26073 |
if (xcontext != null && xcontext.getWiki() != null) { |
82 |
26071 |
DocumentReference documentReference = getFailsafeDocumentReference(); |
83 |
26075 |
LocalDocumentReference classReference = getFailsafeClassReference(); |
84 |
|
|
85 |
26071 |
if (documentReference != null && classReference != null) { |
86 |
25907 |
XWikiDocument document = xcontext.getWiki().getDocument(getDocumentReference(), xcontext); |
87 |
|
|
88 |
25913 |
return getBaseObject(document, language); |
89 |
|
} |
90 |
|
} |
91 |
|
|
92 |
162 |
return null; |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
95 |
25915 |
protected BaseObject getBaseObject(XWikiDocument document, String language)... |
96 |
|
{ |
97 |
25915 |
if (language != null) { |
98 |
12668 |
BaseObject object = document.getXObject(getClassReference(), "default_language", language, true); |
99 |
|
|
100 |
12666 |
if (object != null) { |
101 |
1174 |
return object; |
102 |
|
} |
103 |
|
} else { |
104 |
13246 |
return document.getXObject(getClassReference()); |
105 |
|
} |
106 |
|
|
107 |
11495 |
return null; |
108 |
|
} |
109 |
|
|
|
|
| 82.4% |
Uncovered Elements: 3 (17) |
Complexity: 6 |
Complexity Density: 0.55 |
|
110 |
3 |
@Override... |
111 |
|
protected BaseObject getBaseObject() throws XWikiException |
112 |
|
{ |
113 |
3 |
XWikiContext xcontext = this.xcontextProvider.get(); |
114 |
|
|
115 |
3 |
if (xcontext != null && xcontext.getWiki() != null) { |
116 |
3 |
DocumentReference documentReference = getFailsafeDocumentReference(); |
117 |
3 |
LocalDocumentReference classReference = getFailsafeClassReference(); |
118 |
|
|
119 |
3 |
if (documentReference != null && classReference != null) { |
120 |
3 |
XWikiDocument document = xcontext.getWiki().getDocument(getDocumentReference(), xcontext); |
121 |
|
|
122 |
|
|
123 |
3 |
BaseObject object = getBaseObject(document, xcontext.getLanguage()); |
124 |
|
|
125 |
3 |
if (object != null) { |
126 |
2 |
return object; |
127 |
|
} |
128 |
|
|
129 |
1 |
return document.getXObject(classReference); |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
0 |
return null; |
134 |
|
} |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.8 |
|
136 |
26064 |
protected Object getBaseProperty(String propertyName, String language, boolean text) throws XWikiException... |
137 |
|
{ |
138 |
|
|
139 |
26063 |
BaseObject baseObject = getBaseObject(language); |
140 |
|
|
141 |
26072 |
if (baseObject != null) { |
142 |
2437 |
BaseProperty property = (BaseProperty) baseObject.getField(propertyName); |
143 |
|
|
144 |
403 |
return property != null ? (text ? property.toText() : property.getValue()) : null; |
145 |
|
} |
146 |
|
|
147 |
23634 |
return null; |
148 |
|
} |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
150 |
13051 |
@Override... |
151 |
|
protected Object getBaseProperty(String propertyName, boolean text) throws XWikiException |
152 |
|
{ |
153 |
13047 |
XWikiContext xcontext = this.xcontextProvider.get(); |
154 |
|
|
155 |
|
|
156 |
13054 |
Object propertyValue = getBaseProperty(propertyName, xcontext.getLanguage(), text); |
157 |
|
|
158 |
|
|
159 |
13050 |
if (propertyValue == null || isEmpty(propertyValue)) { |
160 |
13013 |
propertyValue = getBaseProperty(propertyName, null, text); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
13054 |
if (isEmpty(propertyValue)) { |
166 |
13019 |
propertyValue = null; |
167 |
|
} |
168 |
|
|
169 |
13054 |
return propertyValue; |
170 |
|
} |
171 |
|
} |