View Javadoc

1   /*
2    * Copyright (c) 2006-2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
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   * This class models WebDAV's supportedlock response tag
27   *
28   * @author Daniel Sendula
29   */
30  public class SupportedLock extends ResponseProperty {
31  
32      /** Tag name */
33      public static final String TAG_NAME = "supportedlock";
34  
35      /** Lock tag entry tag name - "lockentry" */
36      public static final String LOCK_ENTRY_TAG_NAME = "lockentry";
37  
38      /** Array of supported scopes */
39      protected int[] scopes;
40  
41      /**
42       * Constructor
43       * @param status status
44       */
45      public SupportedLock(Status status) {
46          super(status);
47      }
48  
49      /**
50       * Constructor
51       * @param scopes an array of supported scopes
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       * Renders the tag
73       * @param writer writer
74       * @param provider namespace provider
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  }