1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.index.tree.internal.nestedpages

File AttachmentsTreeNode.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
18
4
1
106
61
7
0.39
4.5
4
1.75

Classes

Class Line # Actions
AttachmentsTreeNode 50 18 0% 7 4
0.8461538684.6%
 

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 org.xwiki.index.tree.internal.nestedpages;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.annotation.InstantiationStrategy;
31    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
32    import org.xwiki.model.reference.DocumentReference;
33    import org.xwiki.security.authorization.ContextualAuthorizationManager;
34    import org.xwiki.security.authorization.Right;
35   
36    import com.xpn.xwiki.XWikiContext;
37    import com.xpn.xwiki.doc.XWikiAttachment;
38    import com.xpn.xwiki.doc.XWikiDocument;
39   
40    /**
41    * The attachments tree node.
42    *
43    * @version $Id: 71fb2a153faa4e70ac950d0b8ef93bbd38664742 $
44    * @since 8.3M2
45    * @since 7.4.5
46    */
47    @Component
48    @Named("attachments")
49    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
50    public class AttachmentsTreeNode extends AbstractDocumentTreeNode
51    {
52    @Inject
53    private ContextualAuthorizationManager authorization;
54   
55    @Inject
56    private Provider<XWikiContext> xcontextProvider;
57   
58    /**
59    * Default constructor.
60    */
 
61  128 toggle public AttachmentsTreeNode()
62    {
63  128 super("attachments");
64    }
65   
 
66  1 toggle @Override
67    protected List<String> getChildren(DocumentReference documentReference, int offset, int limit) throws Exception
68    {
69  1 List<String> children = new ArrayList<String>();
70   
71  1 if (offset == 0 && showAddAttachment(documentReference)) {
72  0 children.add("addAttachment:" + this.defaultEntityReferenceSerializer.serialize(documentReference));
73    }
74   
75  1 XWikiContext xcontext = this.xcontextProvider.get();
76  1 XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
77  1 List<XWikiAttachment> attachments = document.getAttachmentList();
78  1 for (XWikiAttachment attachment : subList(attachments, offset, limit)) {
79  1 children.add(serialize(attachment.getReference()));
80    }
81   
82  1 return children;
83    }
84   
 
85  24 toggle @Override
86    protected int getChildCount(DocumentReference documentReference) throws Exception
87    {
88  24 int count = 0;
89   
90  24 if (showAddAttachment(documentReference)) {
91  0 count++;
92    }
93   
94  24 XWikiContext xcontext = this.xcontextProvider.get();
95  24 XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
96  24 count += document.getAttachmentList().size();
97   
98  24 return count;
99    }
100   
 
101  25 toggle private boolean showAddAttachment(DocumentReference documentReference)
102    {
103  25 return Boolean.TRUE.equals(getProperties().get("showAddAttachment"))
104    && this.authorization.hasAccess(Right.EDIT, documentReference);
105    }
106    }