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.properties;
14  
15  import org.abstracthorizon.danube.webdav.ResourceAdapter;
16  import org.abstracthorizon.danube.webdav.lock.LockingMechanism;
17  import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
18  import org.abstracthorizon.danube.webdav.xml.dav.DAVFactory;
19  import org.abstracthorizon.danube.webdav.xml.dav.request.LockEntry;
20  import org.abstracthorizon.danube.webdav.xml.dav.response.properties.ResponseProperty;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.xml.sax.Attributes;
26  import org.xml.sax.SAXException;
27  
28  /**
29   * This class models WebDAV's supportedlock request property
30   *
31   * @author Daniel Sendula
32   */
33  public class SupportedLock extends RequestProperty {
34  
35      /** Factory */
36      protected DAVFactory davFactory;
37  
38      /** List of lock entries */
39      protected List<LockEntry> lockEntries = new ArrayList<LockEntry>();
40  
41      /**
42       * Constructor
43       * @param parent parnet parser handler
44       * @param factory factory
45       */
46      public SupportedLock(XMLParserHandler parent, DAVFactory factory) {
47          super(parent);
48          this.davFactory = factory;
49      }
50  
51      @Override
52      public Object start(Object current, String tag, Attributes attributes) throws SAXException {
53          if ("lockentry".equals(tag)) {
54              LockEntry lockEntry = davFactory.newLockEntry(this);
55              lockEntries.add(lockEntry);
56              return lockEntry;
57          }  else {
58              return super.start(current, tag, attributes);
59          }
60      }
61  
62      /**
63       * Returns {@link org.abstracthorizon.danube.webdav.xml.dav.response.properties.SupportedLock}
64       * @param adapter adapter
65       * @param resource resource
66       * @return {@link org.abstracthorizon.danube.webdav.xml.dav.response.properties.SupportedLock}
67       */
68      public ResponseProperty processResponse(ResourceAdapter adapter, Object resource) {
69          LockingMechanism lockingMechanism = adapter.getLockingMechanism();
70          int[] scopes = lockingMechanism.getSupportedLockScopes(resource);
71          return new org.abstracthorizon.danube.webdav.xml.dav.response.properties.SupportedLock(scopes);
72      }
73  
74      @Override
75      public String toString() {
76          StringBuffer res = new StringBuffer("SupportedLock[");
77          for (LockEntry lockEntry : lockEntries) {
78              res.append(lockEntry.toString());
79          }
80          res.append(']');
81          return res.toString();
82      }
83  }