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.java.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  /**
20   *
21   * This class obtains content length from given resource
22   *
23   * @author Daniel Sendula
24   *
25   */
26  public class GetContentLength extends org.abstracthorizon.danube.webdav.xml.dav.request.properties.GetContentLength {
27  
28      /**
29       * Constructor
30       * @param parent
31       */
32      public GetContentLength(XMLParserHandler parent) {
33          super(parent);
34      }
35  
36      /**
37       * Sets the property
38       * @param webDAVAdapter DAV adapter
39       * @param resource resource
40       * @return response property
41       */
42      public ResponseProperty processSetProperty(ResourceAdapter webDAVAdapter, Object resource) {
43          long newLength = getContentLength();
44          if (newLength >= 0) {
45  //            File file = (File)resource;
46  //            try {
47  //                RandomAccessFile raf = new RandomAccessFile(file, "rw");
48  //                long oldLength = raf.length();
49  //                if (newLength != oldLength) {
50  //                    raf.setLength(newLength);
51  //                    File f = new File(file.getParentFile(), file.getName());
52  //                    if (newLength == f.length()) {
53  //                        return processResponse(webDAVAdapter, file);
54  //                    }
55  //                }
56  //            } catch (IOException e) {
57  //
58  //            }
59  //            return constructResponse(Status.FORBIDDEN);
60              return super.processSetProperty(webDAVAdapter, resource);
61          } else {
62              return super.processSetProperty(webDAVAdapter, resource);
63          }
64      }
65  }
66