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.HTTPServerConnectionHandler;
16  import org.abstracthorizon.danube.webdav.ResourceAdapter;
17  import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
18  import org.abstracthorizon.danube.webdav.xml.dav.response.properties.ResponseProperty;
19  
20  import java.text.ParseException;
21  import java.util.Date;
22  
23  import org.xml.sax.SAXException;
24  
25  /**
26   * This class models WebDAV's getlastmodified request property tag
27   *
28   * @author Daniel Sendula
29   */
30  public class GetLastModified extends RequestProperty {
31  
32      /** Last modified timestamp */
33      protected long lastModified;
34  
35      /**
36       * Constructor
37       * @param parent parent parser handler
38       */
39      public GetLastModified(XMLParserHandler parent) {
40          super(parent);
41      }
42  
43      @Override
44      public Object end(Object current, String tag, String value) throws SAXException {
45          if ((value != null) && (value.length() >0)) {
46              try {
47                  lastModified = HTTPServerConnectionHandler.DATE_FORMAT.parse(value).getTime();
48              } catch (ParseException e) {
49                  // TODO Auto-generated catch block
50                  e.printStackTrace();
51              }
52          }
53          return super.end(current, tag, value);
54      }
55  
56      /**
57       * This class returns last modified timestamp
58       * @return last modified timestamp
59       */
60      public long getLastModified() {
61          return lastModified;
62      }
63  
64      /**
65       * Returns {@link org.abstracthorizon.danube.webdav.xml.dav.response.properties.GetLastModified}
66       * @param adapter adapter
67       * @param resource resource
68       * @return {@link org.abstracthorizon.danube.webdav.xml.dav.response.properties.GetLastModified}
69       */
70      public ResponseProperty processResponse(ResourceAdapter adapter, Object resource) {
71          return new org.abstracthorizon.danube.webdav.xml.dav.response.properties.GetLastModified(adapter.resourceLastModified(resource));
72      }
73  
74      /**
75       * Retunrs timestamp as string using {@HTTPServerConnectionHandler~DATE_FORMAT} format.
76       * @return timestamp as string
77       */
78      public String asString() {
79          return HTTPServerConnectionHandler.DATE_FORMAT.format(new Date(lastModified));
80      }
81  
82      @Override
83      public String toString() {
84          if (lastModified != 0) {
85              return "GetLastModified[" + asString() + "]";
86          } else {
87              return "GetLastModified[]";
88          }
89      }
90  }