1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.webdav.resources.domain; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.OutputStream; |
24 |
|
|
25 |
|
import org.apache.jackrabbit.server.io.IOUtil; |
26 |
|
import org.apache.jackrabbit.webdav.DavConstants; |
27 |
|
import org.apache.jackrabbit.webdav.DavException; |
28 |
|
import org.apache.jackrabbit.webdav.DavResource; |
29 |
|
import org.apache.jackrabbit.webdav.DavServletResponse; |
30 |
|
import org.apache.jackrabbit.webdav.io.OutputContext; |
31 |
|
import org.apache.jackrabbit.webdav.property.DavPropertyName; |
32 |
|
import org.apache.jackrabbit.webdav.property.DefaultDavProperty; |
33 |
|
|
34 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
35 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
36 |
|
import com.xpn.xwiki.plugin.webdav.resources.XWikiDavResource; |
37 |
|
import com.xpn.xwiki.plugin.webdav.resources.partial.AbstractDavFile; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@version |
43 |
|
|
|
|
| 59.4% |
Uncovered Elements: 26 (64) |
Complexity: 15 |
Complexity Density: 0.37 |
|
44 |
|
public class DavAttachment extends AbstractDavFile |
45 |
|
{ |
46 |
|
|
47 |
|
@link |
48 |
|
|
49 |
|
private XWikiAttachment attachment; |
50 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
51 |
3 |
@Override... |
52 |
|
public void init(XWikiDavResource parent, String name, String relativePath) |
53 |
|
throws DavException |
54 |
|
{ |
55 |
3 |
super.init(parent, name, relativePath); |
56 |
3 |
if (parent.exists()) { |
57 |
3 |
this.attachment = ((DavPage) parent).getDocument().getAttachment(this.name); |
58 |
|
} |
59 |
3 |
if (exists()) { |
60 |
2 |
String timeStamp = DavConstants.creationDateFormat.format(attachment.getDate()); |
61 |
2 |
getProperties().add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, timeStamp)); |
62 |
2 |
timeStamp = DavConstants.modificationDateFormat.format(attachment.getDate()); |
63 |
2 |
getProperties().add( |
64 |
|
new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, timeStamp)); |
65 |
2 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETETAG, timeStamp)); |
66 |
2 |
getProperties().add( |
67 |
|
new DefaultDavProperty(DavPropertyName.GETCONTENTTYPE, getContext().getMimeType( |
68 |
|
attachment))); |
69 |
2 |
getProperties().add( |
70 |
|
new DefaultDavProperty(DavPropertyName.GETCONTENTLANGUAGE, attachment.getDoc() |
71 |
|
.getLanguage())); |
72 |
2 |
getProperties() |
73 |
|
.add( |
74 |
|
new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, attachment |
75 |
|
.getFilesize())); |
76 |
|
} |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
11 |
@Override... |
80 |
|
public boolean exists() |
81 |
|
{ |
82 |
11 |
return this.attachment != null; |
83 |
|
} |
84 |
|
|
|
|
| 75% |
Uncovered Elements: 5 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
85 |
1 |
@Override... |
86 |
|
public void spool(OutputContext outputContext) throws IOException |
87 |
|
{ |
88 |
|
|
89 |
1 |
if (!getContext().hasAccess("view", attachment.getDoc().getFullName())) { |
90 |
0 |
throw new IOException("Access rights violation."); |
91 |
|
} |
92 |
1 |
outputContext.setContentLanguage(attachment.getDoc().getLanguage()); |
93 |
1 |
outputContext.setContentLength(attachment.getFilesize()); |
94 |
1 |
outputContext.setContentType(getContext().getMimeType(attachment)); |
95 |
1 |
outputContext.setETag(DavConstants.modificationDateFormat.format(getModificationTime())); |
96 |
1 |
outputContext.setModificationTime(getModificationTime()); |
97 |
1 |
if (exists()) { |
98 |
1 |
OutputStream out = outputContext.getOutputStream(); |
99 |
1 |
if (null != out) { |
100 |
1 |
try { |
101 |
1 |
out.write(getContext().getContent(attachment)); |
102 |
1 |
out.flush(); |
103 |
|
} catch (DavException ex) { |
104 |
0 |
throw new IOException(ex.getMessage()); |
105 |
|
} |
106 |
|
} |
107 |
|
} |
108 |
|
} |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
110 |
0 |
@Override... |
111 |
|
public void move(DavResource destination) throws DavException |
112 |
|
{ |
113 |
0 |
getContext().checkAccess("edit", attachment.getDoc().getFullName()); |
114 |
0 |
if (destination instanceof DavAttachment) { |
115 |
0 |
DavAttachment dAttachment = (DavAttachment) destination; |
116 |
|
|
117 |
0 |
if (dAttachment.getCollection().equals(getCollection())) { |
118 |
0 |
getContext().moveAttachment(attachment, attachment.getDoc(), |
119 |
|
dAttachment.getDisplayName()); |
120 |
0 |
} else if (dAttachment.getCollection() instanceof DavPage) { |
121 |
0 |
XWikiDocument dDoc = ((DavPage) dAttachment.getCollection()).getDocument(); |
122 |
0 |
getContext().moveAttachment(attachment, dDoc, dAttachment.getDisplayName()); |
123 |
|
} else { |
124 |
0 |
throw new DavException(DavServletResponse.SC_BAD_REQUEST); |
125 |
|
} |
126 |
|
} else { |
127 |
0 |
throw new DavException(DavServletResponse.SC_BAD_REQUEST); |
128 |
|
} |
129 |
0 |
clearCache(); |
130 |
|
} |
131 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
132 |
2 |
@Override... |
133 |
|
public long getModificationTime() |
134 |
|
{ |
135 |
2 |
if (exists()) { |
136 |
2 |
return attachment.getDate().getTime(); |
137 |
|
} |
138 |
0 |
return IOUtil.UNDEFINED_TIME; |
139 |
|
} |
140 |
|
} |