1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.vfs.internal.attach; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.net.URI; |
24 |
|
|
25 |
|
import javax.inject.Provider; |
26 |
|
|
27 |
|
import org.xwiki.component.manager.ComponentManager; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
30 |
|
|
31 |
|
import com.xpn.xwiki.XWikiContext; |
32 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
33 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
34 |
|
|
35 |
|
import net.java.truevfs.kernel.spec.FsNodeName; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
|
|
| 87.5% |
Uncovered Elements: 5 (40) |
Complexity: 13 |
Complexity Density: 0.46 |
|
44 |
|
public class XWikiModelNode |
45 |
|
{ |
46 |
|
private ComponentManager componentManager; |
47 |
|
|
48 |
|
private DocumentReference reference; |
49 |
|
|
50 |
|
private XWikiAttachment attachment; |
51 |
|
|
52 |
|
private XWikiContext xcontext; |
53 |
|
|
54 |
|
private URI uri; |
55 |
|
|
56 |
|
private String name; |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
58 |
4 |
XWikiModelNode(AttachController controller, FsNodeName name)... |
59 |
|
{ |
60 |
4 |
this.name = name.toString(); |
61 |
4 |
this.uri = controller.resolve(name).getUri(); |
62 |
4 |
this.componentManager = controller.getComponentManager(); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
8 |
private ComponentManager getComponentManager()... |
66 |
|
{ |
67 |
8 |
return this.componentManager; |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
@return |
72 |
|
@throws |
73 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
74 |
4 |
public DocumentReference getDocumentReference() throws IOException... |
75 |
|
{ |
76 |
4 |
if (this.reference == null) { |
77 |
4 |
try { |
78 |
|
|
79 |
|
|
80 |
4 |
DocumentReferenceResolver<String> documentReferenceResolver = |
81 |
|
getComponentManager().getInstance(DocumentReferenceResolver.TYPE_STRING); |
82 |
4 |
this.reference = documentReferenceResolver.resolve(this.uri.getAuthority()); |
83 |
|
} catch (Exception e) { |
84 |
0 |
throw new IOException( |
85 |
|
String.format("Failed to compute Document reference for [%s]", this.uri), e); |
86 |
|
} |
87 |
|
} |
88 |
4 |
return this.reference; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
@return |
93 |
|
@throws |
94 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
95 |
12 |
public XWikiContext getXWikiContext() throws IOException... |
96 |
|
{ |
97 |
12 |
if (this.xcontext == null) { |
98 |
4 |
try { |
99 |
4 |
Provider<XWikiContext> xcontextProvider = getComponentManager().getInstance(XWikiContext.TYPE_PROVIDER); |
100 |
4 |
this.xcontext = xcontextProvider.get(); |
101 |
|
} catch (Exception e) { |
102 |
0 |
throw new IOException(String.format("Failed to get XWiki Context for [%s]", this.uri), e); |
103 |
|
} |
104 |
|
} |
105 |
12 |
return this.xcontext; |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
@return |
110 |
|
@since |
111 |
|
@since |
112 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
113 |
2 |
public boolean hasAttachment()... |
114 |
|
{ |
115 |
2 |
boolean result; |
116 |
2 |
try { |
117 |
2 |
getAttachment(); |
118 |
2 |
result = true; |
119 |
|
} catch (Exception e) { |
120 |
0 |
result = false; |
121 |
|
} |
122 |
2 |
return result; |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
@return |
127 |
|
@throws |
128 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
129 |
8 |
public XWikiAttachment getAttachment() throws IOException... |
130 |
|
{ |
131 |
8 |
if (this.attachment == null) { |
132 |
4 |
try { |
133 |
4 |
XWikiDocument document = getXWikiContext().getWiki().getDocument( |
134 |
|
getDocumentReference(), getXWikiContext()); |
135 |
4 |
this.attachment = document.getAttachment(this.name); |
136 |
|
} catch (Exception e) { |
137 |
0 |
throw new IOException(String.format("Failed to get Attachment for [%s]", this.uri), e); |
138 |
|
} |
139 |
|
} |
140 |
8 |
return this.attachment; |
141 |
|
} |
142 |
|
} |