1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.internal.resources.pages; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
import java.util.regex.Pattern; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
|
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.query.Query; |
29 |
|
import org.xwiki.query.QueryFilter; |
30 |
|
import org.xwiki.rest.XWikiResource; |
31 |
|
import org.xwiki.rest.XWikiRestException; |
32 |
|
import org.xwiki.rest.internal.DomainObjectFactory; |
33 |
|
import org.xwiki.rest.internal.Utils; |
34 |
|
import org.xwiki.rest.model.jaxb.Pages; |
35 |
|
import org.xwiki.rest.resources.pages.PagesResource; |
36 |
|
|
37 |
|
import com.xpn.xwiki.api.Document; |
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
|
42 |
|
@Component |
43 |
|
@Named("org.xwiki.rest.internal.resources.pages.PagesResourceImpl") |
|
|
| 60.4% |
Uncovered Elements: 19 (48) |
Complexity: 11 |
Complexity Density: 0.35 |
|
44 |
|
public class PagesResourceImpl extends XWikiResource implements PagesResource |
45 |
|
{ |
|
|
| 59.6% |
Uncovered Elements: 19 (47) |
Complexity: 11 |
Complexity Density: 0.35 |
|
46 |
17 |
@Override... |
47 |
|
public Pages getPages(String wikiName, String spaceName, Integer start, Integer number, |
48 |
|
String parentFilterExpression, String order, Boolean withPrettyNames) |
49 |
|
throws XWikiRestException |
50 |
|
{ |
51 |
17 |
String database = Utils.getXWikiContext(componentManager).getWikiId(); |
52 |
17 |
List<String> spaces = parseSpaceSegments(spaceName); |
53 |
17 |
String spaceId = Utils.getLocalSpaceId(spaces); |
54 |
|
|
55 |
17 |
Pages pages = objectFactory.createPages(); |
56 |
|
|
57 |
17 |
try { |
58 |
17 |
Utils.getXWikiContext(componentManager).setWikiId(wikiName); |
59 |
|
|
60 |
17 |
Query query = ("date".equals(order)) ? queryManager.createQuery( |
61 |
|
"select doc.name from Document doc where doc.space=:space and language='' order by doc.date desc", |
62 |
|
"xwql") : queryManager.getNamedQuery("getSpaceDocsName"); |
63 |
|
|
64 |
|
|
65 |
17 |
List<String> pageNames = |
66 |
|
query.addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "hidden")) |
67 |
|
.bindValue("space", spaceId).setOffset(start).setLimit(number).execute(); |
68 |
|
|
69 |
17 |
Pattern parentFilter = null; |
70 |
17 |
if (parentFilterExpression != null) { |
71 |
0 |
if (parentFilterExpression.equals("null")) { |
72 |
0 |
parentFilter = Pattern.compile(""); |
73 |
|
} else { |
74 |
0 |
parentFilter = Pattern.compile(parentFilterExpression); |
75 |
|
} |
76 |
|
} |
77 |
|
|
78 |
17 |
for (String pageName : pageNames) { |
79 |
134 |
String pageFullName = Utils.getPageId(wikiName, spaces, pageName); |
80 |
|
|
81 |
134 |
if (!Utils.getXWikiApi(componentManager).exists(pageFullName)) { |
82 |
0 |
logger.warning(String |
83 |
|
.format("[Page '%s' appears to be in space '%s' but no information is available.]", |
84 |
|
pageName, |
85 |
|
spaceId)); |
86 |
|
} else { |
87 |
134 |
Document doc = Utils.getXWikiApi(componentManager).getDocument(pageFullName); |
88 |
|
|
89 |
|
|
90 |
134 |
if (doc != null) { |
91 |
134 |
boolean add = true; |
92 |
|
|
93 |
134 |
Document parent = Utils.getParentDocument(doc, Utils.getXWikiApi(componentManager)); |
94 |
|
|
95 |
134 |
if (parentFilter != null) { |
96 |
0 |
String parentId = ""; |
97 |
0 |
if (parent != null && !parent.isNew()) { |
98 |
0 |
parentId = parent.getPrefixedFullName(); |
99 |
|
} |
100 |
0 |
add = parentFilter.matcher(parentId).matches(); |
101 |
|
} |
102 |
|
|
103 |
134 |
if (add) { |
104 |
134 |
pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, |
105 |
|
uriInfo.getBaseUri(), doc, Utils.getXWikiApi(componentManager), withPrettyNames)); |
106 |
|
} |
107 |
|
} |
108 |
|
} |
109 |
|
} |
110 |
|
} catch (Exception e) { |
111 |
0 |
throw new XWikiRestException(e); |
112 |
|
} finally { |
113 |
17 |
Utils.getXWikiContext(componentManager).setWikiId(database); |
114 |
|
} |
115 |
|
|
116 |
17 |
return pages; |
117 |
|
} |
118 |
|
} |