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.webdav.resources.views.pages; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.HashSet; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Set; |
26 |
|
|
27 |
|
import org.apache.jackrabbit.webdav.DavException; |
28 |
|
import org.apache.jackrabbit.webdav.DavResource; |
29 |
|
import org.apache.jackrabbit.webdav.DavResourceIterator; |
30 |
|
import org.apache.jackrabbit.webdav.DavResourceIteratorImpl; |
31 |
|
import org.apache.jackrabbit.webdav.DavServletResponse; |
32 |
|
import org.apache.jackrabbit.webdav.io.InputContext; |
33 |
|
import org.slf4j.Logger; |
34 |
|
import org.slf4j.LoggerFactory; |
35 |
|
|
36 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
37 |
|
import com.xpn.xwiki.plugin.webdav.resources.XWikiDavResource; |
38 |
|
import com.xpn.xwiki.plugin.webdav.resources.domain.DavPage; |
39 |
|
import com.xpn.xwiki.plugin.webdav.resources.partial.AbstractDavView; |
40 |
|
import com.xpn.xwiki.plugin.webdav.utils.XWikiDavUtils; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
|
|
|
| 47.3% |
Uncovered Elements: 69 (131) |
Complexity: 31 |
Complexity Density: 0.34 |
|
47 |
|
public class PagesBySpaceNameSubView extends AbstractDavView |
48 |
|
{ |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private static final Logger logger = LoggerFactory.getLogger(PagesBySpaceNameSubView.class); |
53 |
|
|
|
|
| 53.8% |
Uncovered Elements: 12 (26) |
Complexity: 11 |
Complexity Density: 0.69 |
|
54 |
17 |
@Override... |
55 |
|
public XWikiDavResource decode(String[] tokens, int next) throws DavException |
56 |
|
{ |
57 |
17 |
String nextToken = tokens[next]; |
58 |
17 |
boolean last = (next == tokens.length - 1); |
59 |
17 |
XWikiDavResource resource = null; |
60 |
17 |
if (isTempResource(nextToken)) { |
61 |
0 |
return super.decode(tokens, next); |
62 |
17 |
} else if ((nextToken.startsWith(XWikiDavUtils.VIRTUAL_DIRECTORY_PREFIX) && nextToken |
63 |
|
.endsWith(XWikiDavUtils.VIRTUAL_DIRECTORY_POSTFIX)) |
64 |
|
&& !(last && getContext().isCreateOrMoveRequest())) { |
65 |
0 |
resource = new PagesByFirstLettersSubView(); |
66 |
0 |
resource.init(this, nextToken.toUpperCase(), "/" + nextToken.toUpperCase()); |
67 |
17 |
} else if (getContext().isCreateCollectionRequest() || getContext().exists(this.name + "." + nextToken)) { |
68 |
17 |
resource = new DavPage(); |
69 |
17 |
resource.init(this, this.name + "." + nextToken, "/" + nextToken); |
70 |
0 |
} else if (nextToken.startsWith(this.name + ".") && getContext().exists(nextToken)) { |
71 |
|
|
72 |
0 |
resource = new DavPage(); |
73 |
0 |
resource.init(this, nextToken, "/" + nextToken); |
74 |
|
} else { |
75 |
0 |
throw new DavException(DavServletResponse.SC_BAD_REQUEST); |
76 |
|
} |
77 |
17 |
return last ? resource : resource.decode(tokens, next + 1); |
78 |
|
} |
79 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
80 |
32 |
@Override... |
81 |
|
public boolean exists() |
82 |
|
{ |
83 |
32 |
try { |
84 |
32 |
List<String> spaces = getContext().getSpaces(); |
85 |
32 |
if (spaces.contains(name)) { |
86 |
11 |
return true; |
87 |
|
} |
88 |
|
} catch (DavException ex) { |
89 |
0 |
logger.error("Unexpected Error : ", ex); |
90 |
|
} |
91 |
21 |
return false; |
92 |
|
} |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 5 |
Complexity Density: 0.22 |
|
94 |
0 |
@Override... |
95 |
|
public DavResourceIterator getMembers() |
96 |
|
{ |
97 |
0 |
List<DavResource> children = new ArrayList<DavResource>(); |
98 |
0 |
try { |
99 |
0 |
String sql = "where doc.web='" + this.name + "'"; |
100 |
0 |
List<String> docNames = getContext().searchDocumentsNames(sql); |
101 |
0 |
Set<String> subViewNames = new HashSet<String>(); |
102 |
0 |
int subViewNameLength = XWikiDavUtils.getSubViewNameLength(docNames.size()); |
103 |
0 |
for (String docName : docNames) { |
104 |
0 |
if (getContext().hasAccess("view", docName)) { |
105 |
0 |
int dot = docName.lastIndexOf('.'); |
106 |
0 |
String pageName = docName.substring(dot + 1); |
107 |
0 |
if (subViewNameLength < pageName.length()) { |
108 |
0 |
subViewNames.add(pageName.substring(0, subViewNameLength).toUpperCase()); |
109 |
|
} else { |
110 |
|
|
111 |
0 |
subViewNames.add(pageName.toUpperCase()); |
112 |
|
} |
113 |
|
} |
114 |
|
} |
115 |
0 |
for (String subViewName : subViewNames) { |
116 |
0 |
try { |
117 |
0 |
String modName = |
118 |
|
XWikiDavUtils.VIRTUAL_DIRECTORY_PREFIX + subViewName + XWikiDavUtils.VIRTUAL_DIRECTORY_POSTFIX; |
119 |
0 |
PagesByFirstLettersSubView subView = new PagesByFirstLettersSubView(); |
120 |
0 |
subView.init(this, modName, "/" + modName); |
121 |
0 |
children.add(subView); |
122 |
|
} catch (DavException e) { |
123 |
0 |
logger.error("Unexpected Error : ", e); |
124 |
|
} |
125 |
|
} |
126 |
|
} catch (DavException ex) { |
127 |
0 |
logger.error("Unexpected Error : ", ex); |
128 |
|
} |
129 |
0 |
children.addAll(getVirtualMembers()); |
130 |
0 |
return new DavResourceIteratorImpl(children); |
131 |
|
} |
132 |
|
|
|
|
| 72.7% |
Uncovered Elements: 3 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
133 |
4 |
@Override... |
134 |
|
public void addMember(DavResource resource, InputContext inputContext) throws DavException |
135 |
|
{ |
136 |
4 |
if (resource instanceof DavPage) { |
137 |
4 |
String pName = resource.getDisplayName(); |
138 |
4 |
if (getContext().hasAccess("edit", pName)) { |
139 |
4 |
XWikiDocument childDoc = getContext().getDocument(pName); |
140 |
4 |
childDoc.setContent("This page was created through the WebDAV interface."); |
141 |
4 |
getContext().saveDocument(childDoc); |
142 |
|
} |
143 |
|
} else { |
144 |
0 |
super.addMember(resource, inputContext); |
145 |
|
} |
146 |
|
} |
147 |
|
|
|
|
| 34.5% |
Uncovered Elements: 19 (29) |
Complexity: 5 |
Complexity Density: 0.24 |
|
148 |
4 |
@Override... |
149 |
|
public void removeMember(DavResource member) throws DavException |
150 |
|
{ |
151 |
4 |
XWikiDavResource davResource = (XWikiDavResource) member; |
152 |
4 |
if (davResource instanceof DavPage) { |
153 |
4 |
String pName = davResource.getDisplayName(); |
154 |
4 |
getContext().checkAccess("delete", pName); |
155 |
4 |
XWikiDocument childDoc = getContext().getDocument(pName); |
156 |
4 |
if (!childDoc.isNew()) { |
157 |
4 |
getContext().deleteDocument(childDoc); |
158 |
|
} |
159 |
0 |
} else if (member instanceof PagesByFirstLettersSubView) { |
160 |
|
|
161 |
0 |
String filter = |
162 |
|
member.getDisplayName().substring(XWikiDavUtils.VIRTUAL_DIRECTORY_PREFIX.length(), |
163 |
|
member.getDisplayName().length() - XWikiDavUtils.VIRTUAL_DIRECTORY_POSTFIX.length()); |
164 |
0 |
String sql = "where doc.web='" + this.name + "'"; |
165 |
0 |
List<String> docNames = getContext().searchDocumentsNames(sql); |
166 |
0 |
List<String> filteredDocNames = new ArrayList<String>(); |
167 |
0 |
for (String docName : docNames) { |
168 |
0 |
if (docName.toUpperCase().startsWith(filter)) { |
169 |
0 |
filteredDocNames.add(docName); |
170 |
|
} |
171 |
|
} |
172 |
|
|
173 |
0 |
for (String docName : filteredDocNames) { |
174 |
0 |
getContext().checkAccess("delete", docName); |
175 |
|
} |
176 |
|
|
177 |
0 |
for (String docName : filteredDocNames) { |
178 |
0 |
getContext().deleteDocument(getContext().getDocument(docName)); |
179 |
|
} |
180 |
|
} else { |
181 |
0 |
super.removeMember(member); |
182 |
|
} |
183 |
4 |
davResource.clearCache(); |
184 |
|
} |
185 |
|
|
|
|
| 75% |
Uncovered Elements: 6 (24) |
Complexity: 4 |
Complexity Density: 0.22 |
|
186 |
1 |
@Override... |
187 |
|
public void move(DavResource destination) throws DavException |
188 |
|
{ |
189 |
|
|
190 |
1 |
if (destination instanceof PagesBySpaceNameSubView) { |
191 |
1 |
PagesBySpaceNameSubView dSpace = (PagesBySpaceNameSubView) destination; |
192 |
1 |
if (!dSpace.exists()) { |
193 |
|
|
194 |
1 |
if (getCollection().equals(dSpace.getCollection())) { |
195 |
1 |
String sql = "where doc.web='" + this.name + "'"; |
196 |
1 |
List<String> docNames = getContext().searchDocumentsNames(sql); |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
1 |
for (String docName : docNames) { |
201 |
1 |
String newDocName = dSpace.getDisplayName() + "." + docName; |
202 |
1 |
getContext().checkAccess("edit", docName); |
203 |
1 |
getContext().checkAccess("overwrite", newDocName); |
204 |
|
} |
205 |
1 |
for (String docName : docNames) { |
206 |
1 |
XWikiDocument doc = getContext().getDocument(docName); |
207 |
1 |
String newDocName = dSpace.getDisplayName() + "." + doc.getName(); |
208 |
1 |
getContext().renameDocument(doc, newDocName); |
209 |
|
} |
210 |
|
} else { |
211 |
|
|
212 |
|
|
213 |
0 |
throw new DavException(DavServletResponse.SC_BAD_REQUEST); |
214 |
|
} |
215 |
|
} else { |
216 |
0 |
throw new DavException(DavServletResponse.SC_BAD_REQUEST); |
217 |
|
} |
218 |
|
} else { |
219 |
0 |
throw new DavException(DavServletResponse.SC_BAD_REQUEST); |
220 |
|
} |
221 |
1 |
clearCache(); |
222 |
|
} |
223 |
|
} |