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.attachments; |
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.slf4j.Logger; |
33 |
|
import org.slf4j.LoggerFactory; |
34 |
|
|
35 |
|
import com.xpn.xwiki.plugin.webdav.resources.XWikiDavResource; |
36 |
|
import com.xpn.xwiki.plugin.webdav.resources.partial.AbstractDavView; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 10 |
Complexity Density: 0.38 |
|
43 |
|
public class AttachmentsView extends AbstractDavView |
44 |
|
{ |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
private static final Logger logger = LoggerFactory.getLogger(AttachmentsView.class); |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 6 |
Complexity Density: 0.67 |
|
50 |
0 |
@Override... |
51 |
|
public XWikiDavResource decode(String[] tokens, int next) throws DavException |
52 |
|
{ |
53 |
0 |
String nextToken = tokens[next]; |
54 |
0 |
boolean last = (next == tokens.length - 1); |
55 |
0 |
if (isTempResource(nextToken)) { |
56 |
0 |
return super.decode(tokens, next); |
57 |
0 |
} else if (getContext().getSpaces().contains(nextToken) && !(last && getContext().isCreateOrMoveRequest())) { |
58 |
0 |
AttachmentsBySpaceNameSubView subView = new AttachmentsBySpaceNameSubView(); |
59 |
0 |
subView.init(this, nextToken, "/" + nextToken); |
60 |
0 |
return last ? subView : subView.decode(tokens, next + 1); |
61 |
|
} else { |
62 |
0 |
throw new DavException(DavServletResponse.SC_BAD_REQUEST); |
63 |
|
} |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 4 |
Complexity Density: 0.24 |
|
66 |
0 |
@Override... |
67 |
|
public DavResourceIterator getMembers() |
68 |
|
{ |
69 |
0 |
List<DavResource> children = new ArrayList<DavResource>(); |
70 |
0 |
try { |
71 |
0 |
String sql = ", XWikiAttachment as attach where doc.id = attach.docId"; |
72 |
0 |
List<String> docNames = getContext().searchDocumentsNames(sql); |
73 |
0 |
Set<String> spacesWithAttachments = new HashSet<String>(); |
74 |
0 |
for (String docName : docNames) { |
75 |
0 |
if (getContext().hasAccess("view", docName)) { |
76 |
0 |
int dot = docName.lastIndexOf('.'); |
77 |
0 |
if (dot != -1) { |
78 |
0 |
spacesWithAttachments.add(docName.substring(0, dot)); |
79 |
|
} |
80 |
|
} |
81 |
|
} |
82 |
0 |
for (String spaceName : spacesWithAttachments) { |
83 |
0 |
AttachmentsBySpaceNameSubView subView = new AttachmentsBySpaceNameSubView(); |
84 |
0 |
subView.init(this, spaceName, "/" + spaceName); |
85 |
0 |
children.add(subView); |
86 |
|
} |
87 |
|
} catch (DavException e) { |
88 |
0 |
logger.error("Unexpected Error : ", e); |
89 |
|
} |
90 |
0 |
children.addAll(getVirtualMembers()); |
91 |
0 |
return new DavResourceIteratorImpl(children); |
92 |
|
} |
93 |
|
} |