1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.feed; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
import java.io.ByteArrayOutputStream; |
24 |
|
import java.io.PrintWriter; |
25 |
|
import java.nio.charset.Charset; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.Collections; |
28 |
|
import java.util.Date; |
29 |
|
import java.util.HashMap; |
30 |
|
import java.util.List; |
31 |
|
import java.util.Map; |
32 |
|
import java.util.Properties; |
33 |
|
|
34 |
|
import org.apache.commons.io.output.NullWriter; |
35 |
|
import org.slf4j.Logger; |
36 |
|
import org.slf4j.LoggerFactory; |
37 |
|
import org.w3c.dom.Node; |
38 |
|
import org.w3c.tidy.Tidy; |
39 |
|
import org.xwiki.xml.XMLUtils; |
40 |
|
|
41 |
|
import com.sun.syndication.feed.synd.SyndCategory; |
42 |
|
import com.sun.syndication.feed.synd.SyndCategoryImpl; |
43 |
|
import com.sun.syndication.feed.synd.SyndContent; |
44 |
|
import com.sun.syndication.feed.synd.SyndContentImpl; |
45 |
|
import com.sun.syndication.feed.synd.SyndEntry; |
46 |
|
import com.xpn.xwiki.XWiki; |
47 |
|
import com.xpn.xwiki.XWikiContext; |
48 |
|
import com.xpn.xwiki.XWikiException; |
49 |
|
import com.xpn.xwiki.api.Document; |
50 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
51 |
|
import com.xpn.xwiki.util.TidyMessageLogger; |
52 |
|
|
53 |
|
|
54 |
|
@link |
55 |
|
|
|
|
| 61.3% |
Uncovered Elements: 137 (354) |
Complexity: 90 |
Complexity Density: 0.4 |
|
56 |
|
public class SyndEntryDocumentSource implements SyndEntrySource |
57 |
|
{ |
58 |
|
|
59 |
|
|
60 |
|
|
|
|
| 66.7% |
Uncovered Elements: 8 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
61 |
|
public static class PropertySelector |
62 |
|
{ |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
private String className; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private int objectIndex; |
72 |
|
|
73 |
|
|
74 |
|
@link |
75 |
|
|
76 |
|
private String propertyName; |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@param |
82 |
|
|
83 |
|
|
|
|
| 52.9% |
Uncovered Elements: 8 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
84 |
3 |
public PropertySelector(String strRep)... |
85 |
|
{ |
86 |
3 |
int indexStartPos = strRep.indexOf('_'); |
87 |
3 |
if (indexStartPos < 0) { |
88 |
|
|
89 |
0 |
this.className = null; |
90 |
0 |
this.objectIndex = 0; |
91 |
0 |
this.propertyName = strRep; |
92 |
|
} else { |
93 |
3 |
int propStartPos = strRep.indexOf("_", indexStartPos + 1); |
94 |
3 |
if (propStartPos < 0) { |
95 |
|
|
96 |
3 |
this.className = strRep.substring(0, indexStartPos); |
97 |
3 |
this.objectIndex = 0; |
98 |
3 |
this.propertyName = strRep.substring(indexStartPos + 1); |
99 |
|
} else { |
100 |
|
|
101 |
0 |
this.className = strRep.substring(0, indexStartPos); |
102 |
0 |
this.objectIndex = Integer.parseInt(strRep.substring(indexStartPos + 1, propStartPos)); |
103 |
0 |
this.propertyName = strRep.substring(propStartPos + 1); |
104 |
|
} |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
@return |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
6 |
public String getClassName()... |
112 |
|
{ |
113 |
6 |
return this.className; |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
@return |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
3 |
public int getObjectIndex()... |
120 |
|
{ |
121 |
3 |
return this.objectIndex; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
@return@link |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
3 |
public String getPropertyName()... |
128 |
|
{ |
129 |
3 |
return this.propertyName; |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
|
protected static final Logger LOGGER = LoggerFactory.getLogger(SyndEntryDocumentSource.class); |
134 |
|
|
135 |
|
protected static final TidyMessageLogger TIDY_LOGGER = new TidyMessageLogger(LOGGER); |
136 |
|
|
137 |
|
public static final String CONTENT_TYPE = "ContentType"; |
138 |
|
|
139 |
|
public static final String CONTENT_LENGTH = "ContentLength"; |
140 |
|
|
141 |
|
public static final Properties TIDY_FEED_CONFIG; |
142 |
|
|
143 |
|
public static final Properties TIDY_XML_CONFIG; |
144 |
|
|
145 |
|
public static final Properties TIDY_HTML_CONFIG; |
146 |
|
|
147 |
|
public static final String FIELD_URI = "uri"; |
148 |
|
|
149 |
|
public static final String FIELD_LINK = "link"; |
150 |
|
|
151 |
|
public static final String FIELD_TITLE = "title"; |
152 |
|
|
153 |
|
public static final String FIELD_DESCRIPTION = "description"; |
154 |
|
|
155 |
|
public static final String FIELD_CATEGORIES = "categories"; |
156 |
|
|
157 |
|
public static final String FIELD_PUBLISHED_DATE = "publishedDate"; |
158 |
|
|
159 |
|
public static final String FIELD_UPDATED_DATE = "updatedDate"; |
160 |
|
|
161 |
|
public static final String FIELD_AUTHOR = "author"; |
162 |
|
|
163 |
|
public static final String FIELD_CONTRIBUTORS = "contributors"; |
164 |
|
|
165 |
|
public static final Map<String, Object> DEFAULT_PARAMS; |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
|
167 |
1 |
static {... |
168 |
|
|
169 |
1 |
TIDY_FEED_CONFIG = new Properties(); |
170 |
1 |
TIDY_FEED_CONFIG.setProperty("force-output", "yes"); |
171 |
1 |
TIDY_FEED_CONFIG.setProperty("indent-attributes", "no"); |
172 |
1 |
TIDY_FEED_CONFIG.setProperty("indent", "no"); |
173 |
1 |
TIDY_FEED_CONFIG.setProperty("quiet", "yes"); |
174 |
1 |
TIDY_FEED_CONFIG.setProperty("trim-empty-elements", "yes"); |
175 |
|
|
176 |
|
|
177 |
1 |
TIDY_XML_CONFIG = new Properties(TIDY_FEED_CONFIG); |
178 |
1 |
TIDY_XML_CONFIG.setProperty("input-xml", "yes"); |
179 |
1 |
TIDY_XML_CONFIG.setProperty("output-xml", "yes"); |
180 |
1 |
TIDY_XML_CONFIG.setProperty("add-xml-pi", "no"); |
181 |
1 |
TIDY_XML_CONFIG.setProperty("input-encoding", "UTF8"); |
182 |
|
|
183 |
|
|
184 |
1 |
TIDY_HTML_CONFIG = new Properties(TIDY_FEED_CONFIG); |
185 |
1 |
TIDY_HTML_CONFIG.setProperty("output-xhtml", "yes"); |
186 |
1 |
TIDY_HTML_CONFIG.setProperty("show-body-only", "yes"); |
187 |
1 |
TIDY_HTML_CONFIG.setProperty("drop-empty-paras", "yes"); |
188 |
1 |
TIDY_HTML_CONFIG.setProperty("enclose-text", "yes"); |
189 |
1 |
TIDY_HTML_CONFIG.setProperty("logical-emphasis", "yes"); |
190 |
1 |
TIDY_HTML_CONFIG.setProperty("input-encoding", "UTF8"); |
191 |
|
|
192 |
|
|
193 |
1 |
DEFAULT_PARAMS = new HashMap<String, Object>(); |
194 |
1 |
DEFAULT_PARAMS.put(CONTENT_TYPE, "text/html"); |
195 |
1 |
DEFAULT_PARAMS.put(CONTENT_LENGTH, -1); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
@link |
202 |
|
|
203 |
|
private Map<String, Object> params; |
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
8 |
public SyndEntryDocumentSource()... |
206 |
|
{ |
207 |
8 |
this(new HashMap<String, Object>()); |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
@link |
212 |
|
|
213 |
|
@param |
214 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
215 |
8 |
public SyndEntryDocumentSource(Map<String, Object> params)... |
216 |
|
{ |
217 |
8 |
setParams(params); |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
|
@return |
222 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
223 |
11 |
public Map<String, Object> getParams()... |
224 |
|
{ |
225 |
11 |
return this.params; |
226 |
|
} |
227 |
|
|
228 |
|
|
229 |
|
@link |
230 |
|
|
231 |
|
@param |
232 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
233 |
10 |
public void setParams(Map<String, Object> params)... |
234 |
|
{ |
235 |
10 |
this.params = joinParams(params, getDefaultParams()); |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
241 |
10 |
protected Map<String, Object> getDefaultParams()... |
242 |
|
{ |
243 |
10 |
return DEFAULT_PARAMS; |
244 |
|
} |
245 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
246 |
12 |
@Override... |
247 |
|
public void source(SyndEntry entry, Object obj, Map<String, Object> params, XWikiContext context) |
248 |
|
throws XWikiException |
249 |
|
{ |
250 |
|
|
251 |
12 |
Document doc = castDocument(obj, context); |
252 |
|
|
253 |
|
|
254 |
12 |
if (!doc.hasAccessLevel("view")) { |
255 |
1 |
throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, |
256 |
|
"Access denied in view mode!"); |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
11 |
Map<String, Object> trueParams = joinParams(params, getParams()); |
261 |
|
|
262 |
11 |
sourceDocument(entry, doc, trueParams, context); |
263 |
|
} |
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
@param |
269 |
|
@param |
270 |
|
@param |
271 |
|
@param |
272 |
|
@throws |
273 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
274 |
11 |
public void sourceDocument(SyndEntry entry, Document doc, Map<String, Object> params, XWikiContext context)... |
275 |
|
throws XWikiException |
276 |
|
{ |
277 |
11 |
entry.setUri(getURI(doc, params, context)); |
278 |
11 |
entry.setLink(getLink(doc, params, context)); |
279 |
11 |
entry.setTitle(getTitle(doc, params, context)); |
280 |
11 |
entry.setDescription(getDescription(doc, params, context)); |
281 |
11 |
entry.setCategories(getCategories(doc, params, context)); |
282 |
11 |
entry.setPublishedDate(getPublishedDate(doc, params, context)); |
283 |
11 |
entry.setUpdatedDate(getUpdateDate(doc, params, context)); |
284 |
11 |
entry.setAuthor(getAuthor(doc, params, context)); |
285 |
11 |
entry.setContributors(getContributors(doc, params, context)); |
286 |
|
} |
287 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
288 |
22 |
protected String getDefaultURI(Document doc, Map<String, Object> params, XWikiContext context)... |
289 |
|
throws XWikiException |
290 |
|
{ |
291 |
22 |
return doc.getExternalURL("view", "language=" + doc.getRealLanguage()); |
292 |
|
} |
293 |
|
|
|
|
| 40% |
Uncovered Elements: 6 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
294 |
11 |
protected String getURI(Document doc, Map<String, Object> params, XWikiContext context) throws XWikiException... |
295 |
|
{ |
296 |
11 |
String mapping = (String) params.get(FIELD_URI); |
297 |
11 |
if (mapping == null) { |
298 |
11 |
return getDefaultURI(doc, params, context); |
299 |
0 |
} else if (isVelocityCode(mapping)) { |
300 |
0 |
return parseString(mapping, doc, context); |
301 |
|
} else { |
302 |
0 |
return getStringValue(mapping, doc, context); |
303 |
|
} |
304 |
|
} |
305 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
306 |
11 |
protected String getDefaultLink(Document doc, Map<String, Object> params, XWikiContext context)... |
307 |
|
throws XWikiException |
308 |
|
{ |
309 |
11 |
return getDefaultURI(doc, params, context); |
310 |
|
} |
311 |
|
|
|
|
| 40% |
Uncovered Elements: 6 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
312 |
11 |
protected String getLink(Document doc, Map<String, Object> params, XWikiContext context) throws XWikiException... |
313 |
|
{ |
314 |
11 |
String mapping = (String) params.get(FIELD_LINK); |
315 |
11 |
if (mapping == null) { |
316 |
11 |
return getDefaultLink(doc, params, context); |
317 |
0 |
} else if (isVelocityCode(mapping)) { |
318 |
0 |
return parseString(mapping, doc, context); |
319 |
|
} else { |
320 |
0 |
return getStringValue(mapping, doc, context); |
321 |
|
} |
322 |
|
} |
323 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
324 |
11 |
protected String getDefaultTitle(Document doc, Map<String, Object> params, XWikiContext context)... |
325 |
|
{ |
326 |
11 |
return doc.getDisplayTitle(); |
327 |
|
} |
328 |
|
|
|
|
| 40% |
Uncovered Elements: 6 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
329 |
11 |
protected String getTitle(Document doc, Map<String, Object> params, XWikiContext context) throws XWikiException... |
330 |
|
{ |
331 |
11 |
String mapping = (String) params.get(FIELD_TITLE); |
332 |
11 |
if (mapping == null) { |
333 |
11 |
return getDefaultTitle(doc, params, context); |
334 |
0 |
} else if (isVelocityCode(mapping)) { |
335 |
0 |
return parseString(mapping, doc, context); |
336 |
|
} else { |
337 |
0 |
return getStringValue(mapping, doc, context); |
338 |
|
} |
339 |
|
} |
340 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
341 |
8 |
protected String getDefaultDescription(Document doc, Map<String, Object> params, XWikiContext context)... |
342 |
|
{ |
343 |
8 |
XWiki xwiki = context.getWiki(); |
344 |
8 |
String author = xwiki.getUserName(doc.getAuthor(), null, false, context); |
345 |
|
|
346 |
8 |
String descFormat = "Version %1$s edited by %2$s on %3$s"; |
347 |
8 |
return String.format(descFormat, new Object[] {doc.getVersion(), author, doc.getDate()}); |
348 |
|
} |
349 |
|
|
|
|
| 89.7% |
Uncovered Elements: 3 (29) |
Complexity: 7 |
Complexity Density: 0.41 |
|
350 |
11 |
protected SyndContent getDescription(Document doc, Map<String, Object> params, XWikiContext context)... |
351 |
|
throws XWikiException |
352 |
|
{ |
353 |
11 |
String description; |
354 |
11 |
String mapping = (String) params.get(FIELD_DESCRIPTION); |
355 |
11 |
if (mapping == null) { |
356 |
8 |
description = getDefaultDescription(doc, params, context); |
357 |
3 |
} else if (isVelocityCode(mapping)) { |
358 |
0 |
description = parseString(mapping, doc, context); |
359 |
|
} else { |
360 |
3 |
description = doc.getRenderedContent(getStringValue(mapping, doc, context), doc.getSyntaxId()); |
361 |
|
} |
362 |
11 |
String contentType = (String) params.get(CONTENT_TYPE); |
363 |
11 |
int contentLength = ((Number) params.get(CONTENT_LENGTH)).intValue(); |
364 |
11 |
if (contentLength >= 0) { |
365 |
3 |
if ("text/plain".equals(contentType)) { |
366 |
1 |
description = getPlainPreview(description, contentLength); |
367 |
2 |
} else if ("text/html".equals(contentType)) { |
368 |
1 |
description = getHTMLPreview(description, contentLength); |
369 |
1 |
} else if ("text/xml".equals(contentType)) { |
370 |
1 |
description = getXMLPreview(description, contentLength); |
371 |
|
} |
372 |
|
} |
373 |
11 |
return getSyndContent(contentType, description); |
374 |
|
} |
375 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
376 |
11 |
protected List<SyndCategory> getDefaultCategories(Document doc, Map<String, Object> params, XWikiContext context)... |
377 |
|
{ |
378 |
11 |
return Collections.emptyList(); |
379 |
|
} |
380 |
|
|
|
|
| 16.7% |
Uncovered Elements: 20 (24) |
Complexity: 5 |
Complexity Density: 0.31 |
|
381 |
11 |
protected List<SyndCategory> getCategories(Document doc, Map<String, Object> params, XWikiContext context)... |
382 |
|
throws XWikiException |
383 |
|
{ |
384 |
11 |
String mapping = (String) params.get(FIELD_CATEGORIES); |
385 |
11 |
if (mapping == null) { |
386 |
11 |
return getDefaultCategories(doc, params, context); |
387 |
|
} |
388 |
|
|
389 |
0 |
List<Object> categories; |
390 |
0 |
if (isVelocityCode(mapping)) { |
391 |
0 |
categories = parseList(mapping, doc, context); |
392 |
|
} else { |
393 |
0 |
categories = getListValue(mapping, doc, context); |
394 |
|
} |
395 |
|
|
396 |
0 |
List<SyndCategory> result = new ArrayList<SyndCategory>(); |
397 |
0 |
for (Object category : categories) { |
398 |
0 |
if (category instanceof SyndCategory) { |
399 |
0 |
result.add((SyndCategory) category); |
400 |
0 |
} else if (category != null) { |
401 |
0 |
SyndCategory scat = new SyndCategoryImpl(); |
402 |
0 |
scat.setName(category.toString()); |
403 |
0 |
result.add(scat); |
404 |
|
} |
405 |
|
} |
406 |
0 |
return result; |
407 |
|
} |
408 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
409 |
11 |
protected Date getDefaultPublishedDate(Document doc, Map<String, Object> params, XWikiContext context)... |
410 |
|
{ |
411 |
11 |
return doc.getDate(); |
412 |
|
} |
413 |
|
|
|
|
| 40% |
Uncovered Elements: 6 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
414 |
11 |
protected Date getPublishedDate(Document doc, Map<String, Object> params, XWikiContext context)... |
415 |
|
throws XWikiException |
416 |
|
{ |
417 |
11 |
String mapping = (String) params.get(FIELD_PUBLISHED_DATE); |
418 |
11 |
if (mapping == null) { |
419 |
11 |
return getDefaultPublishedDate(doc, params, context); |
420 |
0 |
} else if (isVelocityCode(mapping)) { |
421 |
0 |
return parseDate(mapping, doc, context); |
422 |
|
} else { |
423 |
0 |
return getDateValue(mapping, doc, context); |
424 |
|
} |
425 |
|
} |
426 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
427 |
11 |
protected Date getDefaultUpdateDate(Document doc, Map<String, Object> params, XWikiContext context)... |
428 |
|
{ |
429 |
11 |
return doc.getDate(); |
430 |
|
} |
431 |
|
|
|
|
| 40% |
Uncovered Elements: 6 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
432 |
11 |
protected Date getUpdateDate(Document doc, Map<String, Object> params, XWikiContext context) throws XWikiException... |
433 |
|
{ |
434 |
11 |
String mapping = (String) params.get(FIELD_UPDATED_DATE); |
435 |
11 |
if (mapping == null) { |
436 |
11 |
return getDefaultUpdateDate(doc, params, context); |
437 |
0 |
} else if (isVelocityCode(mapping)) { |
438 |
0 |
return parseDate(mapping, doc, context); |
439 |
|
} else { |
440 |
0 |
return getDateValue(mapping, doc, context); |
441 |
|
} |
442 |
|
} |
443 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
444 |
11 |
protected String getDefaultAuthor(Document doc, Map<String, Object> params, XWikiContext context)... |
445 |
|
{ |
446 |
11 |
return context.getWiki().getUserName(doc.getCreator(), null, false, context); |
447 |
|
} |
448 |
|
|
|
|
| 40% |
Uncovered Elements: 6 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
449 |
11 |
protected String getAuthor(Document doc, Map<String, Object> params, XWikiContext context) throws XWikiException... |
450 |
|
{ |
451 |
11 |
String mapping = (String) params.get(FIELD_AUTHOR); |
452 |
11 |
if (mapping == null) { |
453 |
11 |
return getDefaultAuthor(doc, params, context); |
454 |
0 |
} else if (isVelocityCode(mapping)) { |
455 |
0 |
return parseString(mapping, doc, context); |
456 |
|
} else { |
457 |
0 |
return getStringValue(mapping, doc, context); |
458 |
|
} |
459 |
|
} |
460 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
461 |
11 |
protected List<String> getDefaultContributors(Document doc, Map<String, Object> params, XWikiContext context)... |
462 |
|
{ |
463 |
11 |
XWiki xwiki = context.getWiki(); |
464 |
11 |
List<String> contributors = new ArrayList<String>(); |
465 |
11 |
contributors.add(xwiki.getUserName(doc.getAuthor(), null, false, context)); |
466 |
11 |
return contributors; |
467 |
|
} |
468 |
|
|
|
|
| 21.1% |
Uncovered Elements: 15 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
469 |
11 |
protected List<String> getContributors(Document doc, Map<String, Object> params, XWikiContext context)... |
470 |
|
throws XWikiException |
471 |
|
{ |
472 |
11 |
String mapping = (String) params.get(FIELD_CONTRIBUTORS); |
473 |
11 |
if (mapping == null) { |
474 |
11 |
return getDefaultContributors(doc, params, context); |
475 |
|
} |
476 |
|
|
477 |
0 |
List<Object> rawContributors; |
478 |
0 |
if (isVelocityCode(mapping)) { |
479 |
0 |
rawContributors = parseList(mapping, doc, context); |
480 |
|
} else { |
481 |
0 |
rawContributors = getListValue(mapping, doc, context); |
482 |
|
} |
483 |
|
|
484 |
0 |
List<String> contributors = new ArrayList<String>(); |
485 |
0 |
for (Object rawContributor : rawContributors) { |
486 |
0 |
if (rawContributor instanceof String) { |
487 |
0 |
contributors.add((String) rawContributor); |
488 |
|
} else { |
489 |
0 |
contributors.add(rawContributor.toString()); |
490 |
|
} |
491 |
|
} |
492 |
|
|
493 |
0 |
return contributors; |
494 |
|
} |
495 |
|
|
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
@param |
500 |
|
@return |
501 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
502 |
3 |
protected boolean isVelocityCode(String mapping)... |
503 |
|
{ |
504 |
3 |
return mapping.charAt(0) == '{' && mapping.charAt(mapping.length() - 1) == '}'; |
505 |
|
} |
506 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
507 |
0 |
protected String parseString(String mapping, Document doc, XWikiContext context) throws XWikiException... |
508 |
|
{ |
509 |
0 |
if (isVelocityCode(mapping)) { |
510 |
0 |
return doc.getRenderedContent(mapping.substring(1, mapping.length() - 1), doc.getSyntax().toIdString()); |
511 |
|
} else { |
512 |
0 |
return mapping; |
513 |
|
} |
514 |
|
} |
515 |
|
|
516 |
|
|
517 |
|
@link |
518 |
|
|
519 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
520 |
0 |
protected Date parseDate(String mapping, Document doc, XWikiContext context) throws NumberFormatException,... |
521 |
|
XWikiException |
522 |
|
{ |
523 |
0 |
if (isVelocityCode(mapping)) { |
524 |
0 |
return new Date(Long.parseLong(parseString(mapping, doc, context).trim())); |
525 |
|
} else { |
526 |
0 |
return null; |
527 |
|
} |
528 |
|
} |
529 |
|
|
530 |
|
|
531 |
|
@link |
532 |
|
|
533 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 6 |
Complexity Density: 0.5 |
|
534 |
0 |
protected List<Object> parseList(String mapping, Document doc, XWikiContext context) throws XWikiException... |
535 |
|
{ |
536 |
0 |
if (!isVelocityCode(mapping)) { |
537 |
0 |
return null; |
538 |
|
} |
539 |
0 |
String strRep = parseString(mapping, doc, context).trim(); |
540 |
0 |
if (strRep.charAt(0) != '[' || strRep.charAt(strRep.length() - 1) != ']') { |
541 |
0 |
return null; |
542 |
|
} |
543 |
0 |
String[] array = strRep.substring(1, strRep.length() - 1).split(","); |
544 |
0 |
if (array.length > 0) { |
545 |
0 |
List<Object> list = new ArrayList<Object>(); |
546 |
0 |
for (int i = 0; i < array.length; i++) { |
547 |
0 |
list.add(array[i]); |
548 |
|
} |
549 |
0 |
return list; |
550 |
|
} else { |
551 |
0 |
return Collections.emptyList(); |
552 |
|
} |
553 |
|
} |
554 |
|
|
555 |
|
|
556 |
|
|
557 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
558 |
3 |
protected String getStringValue(String mapping, Document doc, XWikiContext context) throws XWikiException... |
559 |
|
{ |
560 |
3 |
PropertySelector ps = new PropertySelector(mapping); |
561 |
3 |
if (ps.getClassName() == null) { |
562 |
0 |
return doc.display(ps.getPropertyName()); |
563 |
|
} else { |
564 |
3 |
XWikiDocument xdoc = context.getWiki().getDocument(doc.getFullName(), context); |
565 |
3 |
return xdoc.getObject(ps.getClassName(), ps.getObjectIndex()).getStringValue(ps.getPropertyName()); |
566 |
|
} |
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
|
|
571 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
572 |
0 |
protected Date getDateValue(String mapping, Document doc, XWikiContext context) throws XWikiException... |
573 |
|
{ |
574 |
0 |
XWikiDocument xdoc = context.getWiki().getDocument(doc.getFullName(), context); |
575 |
0 |
PropertySelector ps = new PropertySelector(mapping); |
576 |
0 |
if (ps.getClassName() == null) { |
577 |
0 |
return xdoc.getFirstObject(ps.getPropertyName(), context).getDateValue(ps.getPropertyName()); |
578 |
|
} else { |
579 |
0 |
return xdoc.getObject(ps.getClassName(), ps.getObjectIndex()).getDateValue(ps.getPropertyName()); |
580 |
|
} |
581 |
|
} |
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
586 |
0 |
protected List<Object> getListValue(String mapping, Document doc, XWikiContext context) throws XWikiException... |
587 |
|
{ |
588 |
0 |
XWikiDocument xdoc = context.getWiki().getDocument(doc.getFullName(), context); |
589 |
0 |
PropertySelector ps = new PropertySelector(mapping); |
590 |
0 |
if (ps.getClassName() == null) { |
591 |
0 |
return xdoc.getFirstObject(ps.getPropertyName(), context).getListValue(ps.getPropertyName()); |
592 |
|
} else { |
593 |
0 |
return xdoc.getObject(ps.getClassName(), ps.getObjectIndex()).getListValue(ps.getPropertyName()); |
594 |
|
} |
595 |
|
} |
596 |
|
|
597 |
|
|
598 |
|
@return |
599 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
600 |
21 |
protected Map<String, Object> joinParams(Map<String, Object> base, Map<String, Object> extra)... |
601 |
|
{ |
602 |
21 |
Map<String, Object> params = new HashMap<String, Object>(); |
603 |
21 |
params.putAll(base); |
604 |
|
|
605 |
21 |
for (Map.Entry<String, Object> entry : extra.entrySet()) { |
606 |
43 |
if (params.get(entry.getKey()) == null) { |
607 |
35 |
params.put(entry.getKey(), entry.getValue()); |
608 |
|
} |
609 |
|
} |
610 |
21 |
return params; |
611 |
|
} |
612 |
|
|
613 |
|
|
614 |
|
|
615 |
|
|
616 |
|
@param |
617 |
|
@param |
618 |
|
@return |
619 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
620 |
8 |
public static org.w3c.dom.Document tidy(String xmlFragment, Properties config)... |
621 |
|
{ |
622 |
8 |
Tidy tidy = new Tidy(); |
623 |
8 |
tidy.setConfigurationFromProps(config); |
624 |
|
|
625 |
|
|
626 |
8 |
tidy.setMessageListener(TIDY_LOGGER); |
627 |
8 |
tidy.setErrout(new PrintWriter(new NullWriter())); |
628 |
|
|
629 |
|
|
630 |
8 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
631 |
8 |
ByteArrayInputStream in = new ByteArrayInputStream(xmlFragment.getBytes(Charset.forName(config.getProperty("input-encoding")))); |
632 |
8 |
return tidy.parseDOM(in, out); |
633 |
|
} |
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
|
638 |
|
@param |
639 |
|
@return |
640 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 5 |
Complexity Density: 0.36 |
|
641 |
47 |
public static int innerTextLength(Node node)... |
642 |
|
{ |
643 |
47 |
switch (node.getNodeType()) { |
644 |
10 |
case Node.TEXT_NODE: |
645 |
10 |
return node.getNodeValue().length(); |
646 |
33 |
case Node.ELEMENT_NODE: |
647 |
33 |
int length = 0; |
648 |
33 |
Node child = node.getFirstChild(); |
649 |
72 |
while (child != null) { |
650 |
39 |
length += innerTextLength(child); |
651 |
39 |
child = child.getNextSibling(); |
652 |
|
} |
653 |
33 |
return length; |
654 |
4 |
case Node.DOCUMENT_NODE: |
655 |
4 |
return innerTextLength(((org.w3c.dom.Document) node).getDocumentElement()); |
656 |
0 |
default: |
657 |
0 |
return 0; |
658 |
|
} |
659 |
|
} |
660 |
|
|
661 |
|
|
662 |
|
|
663 |
|
|
664 |
|
|
665 |
|
|
666 |
|
@param |
667 |
|
@param |
668 |
|
@return |
669 |
|
|
670 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
671 |
2 |
public static String getXMLPreview(String xmlFragment, int previewLength)... |
672 |
|
{ |
673 |
2 |
try { |
674 |
2 |
return XMLUtils.extractXML(tidy(xmlFragment, TIDY_XML_CONFIG), 0, previewLength); |
675 |
|
} catch (RuntimeException e) { |
676 |
0 |
return getPlainPreview(xmlFragment, previewLength); |
677 |
|
} |
678 |
|
} |
679 |
|
|
680 |
|
|
681 |
|
|
682 |
|
|
683 |
|
|
684 |
|
|
685 |
|
@param |
686 |
|
@param |
687 |
|
|
688 |
|
@return |
689 |
|
|
690 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
691 |
2 |
public static String getHTMLPreview(String htmlFragment, int previewLength)... |
692 |
|
{ |
693 |
2 |
try { |
694 |
2 |
org.w3c.dom.Document html = tidy(htmlFragment, TIDY_HTML_CONFIG); |
695 |
2 |
Node body = html.getElementsByTagName("body").item(0); |
696 |
2 |
return XMLUtils.extractXML(body.getFirstChild(), 0, previewLength); |
697 |
|
} catch (RuntimeException e) { |
698 |
0 |
return getPlainPreview(htmlFragment, previewLength); |
699 |
|
} |
700 |
|
} |
701 |
|
|
702 |
|
|
703 |
|
|
704 |
|
|
705 |
|
@param |
706 |
|
@param |
707 |
|
@return |
708 |
|
|
|
|
| 62.5% |
Uncovered Elements: 6 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
709 |
2 |
public static String getPlainPreview(String plainText, int previewLength)... |
710 |
|
{ |
711 |
2 |
if (plainText.length() <= previewLength) { |
712 |
0 |
return plainText; |
713 |
|
} |
714 |
|
|
715 |
|
|
716 |
2 |
plainText = plainText.trim(); |
717 |
2 |
if (plainText.length() <= previewLength) { |
718 |
0 |
return plainText; |
719 |
|
} |
720 |
2 |
int spaceIndex = plainText.lastIndexOf(" ", previewLength); |
721 |
2 |
if (spaceIndex < 0) { |
722 |
0 |
spaceIndex = previewLength; |
723 |
|
} |
724 |
2 |
plainText = plainText.substring(0, spaceIndex); |
725 |
2 |
return plainText; |
726 |
|
} |
727 |
|
|
728 |
|
|
729 |
|
@link |
730 |
|
|
731 |
|
@param |
732 |
|
@param |
733 |
|
@return@link |
734 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
735 |
11 |
protected SyndContent getSyndContent(String type, String value)... |
736 |
|
{ |
737 |
11 |
SyndContent content = new SyndContentImpl(); |
738 |
11 |
content.setType(type); |
739 |
11 |
content.setValue(value); |
740 |
11 |
return content; |
741 |
|
} |
742 |
|
|
743 |
|
|
744 |
|
@link@link |
745 |
|
@link |
746 |
|
|
747 |
|
@param |
748 |
|
@param |
749 |
|
@return |
750 |
|
@throws@link@link |
751 |
|
|
752 |
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
753 |
12 |
protected Document castDocument(Object obj, XWikiContext context) throws XWikiException... |
754 |
|
{ |
755 |
12 |
if (obj instanceof Document) { |
756 |
1 |
return (Document) obj; |
757 |
11 |
} else if (obj instanceof XWikiDocument) { |
758 |
10 |
return ((XWikiDocument) obj).newDocument(context); |
759 |
1 |
} else if (obj instanceof String) { |
760 |
1 |
return context.getWiki().getDocument((String) obj, context).newDocument(context); |
761 |
|
} else { |
762 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_DOES_NOT_EXIST, ""); |
763 |
|
} |
764 |
|
} |
765 |
|
} |