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.http.Status;
16  import org.abstracthorizon.danube.webdav.ResourceAdapter;
17  import org.abstracthorizon.danube.webdav.lock.Lock;
18  import org.abstracthorizon.danube.webdav.lock.LockingMechanism;
19  import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
20  import org.abstracthorizon.danube.webdav.xml.dav.response.properties.ResponseProperty;
21  
22  import org.xml.sax.SAXException;
23  
24  /**
25   * This class models WebDAV's lockdiscovery request property
26   *
27   * @author Daniel Sendula
28   */
29  public class LockDiscovery extends RequestProperty {
30  
31      /**
32       * Constructory
33       * @param parent
34       */
35      public LockDiscovery(XMLParserHandler parent) {
36          super(parent);
37      }
38  
39      @Override
40      public Object end(Object current, String tag, String value) throws SAXException {
41          return super.end(current, tag, value);
42      }
43  
44      @Override
45      public String toString() {
46          return "LockDiscovery[]";
47      }
48  
49      /**
50       * Returns lock discovetry response property based on locking mechanism defined in the adapter
51       * @param adapter adapter
52       * @param resource resource
53       * @return lock discovery response property
54       */
55      public ResponseProperty processResponse(ResourceAdapter adapter, Object resource) {
56          LockingMechanism lockingMechanism = adapter.getLockingMechanism();
57          if (lockingMechanism != null) {
58              Lock[] locks = lockingMechanism.getLocks(resource);
59              org.abstracthorizon.danube.webdav.xml.dav.response.properties.LockDiscovery lockDiscovery = new org.abstracthorizon.danube.webdav.xml.dav.response.properties.LockDiscovery(Status.OK);
60              if ((locks != null) && (locks.length > 0)) {
61                  for (Lock l : locks) {
62                      lockDiscovery.getLocks().add(l);
63                  }
64              }
65              return lockDiscovery;
66          } else {
67              return super.processResponse(adapter, resource);
68          }
69      }
70  }