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.LockingMechanism;
17 import org.abstracthorizon.danube.webdav.util.NamespacesProvider;
18 import org.abstracthorizon.danube.webdav.xml.common.XMLUtils;
19 import org.abstracthorizon.danube.webdav.xml.dav.DAVNamespace;
20 import org.abstracthorizon.danube.webdav.xml.dav.response.LockScope;
21 import org.abstracthorizon.danube.webdav.xml.dav.response.LockType;
22
23 import java.io.PrintWriter;
24
25
26
27
28
29
30 public class SupportedLock extends ResponseProperty {
31
32
33 public static final String TAG_NAME = "supportedlock";
34
35
36 public static final String LOCK_ENTRY_TAG_NAME = "lockentry";
37
38
39 protected int[] scopes;
40
41
42
43
44
45 public SupportedLock(Status status) {
46 super(status);
47 }
48
49
50
51
52
53 public SupportedLock(int[] scopes) {
54 this.scopes = scopes;
55 }
56
57 @Override
58 public String toString() {
59 StringBuffer res = new StringBuffer("SupportedLock[");
60 for (int scope : scopes) {
61 if (scope == LockingMechanism.SCOPE_EXCLUSIVE) {
62 res.append("LockEntry[exclusive,write]");
63 } else if (scope == LockingMechanism.SCOPE_SHARED) {
64 res.append("LockEntry[shared,write]");
65 }
66 }
67 res.append(']');
68 return res.toString();
69 }
70
71
72
73
74
75
76 public void render(PrintWriter writer, NamespacesProvider provider) {
77 writer.println(XMLUtils.createStartTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
78 for (int scope : scopes) {
79 if (scope == LockingMechanism.SCOPE_EXCLUSIVE) {
80 writer.println(XMLUtils.createStartTag(provider, DAVNamespace.DAV_NAMESPACE_URL, LOCK_ENTRY_TAG_NAME));
81 LockScope.EXCLUSIVE.render(writer, provider);
82 LockType.WRITE.render(writer, provider);
83 writer.println(XMLUtils.createEndTag(provider, DAVNamespace.DAV_NAMESPACE_URL, LOCK_ENTRY_TAG_NAME));
84 } else if (scope == LockingMechanism.SCOPE_SHARED) {
85 writer.println(XMLUtils.createStartTag(provider, DAVNamespace.DAV_NAMESPACE_URL, LOCK_ENTRY_TAG_NAME));
86 LockScope.SHARED.render(writer, provider);
87 LockType.WRITE.render(writer, provider);
88 writer.println(XMLUtils.createEndTag(provider, DAVNamespace.DAV_NAMESPACE_URL, LOCK_ENTRY_TAG_NAME));
89 }
90 }
91 writer.println(XMLUtils.createEndTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
92 }
93
94 }