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.xml.XMLParserHandler;
17  import org.abstracthorizon.danube.webdav.xml.dav.response.properties.ResponseProperty;
18  
19  import org.xml.sax.SAXException;
20  
21  /**
22   * This class models WebDAV's getcontentlength tag
23   *
24   * @author Daniel Sendula
25   */
26  public class GetContentLength extends RequestProperty {
27  
28      /** Content length */
29      protected long contentLength = -1;
30  
31      /**
32       * Constructor
33       * @param parent parent parser handler
34       */
35      public GetContentLength(XMLParserHandler parent) {
36          super(parent);
37      }
38  
39      @Override
40      public Object end(Object current, String tag, String value) throws SAXException {
41          try {
42              contentLength = Long.parseLong(value);
43          } catch (NumberFormatException e) {
44              contentLength = -1;
45          }
46          return super.end(current, tag, value);
47      }
48  
49      /**
50       * Returns content length
51       * @return content length
52       */
53      public long getContentLength() {
54          return contentLength;
55      }
56  
57      /**
58       * Returns {@link org.abstracthorizon.danube.webdav.xml.dav.response.properties.GetContentLength}
59       * @param adapter adapter
60       * @param resource resource
61       * @return {@link org.abstracthorizon.danube.webdav.xml.dav.response.properties.GetContentLength}
62       */
63      public ResponseProperty processResponse(ResourceAdapter adapter, Object resource) {
64          return new org.abstracthorizon.danube.webdav.xml.dav.response.properties.GetContentLength(adapter.resourceLength(resource));
65      }
66  
67      @Override
68      public String toString() {
69          return "GetContentLength[" + getContentLength() + "]";
70      }
71  }