1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.stats.impl; |
21 |
|
|
22 |
|
import java.util.Date; |
23 |
|
import java.util.Iterator; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.apache.commons.lang3.StringUtils; |
27 |
|
import org.dom4j.Element; |
28 |
|
import org.dom4j.dom.DOMElement; |
29 |
|
import org.xwiki.model.EntityType; |
30 |
|
import org.xwiki.model.reference.EntityReference; |
31 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
32 |
|
|
33 |
|
import com.xpn.xwiki.XWikiException; |
34 |
|
import com.xpn.xwiki.objects.BaseCollection; |
35 |
|
import com.xpn.xwiki.objects.BaseProperty; |
36 |
|
import com.xpn.xwiki.objects.PropertyInterface; |
37 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
38 |
|
import com.xpn.xwiki.objects.classes.PropertyClass; |
39 |
|
import com.xpn.xwiki.stats.impl.StatsUtil.PeriodType; |
40 |
|
import com.xpn.xwiki.web.Utils; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
|
|
|
| 1% |
Uncovered Elements: 96 (97) |
Complexity: 24 |
Complexity Density: 0.39 |
|
47 |
|
public class XWikiStats extends BaseCollection |
48 |
|
{ |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@version |
53 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
54 |
|
public enum Property |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
period, |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
pageViews |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
private static final String XMLNODE_OBJECT = "object"; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
private static final String XMLNODE_NAME = "name"; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
private static final String XMLNODE_NUMBER = "number"; |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
private static final String XMLNODE_CLASSNAME = "className"; |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
private static final String XMLNODE_PROPERTY = "property"; |
91 |
|
|
92 |
|
|
93 |
|
private final EntityReferenceResolver<String> resolver = Utils.getComponent(EntityReferenceResolver.TYPE_STRING); |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
98 |
87 |
public XWikiStats()... |
99 |
|
{ |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
@param |
104 |
|
@param |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
0 |
public XWikiStats(Date periodDate, PeriodType periodtype)... |
107 |
|
{ |
108 |
0 |
setPeriod(StatsUtil.getPeriodAsInt(periodDate, periodtype)); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
@return |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
0 |
public int getPeriod()... |
115 |
|
{ |
116 |
0 |
return getIntValue(Property.period.toString()); |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
@param |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
0 |
public void setPeriod(int period)... |
123 |
|
{ |
124 |
0 |
setIntValue(Property.period.toString(), period); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
@return |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0 |
public int getPageViews()... |
131 |
|
{ |
132 |
0 |
return getIntValue(Property.pageViews.toString()); |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
@param |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
0 |
public void setPageViews(int pageViews)... |
139 |
|
{ |
140 |
0 |
setIntValue(Property.pageViews.toString(), pageViews); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
0 |
public void incPageViews()... |
147 |
|
{ |
148 |
0 |
setIntValue(Property.pageViews.toString(), getPageViews() + 1); |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
151 |
0 |
@Override... |
152 |
|
protected String getLocalKey() |
153 |
|
{ |
154 |
0 |
StringBuilder sb = new StringBuilder(64); |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
0 |
String name = getName(); |
159 |
0 |
int nb = getNumber(); |
160 |
|
|
161 |
0 |
if (!StringUtils.isEmpty(name)) { |
162 |
|
|
163 |
0 |
EntityReference ref = this.resolver.resolve(name, EntityType.DOCUMENT); |
164 |
0 |
if (ref.getName().equals(name)) { |
165 |
0 |
ref = new EntityReference(name, EntityType.SPACE); |
166 |
|
} |
167 |
0 |
sb.append(getLocalUidStringEntityReferenceSerializer().serialize(ref)); |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
0 |
if (nb != 0) { |
173 |
|
|
174 |
0 |
String str = Integer.toString(nb); |
175 |
0 |
sb.append(str.length()).append(':').append(str); |
176 |
|
} |
177 |
|
|
178 |
0 |
return sb.toString(); |
179 |
|
} |
180 |
|
|
181 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
0 |
@Override... |
183 |
|
public int hashCode() |
184 |
|
{ |
185 |
0 |
return super.hashCode(); |
186 |
|
} |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
188 |
0 |
@Override... |
189 |
|
public boolean equals(Object obj) |
190 |
|
{ |
191 |
|
|
192 |
0 |
if (this == obj) { |
193 |
0 |
return true; |
194 |
|
} |
195 |
|
|
196 |
0 |
if (!super.equals(obj)) { |
197 |
0 |
return false; |
198 |
|
} |
199 |
|
|
200 |
0 |
if (getNumber() != ((BaseCollection) obj).getNumber()) { |
201 |
0 |
return false; |
202 |
|
} |
203 |
|
|
204 |
0 |
return true; |
205 |
|
} |
206 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 4 |
Complexity Density: 0.21 |
|
207 |
0 |
@Override... |
208 |
|
|
209 |
|
public Element toXML(BaseClass bclass) |
210 |
|
{ |
211 |
0 |
Element oel = new DOMElement(XMLNODE_OBJECT); |
212 |
|
|
213 |
|
|
214 |
0 |
if (bclass != null) { |
215 |
0 |
if (bclass.getFieldList().size() > 0) { |
216 |
0 |
oel.add(bclass.toXML()); |
217 |
|
} |
218 |
|
} |
219 |
|
|
220 |
0 |
Element el = new DOMElement(XMLNODE_NAME); |
221 |
0 |
el.addText(getName()); |
222 |
0 |
oel.add(el); |
223 |
|
|
224 |
0 |
el = new DOMElement(XMLNODE_NUMBER); |
225 |
0 |
el.addText(getNumber() + ""); |
226 |
0 |
oel.add(el); |
227 |
|
|
228 |
0 |
el = new DOMElement(XMLNODE_CLASSNAME); |
229 |
0 |
el.addText(getClassName()); |
230 |
0 |
oel.add(el); |
231 |
|
|
232 |
0 |
for (Iterator<?> it = getFieldList().iterator(); it.hasNext();) { |
233 |
0 |
Element pel = new DOMElement(XMLNODE_PROPERTY); |
234 |
0 |
PropertyInterface bprop = (PropertyInterface) it.next(); |
235 |
0 |
pel.add(bprop.toXML()); |
236 |
0 |
oel.add(pel); |
237 |
|
} |
238 |
|
|
239 |
0 |
return oel; |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
@param |
246 |
|
@throws |
247 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
248 |
0 |
public void fromXML(Element oel) throws XWikiException... |
249 |
|
{ |
250 |
0 |
Element cel = oel.element("class"); |
251 |
0 |
BaseClass bclass = new BaseClass(); |
252 |
0 |
if (cel != null) { |
253 |
0 |
bclass.fromXML(cel); |
254 |
0 |
setClassName(bclass.getName()); |
255 |
|
} |
256 |
|
|
257 |
0 |
setName(oel.element(XMLNODE_NAME).getText()); |
258 |
0 |
List<?> list = oel.elements(XMLNODE_PROPERTY); |
259 |
0 |
for (int i = 0; i < list.size(); i++) { |
260 |
0 |
Element pcel = (Element) ((Element) list.get(i)).elements().get(0); |
261 |
0 |
String name = pcel.getName(); |
262 |
0 |
PropertyClass pclass = (PropertyClass) bclass.get(name); |
263 |
0 |
if (pclass != null) { |
264 |
0 |
BaseProperty property = pclass.newPropertyfromXML(pcel); |
265 |
0 |
property.setName(name); |
266 |
0 |
property.setObject(this); |
267 |
0 |
safeput(name, property); |
268 |
|
} |
269 |
|
} |
270 |
|
} |
271 |
|
} |