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;
14
15 import org.abstracthorizon.danube.webdav.lock.LockingMechanism;
16 import org.abstracthorizon.danube.webdav.util.NamespacesProvider;
17 import org.abstracthorizon.danube.webdav.xml.dav.request.properties.RequestProperty;
18 import org.abstracthorizon.danube.webdav.xml.dav.response.properties.ResponseProperty;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.OutputStream;
24
25 /**
26 * This is resource adapter interface that simplifies
27 * access to resource from WebDAV handler
28 *
29 * @author Daniel Sendula
30 */
31 public interface ResourceAdapter {
32
33 /**
34 * <p>
35 * Obtains resource object. It is supposed to be resource
36 * itself or an proxy as {@link File} is.
37 * </p>
38 * <p>
39 * If this method returns <code>null</code> then rest of the method
40 * relying on the resource must be able to deal with it since
41 * this class users might not care what the value is.
42 * </p>
43 *
44 * @param path path to the resource
45 * @return resource
46 */
47 Object findResource(String path);
48
49 /**
50 * Returns parent resource for given resource.
51 *
52 *
53 * @param resource existing resource
54 * @return parent resource or <code>null</code> if resource is already root of the hierarchy
55 */
56 Object findParentResource(Object resource);
57
58 /**
59 * Returns resource's length or -1 if unknown
60 * @param resource resource
61 * @return resource's length
62 */
63 long resourceLength(Object resource);
64
65 /**
66 * Returns when resource was last modified or -1 if unknown
67 * @param resource resource
68 * @return resource's last modified timestamp
69 */
70 long resourceLastModified(Object resource);
71
72 /**
73 * Returns when resource was created or -1 if unknown
74 * @param resource resource
75 * @return resource's created timestamp
76 */
77 long resourceCreated(Object resource);
78
79 /**
80 * Returns resource name
81 * @param resource resource name
82 * @return resource name
83 */
84 String getResourceName(Object resource);
85
86 /**
87 * Returns resource ETag (as specified in RFC-2616)
88 * @param resource resource
89 * @return etag
90 */
91 String getResourceETag(Object resource);
92
93 /**
94 * Returns <code>true</code> if resource exists
95 * @param resource resource
96 * @return <code>true</code> if resource exists
97 */
98 boolean exists(Object resource);
99
100 /**
101 * Returns <code>true</code> if resource is a collection
102 * @param resource resource
103 * @return <code>true</code> if resource is a collection
104 */
105 boolean isCollection(Object resource);
106
107 /**
108 * Deletes resource
109 *
110 * @param resource resource
111 *
112 * @throws IOException thrown if there was a problem deleting the resource
113 */
114 void delete(Object resource) throws IOException;
115
116 /**
117 * Makes a collection
118 *
119 * @param resource resource that identifies collection
120 * @throws IOException thrown if there was a problem while creating the collection
121 */
122 void makeCollection(Object resource) throws IOException;
123
124 /**
125 * Copies the resource to given destination.
126 *
127 * @param source source resource
128 * @param destination destination resource
129 * @param recursive will it perform deep copy or not
130 * @throws IOException thrown if there is a problem with copying.
131 */
132 void copy(Object source, Object destination, boolean recursive) throws IOException;
133
134 /**
135 * Noves the resource to given destination
136 * @param source source
137 * @param destination destination
138 * @throws IOException thrown if moving failed
139 */
140 void move(Object source, Object destination) throws IOException;
141
142 /**
143 * Returns collection elements for given resource
144 *
145 * @param resource resource
146 * @return collection elements or <code>null</code> if there is no elemetns or resource is not a colleciton
147 */
148 Object[] collectionElements(Object resource);
149
150 // TODO Refactor this
151 ResponseProperty[] getDefaultResponseProperties(Object resource);
152
153 // TODO Refactor this
154 RequestProperty[] getDefaultRequestProperties(Object resource);
155
156 /**
157 * Returns input stream of a resource
158 *
159 * @param resource resource
160 * @return input stream or <code>null</code> if not supported
161 *
162 * @throws IOException thrown if there is a problem returning the input stream
163 */
164 InputStream getInputStream(Object resource) throws IOException;
165
166 /**
167 * Returns input stream of a resource's range
168 *
169 * @param resource resource
170 * @param from from offset
171 * @param length amount of bytes to be trasmitted
172 * @return input stream or <code>null</code> if not supported
173 *
174 * @throws IOException thrown if there is a problem returning the input stream
175 */
176 InputStream getInpusStream(Object resource, long from, long length) throws IOException;
177
178 /**
179 * Returns output stream of a resource. It creates new resource or overwrites
180 * existing.
181 *
182 * @param resource resource
183 * @return output stream or <code>null</code> if not supported
184 *
185 * @throws IOException thrown if there is a problem creating new resource or replaying existing
186 */
187 OutputStream getOutputStream(Object resource) throws IOException;
188
189 /**
190 * Returns output stream of a resource. It creates new resource or overwrites
191 * existing. Given range specifies that only part of the resource is going to be supplied.
192 *
193 * @param resource resource
194 * @param from from offset
195 * @param length number of bytes to be trasmitted
196 * @return output stream or <code>null</code> if not supported
197 *
198 * @throws IOException thrown if there is a problem creating new resource or replaying existing
199 */
200 OutputStream getOutputStream(Object resource, long from, long length) throws IOException;
201
202 // TODO - is this right place for the provider?
203 /**
204 * Returns namespace privider
205 * @return namespace provider
206 */
207 NamespacesProvider getNamespacesProvider();
208
209 // TODO - re-design obtaining locking mechanism so it doesn't have to be supplied by the adapter
210 /**
211 * Returns locking mechanism
212 * @return locking mechanism
213 */
214 LockingMechanism getLockingMechanism();
215 }