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;
14  
15  import org.abstracthorizon.danube.http.util.IOUtils;
16  
17  import java.io.InputStream;
18  import java.io.OutputStream;
19  
20  /**
21   * This class adds several methods to the bean (path) object. Adapter is, then,
22   * using these methods to obtain various attributes of the object.
23   *
24   * @author Daniel Sendula
25   */
26  public abstract class Delegate extends Bean {
27  
28      /** Parent object path - parent portion of the supplied path */
29      protected String objectPath;
30  
31      /**
32       * Constructor
33       * @param path path to the object
34       */
35      public Delegate(String path) {
36          super(path);
37          objectPath = IOUtils.parentPath(path);
38      }
39  
40      /**
41       * Returns resource length
42       * @param adapter adapter it is called from
43       * @return resource length or -1 if unknown.
44       */
45      public abstract int resourceLength(JavaWebDAVResourceAdapter adapter);
46  
47      /**
48       * Returns etag of the object. If not overriden then parent's object
49       * identity hash + class name is returned as a weak etag (see RFC-2616)
50       * @param adapter adapter
51       * @return an etag
52       */
53      public String getResourceETag(JavaWebDAVResourceAdapter adapter) {
54          Object object = adapter.findObjectImpl(objectPath);
55          if (object != null) {
56              String eTag = "W/\"" + Integer.toHexString(System.identityHashCode(object)) + "-" + getClass().getName() + "\"";
57              return eTag;
58          } else {
59              String path = getPath();
60              return "W/\"" + path + "-NULL\"";
61          }
62      }
63  
64      /**
65       * Returns input stream of the object/field's value. This implementation returns <code>null</code>
66       * @param adapter adapter
67       * @return input stream or <code>null</code>
68       */
69      public InputStream getInputStream(JavaWebDAVResourceAdapter adapter) {
70          return null;
71      }
72  
73      /**
74       * Returns input stream of a given range of the object/field's value. This implementation returns <code>null</code>
75       * @param adapter adapter
76       * @param from offset
77       * @param length length
78       * @return input stream or <code>null</code>
79       */
80      public InputStream getInputStream(JavaWebDAVResourceAdapter adapter, long from, long length) {
81          InputStream is = getInputStream(adapter);
82          if (is == null) {
83              return null;
84          }
85          return null;
86      }
87  
88      /**
89       * Returns output stream of the object/field's value. It is used to write into the object/field.
90       * This implementation returns <code>null</code>
91       * @param adapter adapter
92       * @return output stream or <code>null</code>
93       */
94      public OutputStream getOutputStream(JavaWebDAVResourceAdapter adapter) {
95          return null;
96      }
97  
98      /**
99       * Returns output stream of the object/field's value. It is used to write into the object/field.
100      * This implementation returns <code>null</code>
101      * @param adapter adapter
102      * @param from offset
103      * @param length length
104      * @return output stream or <code>null</code>
105      */
106     public OutputStream getOutputStream(JavaWebDAVResourceAdapter adapter, long from, long length) {
107         OutputStream out = getOutputStream(adapter);
108         if (out == null) {
109             return null;
110         }
111         return null;
112     }
113 
114     /**
115      * Returns content type. This implementation returns &quot;unknown/unknown&quot;.
116      * @param adapter adapter
117      * @return content type
118      */
119     public String getContentType(JavaWebDAVResourceAdapter adapter) {
120         return "unknown/unknown";
121     }
122 
123 }