| 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 |
|
import java.util.ArrayList; |
| 25 |
|
import java.util.Date; |
| 26 |
|
import java.util.List; |
| 27 |
|
|
| 28 |
|
import org.apache.jackrabbit.server.io.IOUtil; |
| 29 |
|
import org.apache.jackrabbit.webdav.DavConstants; |
| 30 |
|
import org.apache.jackrabbit.webdav.DavException; |
| 31 |
|
import org.apache.jackrabbit.webdav.DavResource; |
| 32 |
|
import org.apache.jackrabbit.webdav.DavResourceIterator; |
| 33 |
|
import org.apache.jackrabbit.webdav.DavResourceIteratorImpl; |
| 34 |
|
import org.apache.jackrabbit.webdav.DavServletResponse; |
| 35 |
|
import org.apache.jackrabbit.webdav.io.InputContext; |
| 36 |
|
import org.apache.jackrabbit.webdav.io.OutputContext; |
| 37 |
|
import org.apache.jackrabbit.webdav.property.DavPropertyName; |
| 38 |
|
import org.apache.jackrabbit.webdav.property.DefaultDavProperty; |
| 39 |
|
|
| 40 |
|
import com.xpn.xwiki.plugin.webdav.resources.XWikiDavResource; |
| 41 |
|
import com.xpn.xwiki.plugin.webdav.resources.partial.AbstractDavResource; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@version |
| 47 |
|
|
| |
|
| 85.6% |
Uncovered Elements: 13 (90) |
Complexity: 28 |
Complexity Density: 0.5 |
|
| 48 |
|
public class DavTempFile extends AbstractDavResource |
| 49 |
|
{ |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
private boolean isCollection; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
private byte[] data; |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
private boolean created; |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
private Date timeOfCreation; |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
private Date timeOfLastModification; |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 80 |
36 |
public DavTempFile()... |
| 81 |
|
{ |
| 82 |
36 |
timeOfCreation = new Date(IOUtil.UNDEFINED_TIME); |
| 83 |
36 |
timeOfLastModification = (Date) timeOfCreation.clone(); |
| 84 |
|
} |
| 85 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 86 |
62 |
@Override... |
| 87 |
|
public void init(XWikiDavResource parent, String name, String relativePath) throws DavException |
| 88 |
|
{ |
| 89 |
62 |
super.init(parent, name, relativePath); |
| 90 |
62 |
String strTimeOfCreation = DavConstants.creationDateFormat.format(timeOfCreation); |
| 91 |
62 |
getProperties().add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, strTimeOfCreation)); |
| 92 |
62 |
String strTimeOfModification = DavConstants.modificationDateFormat.format(timeOfLastModification); |
| 93 |
62 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, strTimeOfModification)); |
| 94 |
62 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETETAG, strTimeOfModification)); |
| 95 |
62 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETCONTENTLANGUAGE, "en")); |
| 96 |
62 |
String contentType = isCollection() ? "text/directory" : "application/octet-stream"; |
| 97 |
62 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETCONTENTTYPE, contentType)); |
| 98 |
62 |
int contentLength = (data != null) ? data.length : 0; |
| 99 |
62 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, contentLength)); |
| 100 |
|
} |
| 101 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 102 |
10 |
@Override... |
| 103 |
|
public XWikiDavResource decode(String[] tokens, int next) throws DavException |
| 104 |
|
{ |
| 105 |
10 |
return super.decode(tokens, next); |
| 106 |
|
} |
| 107 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 108 |
42 |
@Override... |
| 109 |
|
public boolean exists() |
| 110 |
|
{ |
| 111 |
42 |
return parentResource.getVirtualMembers().contains(this); |
| 112 |
|
} |
| 113 |
|
|
| |
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 6 |
Complexity Density: 0.6 |
|
| 114 |
4 |
@Override... |
| 115 |
|
public void spool(OutputContext outputContext) throws IOException |
| 116 |
|
{ |
| 117 |
4 |
outputContext.setContentLanguage("en"); |
| 118 |
4 |
outputContext.setContentLength(data != null ? data.length : 0); |
| 119 |
4 |
outputContext.setContentType(isCollection() ? "text/directory" : "application/octet-stream"); |
| 120 |
4 |
outputContext.setETag(DavConstants.modificationDateFormat.format(getModificationTime())); |
| 121 |
4 |
outputContext.setModificationTime(getModificationTime()); |
| 122 |
4 |
if (exists() && !isCollection()) { |
| 123 |
4 |
OutputStream out = outputContext.getOutputStream(); |
| 124 |
4 |
if (out != null) { |
| 125 |
4 |
out.write(this.data); |
| 126 |
4 |
out.flush(); |
| 127 |
|
} |
| 128 |
|
} |
| 129 |
|
} |
| 130 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 131 |
0 |
@Override... |
| 132 |
|
public DavResourceIterator getMembers() |
| 133 |
|
{ |
| 134 |
0 |
List<DavResource> children = new ArrayList<DavResource>(); |
| 135 |
0 |
children.addAll(getVirtualMembers()); |
| 136 |
0 |
return new DavResourceIteratorImpl(children); |
| 137 |
|
} |
| 138 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 139 |
2 |
@Override... |
| 140 |
|
public void addMember(DavResource resource, InputContext inputContext) throws DavException |
| 141 |
|
{ |
| 142 |
2 |
if (resource instanceof DavTempFile) { |
| 143 |
2 |
addVirtualMember(resource, inputContext); |
| 144 |
|
} else { |
| 145 |
0 |
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR); |
| 146 |
|
} |
| 147 |
|
} |
| 148 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 149 |
2 |
@Override... |
| 150 |
|
public void removeMember(DavResource resource) throws DavException |
| 151 |
|
{ |
| 152 |
2 |
if (resource instanceof DavTempFile) { |
| 153 |
2 |
removeVirtualMember(resource); |
| 154 |
|
} else { |
| 155 |
0 |
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR); |
| 156 |
|
} |
| 157 |
|
} |
| 158 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 5 |
Complexity Density: 0.71 |
|
| 159 |
4 |
@Override... |
| 160 |
|
public void move(DavResource destination) throws DavException |
| 161 |
|
{ |
| 162 |
4 |
if (destination instanceof DavTempFile && destination.getCollection().equals(getCollection()) |
| 163 |
|
&& !destination.isCollection() && !isCollection()) { |
| 164 |
|
|
| 165 |
2 |
DavTempFile destTempFile = (DavTempFile) destination; |
| 166 |
2 |
parentResource.getVirtualMembers().remove(this); |
| 167 |
2 |
parentResource.getVirtualMembers().add(destTempFile); |
| 168 |
2 |
destTempFile.update(this.data.clone(), this.timeOfLastModification); |
| 169 |
|
} else { |
| 170 |
2 |
throw new DavException(DavServletResponse.SC_FORBIDDEN); |
| 171 |
|
} |
| 172 |
2 |
clearCache(); |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
@param |
| 177 |
|
@param |
| 178 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 179 |
4 |
public void update(byte[] data, Date modificationTime)... |
| 180 |
|
{ |
| 181 |
4 |
this.data = data.clone(); |
| 182 |
4 |
setModified(modificationTime); |
| 183 |
4 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, this.data.length)); |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
|
@param |
| 190 |
|
|
| |
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 191 |
8 |
public void setModified(Date modificationTime)... |
| 192 |
|
{ |
| 193 |
8 |
if (!created) { |
| 194 |
8 |
timeOfCreation = (Date) modificationTime.clone(); |
| 195 |
8 |
String strTimeOfCreation = DavConstants.creationDateFormat.format(timeOfCreation); |
| 196 |
8 |
getProperties().add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, strTimeOfCreation)); |
| 197 |
8 |
created = true; |
| 198 |
|
} |
| 199 |
8 |
timeOfLastModification = (Date) modificationTime.clone(); |
| 200 |
8 |
String strTimeOfModification = DavConstants.modificationDateFormat.format(timeOfLastModification); |
| 201 |
8 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, strTimeOfModification)); |
| 202 |
8 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETETAG, String.valueOf(timeOfLastModification))); |
| 203 |
|
} |
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 208 |
5 |
public void setCollection()... |
| 209 |
|
{ |
| 210 |
5 |
this.isCollection = true; |
| 211 |
|
} |
| 212 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 213 |
151 |
@Override... |
| 214 |
|
public boolean isCollection() |
| 215 |
|
{ |
| 216 |
151 |
return isCollection; |
| 217 |
|
} |
| 218 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 219 |
8 |
@Override... |
| 220 |
|
public long getModificationTime() |
| 221 |
|
{ |
| 222 |
8 |
return timeOfLastModification.getTime(); |
| 223 |
|
} |
| 224 |
|
} |