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.List; |
24 |
|
|
25 |
|
import org.apache.jackrabbit.webdav.DavException; |
26 |
|
import org.apache.jackrabbit.webdav.DavResource; |
27 |
|
import org.apache.jackrabbit.webdav.DavResourceIterator; |
28 |
|
import org.apache.jackrabbit.webdav.DavResourceIteratorImpl; |
29 |
|
import org.apache.jackrabbit.webdav.DavServletResponse; |
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.slf4j.LoggerFactory; |
32 |
|
|
33 |
|
import com.xpn.xwiki.plugin.webdav.resources.XWikiDavResource; |
34 |
|
import com.xpn.xwiki.plugin.webdav.resources.domain.DavPage; |
35 |
|
import com.xpn.xwiki.plugin.webdav.resources.partial.AbstractDavView; |
36 |
|
import com.xpn.xwiki.plugin.webdav.utils.XWikiDavUtils; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 14 |
Complexity Density: 0.47 |
|
43 |
|
public class AttachmentsByFirstLettersSubView extends AbstractDavView |
44 |
|
{ |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
private static final Logger logger = LoggerFactory.getLogger(AttachmentsByFirstLettersSubView.class); |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 4 |
Complexity Density: 1.33 |
|
50 |
0 |
@Override... |
51 |
|
public void init(XWikiDavResource parent, String name, String relativePath) throws DavException |
52 |
|
{ |
53 |
0 |
super.init(parent, name, relativePath); |
54 |
0 |
if (!name.startsWith(XWikiDavUtils.VIRTUAL_DIRECTORY_PREFIX) |
55 |
|
|| !name.endsWith(XWikiDavUtils.VIRTUAL_DIRECTORY_POSTFIX) || !name.equals(name.toUpperCase())) { |
56 |
0 |
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR); |
57 |
|
} |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 6 |
Complexity Density: 0.6 |
|
60 |
0 |
@Override... |
61 |
|
public XWikiDavResource decode(String[] tokens, int next) throws DavException |
62 |
|
{ |
63 |
0 |
String nextToken = tokens[next]; |
64 |
0 |
String pageName = getCollection().getDisplayName() + "." + nextToken; |
65 |
0 |
boolean last = (next == tokens.length - 1); |
66 |
0 |
if (isTempResource(nextToken)) { |
67 |
0 |
return super.decode(tokens, next); |
68 |
0 |
} else if (getContext().exists(pageName) && !(last && getContext().isCreateOrMoveRequest())) { |
69 |
0 |
DavPage page = new DavPage(); |
70 |
0 |
page.init(this, pageName, "/" + nextToken); |
71 |
0 |
return last ? page : page.decode(tokens, next + 1); |
72 |
|
} else { |
73 |
0 |
throw new DavException(DavServletResponse.SC_BAD_REQUEST); |
74 |
|
} |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 4 |
Complexity Density: 0.24 |
|
77 |
0 |
@Override... |
78 |
|
public DavResourceIterator getMembers() |
79 |
|
{ |
80 |
0 |
List<DavResource> children = new ArrayList<DavResource>(); |
81 |
0 |
String spaceName = getCollection().getDisplayName(); |
82 |
0 |
String filter = |
83 |
|
getDisplayName().substring(XWikiDavUtils.VIRTUAL_DIRECTORY_PREFIX.length(), |
84 |
|
getDisplayName().length() - XWikiDavUtils.VIRTUAL_DIRECTORY_POSTFIX.length()); |
85 |
0 |
try { |
86 |
0 |
String sql = ", XWikiAttachment as attach where doc.id = attach.docId and doc.web = '" + spaceName + "'"; |
87 |
0 |
List<String> docNames = getContext().searchDocumentsNames(sql); |
88 |
0 |
for (String docName : docNames) { |
89 |
0 |
if (getContext().hasAccess("view", docName)) { |
90 |
0 |
int dot = docName.lastIndexOf('.'); |
91 |
0 |
String pageName = docName.substring(dot + 1); |
92 |
0 |
if (pageName.toUpperCase().startsWith(filter)) { |
93 |
0 |
DavPage page = new DavPage(); |
94 |
0 |
page.init(this, docName, "/" + pageName); |
95 |
0 |
children.add(page); |
96 |
|
} |
97 |
|
} |
98 |
|
} |
99 |
|
} catch (DavException e) { |
100 |
0 |
logger.error("Unexpected Error : ", e); |
101 |
|
} |
102 |
0 |
children.addAll(getVirtualMembers()); |
103 |
0 |
return new DavResourceIteratorImpl(children); |
104 |
|
} |
105 |
|
} |