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.lock.Lock;
17 import org.abstracthorizon.danube.webdav.lock.LockingMechanism;
18 import org.abstracthorizon.danube.webdav.util.NamespacesProvider;
19 import org.abstracthorizon.danube.webdav.xml.common.XMLUtils;
20 import org.abstracthorizon.danube.webdav.xml.dav.DAVNamespace;
21 import org.abstracthorizon.danube.webdav.xml.dav.HRef;
22 import org.abstracthorizon.danube.webdav.xml.dav.response.Depth;
23 import org.abstracthorizon.danube.webdav.xml.dav.response.LockScope;
24 import org.abstracthorizon.danube.webdav.xml.dav.response.LockType;
25 import org.abstracthorizon.danube.webdav.xml.dav.response.Owner;
26
27 import java.io.PrintWriter;
28 import java.util.ArrayList;
29 import java.util.List;
30
31
32
33
34
35
36 public class LockDiscovery extends ResponseProperty {
37
38
39 public static final String TAG_NAME = "lockdiscovery";
40
41
42 public static final String ACTIVE_LOCK_TAG_NAME = "activelock";
43
44
45 public static final String TIMEOUT_TAG_NAME = "timeout";
46
47
48 public static final String LOCK_TOKEN_TAG_NAME = "locktoken";
49
50
51 protected List<Lock> locks;
52
53
54
55
56
57 public LockDiscovery(Status status) {
58 super(status);
59 }
60
61 @Override
62 public String toString() {
63 return "LockDiscovery[]";
64 }
65
66
67
68
69
70 public List<Lock> getLocks() {
71 if (locks == null) {
72 locks = new ArrayList<Lock>();
73 }
74 return locks;
75 }
76
77
78
79
80
81
82 public void render(PrintWriter writer, NamespacesProvider provider) {
83 if (locks == null) {
84 writer.println(XMLUtils.createEmptyTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
85 } else {
86 writer.println(XMLUtils.createStartTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
87 for (Lock lock : locks) {
88 writer.println(XMLUtils.createStartTag(provider, DAVNamespace.DAV_NAMESPACE_URL, ACTIVE_LOCK_TAG_NAME));
89 LockType.WRITE.render(writer, provider);
90 if (lock.getScope() == LockingMechanism.SCOPE_EXCLUSIVE) {
91 LockScope.EXCLUSIVE.render(writer, provider);
92 } else {
93 LockScope.SHARED.render(writer, provider);
94 }
95 Depth.DEPTHS[lock.getDepth()].render(writer, provider);
96 if (lock.getOwner() != null) {
97 Owner owner = new Owner(lock.getOwner());
98 owner.render(writer, provider);
99 }
100 if (lock.getTimeout() != null) {
101 writer.println(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TIMEOUT_TAG_NAME, lock.getTimeout().asString()));
102 }
103 if (lock.getToken() != null) {
104 HRef href = new HRef(lock.getToken().toString());
105 writer.println(XMLUtils.createStartTag(provider, DAVNamespace.DAV_NAMESPACE_URL, LOCK_TOKEN_TAG_NAME));
106 href.render(writer, provider);
107 writer.println(XMLUtils.createEndTag(provider, DAVNamespace.DAV_NAMESPACE_URL, LOCK_TOKEN_TAG_NAME));
108 }
109
110 writer.println(XMLUtils.createEndTag(provider, DAVNamespace.DAV_NAMESPACE_URL, ACTIVE_LOCK_TAG_NAME));
111 }
112 writer.println(XMLUtils.createEndTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
113 }
114 }
115 }