1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
@since |
46 |
|
|
47 |
|
@Component |
48 |
|
@Named("attachments") |
49 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 84.6% |
Uncovered Elements: 4 (26) |
Complexity: 7 |
Complexity Density: 0.39 |
|
50 |
|
public class AttachmentsTreeNode extends AbstractDocumentTreeNode |
51 |
|
{ |
52 |
|
@Inject |
53 |
|
private ContextualAuthorizationManager authorization; |
54 |
|
|
55 |
|
@Inject |
56 |
|
private Provider<XWikiContext> xcontextProvider; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
128 |
public AttachmentsTreeNode()... |
62 |
|
{ |
63 |
128 |
super("attachments"); |
64 |
|
} |
65 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
66 |
1 |
@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 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
85 |
24 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
25 |
private boolean showAddAttachment(DocumentReference documentReference)... |
102 |
|
{ |
103 |
25 |
return Boolean.TRUE.equals(getProperties().get("showAddAttachment")) |
104 |
|
&& this.authorization.hasAccess(Right.EDIT, documentReference); |
105 |
|
} |
106 |
|
} |