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;
14  
15  import org.abstracthorizon.danube.webdav.util.NamespacesProvider;
16  import org.abstracthorizon.danube.webdav.xml.XMLRenderer;
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  
22  /**
23   * This class models WebDAV's lockscope response tag
24   *
25   * @author Daniel Sendula
26   */
27  public class LockScope implements XMLRenderer {
28  
29      /** Tag name */
30      public static final String TAG_NAME = "lockscope";
31  
32      /** Exclusive tag singleton */
33      public static final LockScope EXCLUSIVE = new LockScope(true);
34  
35      /** Shared tag singleton */
36      public static final LockScope SHARED = new LockScope(false);
37  
38      /** Exclusive flag */
39      protected boolean exclusive = false;
40  
41      /**
42       * Constructor
43       * @param exclusive exclusive
44       */
45      public LockScope(boolean exclusive) {
46          this.exclusive = exclusive;
47      }
48  
49      @Override
50      public String toString() {
51          if (exclusive) {
52              return "LockScope[exclusive]";
53          } else {
54              return "LockScope[shared]";
55          }
56      }
57  
58      /**
59       * Renders the tag
60       * @param writer writer
61       * @param provider namespace provider
62       */
63      public void render(PrintWriter writer, NamespacesProvider provider) {
64          writer.print(XMLUtils.createStartTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
65          if (exclusive) {
66              writer.print(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, "exclusive", null));
67          } else {
68              writer.print(XMLUtils.createTag(provider, DAVNamespace.DAV_NAMESPACE_URL, "shared", null));
69          }
70          writer.println(XMLUtils.createEndTag(provider, DAVNamespace.DAV_NAMESPACE_URL, TAG_NAME));
71       }
72  
73  }