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

File AttachmentsBySpaceNameSubView.java

 

Coverage histogram

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

Code metrics

10
32
2
1
108
74
12
0.38
16
2
6

Classes

Class Line # Actions
AttachmentsBySpaceNameSubView 44 32 0% 12 44
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    import com.xpn.xwiki.plugin.webdav.utils.XWikiDavUtils;
38   
39    /**
40    * This view groups all pages having attachments according to their space name.
41    *
42    * @version $Id: 61b2e58e1368cca13a9edab48014a90841b4354d $
43    */
 
44    public class AttachmentsBySpaceNameSubView extends AbstractDavView
45    {
46    /**
47    * Logger instance.
48    */
49    private static final Logger logger = LoggerFactory.getLogger(AttachmentsBySpaceNameSubView.class);
50   
 
51  0 toggle @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   
 
69  0 toggle @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    // This is not good.
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    }