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 |
|
import com.xpn.xwiki.plugin.webdav.utils.XWikiDavUtils; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 12 |
Complexity Density: 0.38 |
|
44 |
|
public class AttachmentsBySpaceNameSubView extends AbstractDavView |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
private static final Logger logger = LoggerFactory.getLogger(AttachmentsBySpaceNameSubView.class); |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 7 |
Complexity Density: 0.78 |
|
51 |
0 |
@Override... |
52 |
|
public XWikiDavResource decode(String[] tokens, int next) throws DavException |
53 |
|
{ |
54 |
0 |
String nextToken = tokens[next]; |
55 |
0 |
boolean last = (next == tokens.length - 1); |
56 |
0 |
if (isTempResource(nextToken)) { |
57 |
0 |
return super.decode(tokens, next); |
58 |
0 |
} else if ((nextToken.startsWith(XWikiDavUtils.VIRTUAL_DIRECTORY_PREFIX) && nextToken |
59 |
|
.endsWith(XWikiDavUtils.VIRTUAL_DIRECTORY_POSTFIX)) |
60 |
|
&& !(last && getContext().isCreateOrMoveRequest())) { |
61 |
0 |
AttachmentsByFirstLettersSubView subView = new AttachmentsByFirstLettersSubView(); |
62 |
0 |
subView.init(this, nextToken.toUpperCase(), "/" + nextToken.toUpperCase()); |
63 |
0 |
return last ? subView : subView.decode(tokens, next + 1); |
64 |
|
} else { |
65 |
0 |
throw new DavException(DavServletResponse.SC_BAD_REQUEST); |
66 |
|
} |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 5 |
Complexity Density: 0.22 |
|
69 |
0 |
@Override... |
70 |
|
public DavResourceIterator getMembers() |
71 |
|
{ |
72 |
0 |
List<DavResource> children = new ArrayList<DavResource>(); |
73 |
0 |
try { |
74 |
0 |
String sql = |
75 |
|
", XWikiAttachment as attach where doc.id = attach.docId and doc.web = '" + getDisplayName() + "'"; |
76 |
0 |
List<String> docNames = getContext().searchDocumentsNames(sql); |
77 |
0 |
Set<String> subViewNames = new HashSet<String>(); |
78 |
0 |
int subViewNameLength = XWikiDavUtils.getSubViewNameLength(docNames.size()); |
79 |
0 |
for (String docName : docNames) { |
80 |
0 |
if (getContext().hasAccess("view", docName)) { |
81 |
0 |
int dot = docName.lastIndexOf('.'); |
82 |
0 |
String pageName = docName.substring(dot + 1); |
83 |
0 |
if (subViewNameLength < pageName.length()) { |
84 |
0 |
subViewNames.add(pageName.substring(0, subViewNameLength).toUpperCase()); |
85 |
|
} else { |
86 |
|
|
87 |
0 |
subViewNames.add(pageName.toUpperCase()); |
88 |
|
} |
89 |
|
} |
90 |
|
} |
91 |
0 |
for (String subViewName : subViewNames) { |
92 |
0 |
try { |
93 |
0 |
String modName = |
94 |
|
XWikiDavUtils.VIRTUAL_DIRECTORY_PREFIX + subViewName + XWikiDavUtils.VIRTUAL_DIRECTORY_POSTFIX; |
95 |
0 |
AttachmentsByFirstLettersSubView subView = new AttachmentsByFirstLettersSubView(); |
96 |
0 |
subView.init(this, modName, "/" + modName); |
97 |
0 |
children.add(subView); |
98 |
|
} catch (DavException e) { |
99 |
0 |
logger.error("Unexpected Error : ", e); |
100 |
|
} |
101 |
|
} |
102 |
|
} catch (DavException ex) { |
103 |
0 |
logger.error("Unexpected Error : ", ex); |
104 |
|
} |
105 |
0 |
children.addAll(getVirtualMembers()); |
106 |
0 |
return new DavResourceIteratorImpl(children); |
107 |
|
} |
108 |
|
} |