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

File AttachmentsByFirstLettersSubView.java

 

Coverage histogram

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

Code metrics

12
30
3
1
105
71
14
0.47
10
3
4.67

Classes

Class Line # Actions
AttachmentsByFirstLettersSubView 43 30 0% 14 45
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.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    * The view responsible for holding a set of pages (with attachments) all of which begin with a particular phrase.
40    *
41    * @version $Id: d91db8e3c87048eab7fd93f674ffc6048724e20d $
42    */
 
43    public class AttachmentsByFirstLettersSubView extends AbstractDavView
44    {
45    /**
46    * Logger instance.
47    */
48    private static final Logger logger = LoggerFactory.getLogger(AttachmentsByFirstLettersSubView.class);
49   
 
50  0 toggle @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   
 
60  0 toggle @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   
 
77  0 toggle @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    }