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.request;
14  
15  import org.abstracthorizon.danube.webdav.lock.LockingMechanism;
16  import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
17  
18  import org.xml.sax.Attributes;
19  import org.xml.sax.SAXException;
20  
21  /**
22   * This class models WebDAV's lockscope tag
23   *
24   * @author Daniel Sendula
25   */
26  public class LockScope extends AbstractSimpleXMLHandler {
27  
28      /** Is exclusive scope or shared */
29      protected boolean exclusive = false;
30  
31      /**
32       * Constructor
33       * @param parent parent parser handler
34       */
35      public LockScope(XMLParserHandler parent) {
36          super(parent);
37      }
38  
39      @Override
40      public Object start(Object current, String tag, Attributes attributes) throws SAXException {
41          if ("exclusive".equals(tag)) {
42              exclusive = true;
43              return this;
44          } else if ("shared".equals(tag)) {
45              exclusive = false;
46              return this;
47          } else {
48              return super.start(current, tag, attributes);
49          }
50      }
51  
52      @Override
53      public Object end(Object current, String tag, String value) throws SAXException {
54          if ("exclusive".equals(tag)) {
55              exclusive = true;
56              return this;
57          } else if ("shared".equals(tag)) {
58              exclusive = false;
59              return this;
60          } else {
61              return super.end(current, tag, value);
62          }
63      }
64  
65      /**
66       * Returns scope
67       * @return scope
68       * @see LockingMechanism#SCOPE_EXCLUSIVE
69       * @see LockingMechanism#SCOPE_SHARED
70       */
71      public int getScope() {
72          if (exclusive) {
73              return LockingMechanism.SCOPE_EXCLUSIVE;
74          } else {
75              return LockingMechanism.SCOPE_SHARED;
76          }
77      }
78  
79      @Override
80      public String toString() {
81          return "LockScope[exclusive=" + exclusive + "]";
82      }
83  
84  }