1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.webdav.resources.views.attachments

File AttachmentsView.java

 

Coverage histogram

../../../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

10
26
2
1
93
60
10
0.38
13
2
5

Classes

Class Line # Actions
AttachmentsView 43 26 0% 10 38
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * This view list all documents containing attachments.
40    *
41    * @version $Id: bdd6750b48e0050d91fc09ec3bc9f319c8847f5b $
42    */
 
43    public class AttachmentsView extends AbstractDavView
44    {
45    /**
46    * Logger instance.
47    */
48    private static final Logger logger = LoggerFactory.getLogger(AttachmentsView.class);
49   
 
50  0 toggle @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   
 
66  0 toggle @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    }