1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.danube.webdav.spring.properties;
14
15 import org.abstracthorizon.danube.http.Status;
16 import org.abstracthorizon.danube.webdav.ResourceAdapter;
17 import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
18 import org.abstracthorizon.danube.webdav.xml.dav.response.properties.ResponseProperty;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.io.RandomAccessFile;
23
24 import org.springframework.core.io.Resource;
25
26
27
28
29
30
31 public class GetContentLength extends org.abstracthorizon.danube.webdav.xml.dav.request.properties.GetContentLength {
32
33
34
35
36
37 public GetContentLength(XMLParserHandler parent) {
38 super(parent);
39 }
40
41
42
43
44
45
46
47 public ResponseProperty processSetProperty(ResourceAdapter adapter, Object resource) {
48 long newLength = getContentLength();
49 if (newLength >= 0) {
50 Resource r = (Resource)resource;
51 try {
52 File file = r.getFile();
53 RandomAccessFile raf = new RandomAccessFile(file, "rw");
54 long oldLength = raf.length();
55 if (newLength != oldLength) {
56 raf.setLength(newLength);
57 File f = new File(file.getParentFile(), file.getName());
58 if (newLength == f.length()) {
59 return processResponse(adapter, file);
60 }
61 }
62 } catch (IOException e) {
63
64 }
65 return constructResponse(Status.FORBIDDEN);
66 } else {
67 return super.processSetProperty(adapter, resource);
68 }
69 }
70 }
71