1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.danube.webdav.xml.dav.response.properties;
14
15 import org.abstracthorizon.danube.http.Status;
16 import org.abstracthorizon.danube.webdav.util.NamespacesProvider;
17 import org.abstracthorizon.danube.webdav.xml.common.XMLUtils;
18 import org.abstracthorizon.danube.webdav.xml.dav.DAVNamespace;
19
20 import java.io.PrintWriter;
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23
24
25
26
27
28
29 public class CreationDate extends ResponseProperty {
30
31
32 public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ssZ");
33
34
35 protected long modified = -1;
36
37
38 protected String cachedDate;
39
40
41 public static final String TAG_NAME = "creationdate";
42
43
44 protected String dateString;
45
46
47
48
49
50 public CreationDate(Status status) {
51 super(status);
52 }
53
54
55
56
57
58 public CreationDate(long modified) {
59 this.modified = modified;
60 }
61
62
63
64
65
66 public long getLastModified() {
67 return modified;
68 }
69
70
71
72
73
74 public String asString() {
75 if (cachedDate == null) {
76 if (modified != -1) {
77 cachedDate = DATE_FORMAT.format(new Date(modified));
78 }
79 }
80 return cachedDate;
81 }
82
83 @Override
84 public String toString() {
85 return "CreationDate[" + asString() + "]";
86 }
87
88
89
90
91
92
93 public void render(PrintWriter writer, NamespacesProvider provider) {
94 if ((dateString == null) || (dateString.length() == 0)) {
95 writer.println(XMLUtils.createEmptyTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
96 } else {
97 writer.println(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME, asString()));
98 }
99 }
100 }