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

File PagesByFirstLettersSubView.java

 

Coverage histogram

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

Code metrics

16
36
5
1
129
91
17
0.47
7.2
5
3.4

Classes

Class Line # Actions
PagesByFirstLettersSubView 45 36 0% 17 57
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.pages;
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.apache.jackrabbit.webdav.io.InputContext;
31    import org.slf4j.Logger;
32    import org.slf4j.LoggerFactory;
33   
34    import com.xpn.xwiki.plugin.webdav.resources.XWikiDavResource;
35    import com.xpn.xwiki.plugin.webdav.resources.domain.DavPage;
36    import com.xpn.xwiki.plugin.webdav.resources.domain.DavTempFile;
37    import com.xpn.xwiki.plugin.webdav.resources.partial.AbstractDavView;
38    import com.xpn.xwiki.plugin.webdav.utils.XWikiDavUtils;
39   
40    /**
41    * The view responsible for holding a set of pages all of which begin with a particular phrase.
42    *
43    * @version $Id: 77d15873efefd017df0e6947985e871270b9cecf $
44    */
 
45    public class PagesByFirstLettersSubView extends AbstractDavView
46    {
47    /**
48    * Logger instance.
49    */
50    private static final Logger logger = LoggerFactory.getLogger(PagesByFirstLettersSubView.class);
51   
 
52  0 toggle @Override
53    public void init(XWikiDavResource parent, String name, String relativePath) throws DavException
54    {
55  0 super.init(parent, name, relativePath);
56  0 if (!name.startsWith(XWikiDavUtils.VIRTUAL_DIRECTORY_PREFIX)
57    || !name.endsWith(XWikiDavUtils.VIRTUAL_DIRECTORY_POSTFIX) || !name.equals(name.toUpperCase())) {
58  0 throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
59    }
60    }
61   
 
62  0 toggle @Override
63    public XWikiDavResource decode(String[] tokens, int next) throws DavException
64    {
65  0 String spaceName = getCollection().getDisplayName();
66  0 boolean last = (next == tokens.length - 1);
67  0 String nextToken = tokens[next];
68  0 if (isTempResource(nextToken)) {
69  0 return super.decode(tokens, next);
70  0 } else if (!(last && getContext().isCreateFileRequest())) {
71  0 DavPage page = new DavPage();
72  0 page.init(this, spaceName + "." + nextToken, "/" + nextToken);
73  0 return last ? page : page.decode(tokens, next + 1);
74    } else {
75  0 throw new DavException(DavServletResponse.SC_BAD_REQUEST);
76    }
77    }
78   
 
79  0 toggle @Override
80    public DavResourceIterator getMembers()
81    {
82  0 List<DavResource> children = new ArrayList<DavResource>();
83  0 String spaceName = getCollection().getDisplayName();
84  0 String filter =
85    getDisplayName().substring(XWikiDavUtils.VIRTUAL_DIRECTORY_PREFIX.length(),
86    getDisplayName().length() - XWikiDavUtils.VIRTUAL_DIRECTORY_POSTFIX.length());
87  0 try {
88  0 String sql = "where doc.web='" + spaceName + "'";
89  0 List<String> docNames = getContext().searchDocumentsNames(sql);
90  0 for (String docName : docNames) {
91  0 if (getContext().hasAccess("view", docName)) {
92  0 int dot = docName.lastIndexOf('.');
93  0 String pageName = docName.substring(dot + 1);
94  0 if (pageName.toUpperCase().startsWith(filter)) {
95  0 DavPage page = new DavPage();
96  0 page.init(this, docName, "/" + pageName);
97  0 children.add(page);
98    }
99    }
100    }
101    } catch (DavException e) {
102  0 logger.error("Unexpected Error : ", e);
103    }
104  0 children.addAll(getVirtualMembers());
105  0 return new DavResourceIteratorImpl(children);
106    }
107   
 
108  0 toggle @Override
109    public void addMember(DavResource resource, InputContext inputContext) throws DavException
110    {
111  0 if (resource instanceof DavTempFile) {
112  0 addVirtualMember(resource, inputContext);
113    } else {
114    // This is only a virtual grouping of pages. Delegate the request to the parent.
115  0 getCollection().addMember(resource, inputContext);
116    }
117    }
118   
 
119  0 toggle @Override
120    public void removeMember(DavResource member) throws DavException
121    {
122  0 if (member instanceof DavTempFile) {
123  0 removeVirtualMember(member);
124    } else {
125    // This is only a virtual grouping of pages. Delegate the request to the parent.
126  0 getCollection().removeMember(member);
127    }
128    }
129    }