001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.war.webdav;
034:
035: import com.flexive.shared.FxSharedUtils;
036:
037: import javax.servlet.http.HttpServletRequest;
038: import javax.servlet.http.HttpServletResponse;
039: import java.io.IOException;
040: import java.io.OutputStream;
041: import java.util.Date;
042:
043: /**
044: *
045: */
046: public class FxDavDummyContext extends FxDavContext {
047:
048: private static FxDavDummyContext ddc = new FxDavDummyContext();
049:
050: public FxDavDummyContext getSingleton() {
051: return ddc;
052: }
053:
054: /**
055: * Gets the resource stored under the given name, or null if the resource does not exist.
056: * <p/>
057: * The returned resource may be a collection (directory) or file.<br>
058: * The path starts always from the root entry, but there is no starting '/' character.<br>
059: * A empty String denotes the root collection.
060: *
061: * @param name the name of the resource, eg 'myFolder1/myFolder2/demo.html'
062: * @return the resource
063: */
064: public FxDavEntry getResource(HttpServletRequest request,
065: String name) {
066: if (name.equals("")) {
067: return new FxDavCollection("", new Date(), new Date());
068: }
069: if (name.equals("adm")) {
070: return new FxDavCollection("adm", new Date(), new Date());
071: }
072: if (name.equals("test1.txt")) {
073: return new FxDavResource("test1.txt", new Date(),
074: new Date(), 120);
075: }
076: if (name.equals("test2.html")) {
077: return new FxDavResource("test2.html", new Date(),
078: new Date(), 120);
079: }
080: if (name.equals("adm/test1.txt")) {
081: return new FxDavResource("adm/test1.txt", new Date(),
082: new Date(), 120);
083: }
084: if (name.equals("adm/test2.html")) {
085: return new FxDavResource("adm/test2.html", new Date(),
086: new Date(), 120);
087: }
088:
089: return null;
090: }
091:
092: /**
093: * Returns all childs of a given resource.
094: * <p/>
095: * A empty String denotes the root collection.
096: *
097: * @param name the name of the resource, eg 'myFolder1/myFolder2', 'myFolder1/File1.txt', 'File.txt'
098: * @return all childs of a given resource.
099: */
100: public FxDavEntry[] getChildren(HttpServletRequest request,
101: String name) {
102: if (name.equals("")) {
103: return new FxDavEntry[] {
104: new FxDavCollection("adm", new Date(), new Date()),
105: new FxDavResource("test1.txt", new Date(),
106: new Date(), 133),
107: new FxDavResource("test2.html", new Date(),
108: new Date(), 120) };
109: } else if (name.equals("adm")) {
110: return new FxDavResource[] {
111: new FxDavResource("test1.txt", new Date(),
112: new Date(), 133),
113: new FxDavResource("test2.html", new Date(),
114: new Date(), 120) };
115: }
116: return null;
117: }
118:
119: /**
120: * Serves a resource to the webdav client.
121: *
122: * @param response the response
123: * @param name the name of the resource, eg 'myFolder1/File1.txt'
124: * @throws java.io.IOException if the resource could not be served
125: */
126: public void serviceResource(HttpServletRequest request,
127: HttpServletResponse response, String name)
128: throws IOException {
129: FxDavEntry entry = getResource(request, name);
130: if (entry == null || entry.isCollection()) {
131: response.sendError(FxWebDavStatus.SC_NOT_FOUND);
132: return;
133: }
134: FxDavResource resource = (FxDavResource) entry;
135: String send = "WebDav:" + name;
136: response.setContentLength(send.length());
137: response.setContentType("text/html;charset=UTF-8");
138: FxWebDavUtils.setModifiedAtDate(response, resource
139: .getLastmodified());
140: response.setStatus(HttpServletResponse.SC_OK);
141: OutputStream o = response.getOutputStream();
142: o.write(FxSharedUtils.getBytes(send));
143: o.flush();
144: o.close();
145: }
146:
147: /**
148: * Create a collection (Mkcol operation).
149: * <p/>
150: * MKCOL creates a new collection resource at the location specified by the Request-URI.
151: * If the resource identified by the Request-URI is non-null then the MKCOL MUST fail.
152: * During MKCOL processing, a server MUST make the Request-URI a member of its parent collection, unless the
153: * Request-URI is "/". If no such ancestor exists, the method MUST fail.<br>
154: * When the MKCOL operation creates a new collection resource, all ancestors MUST already exist, or the method MUST
155: * fail with a 409 (Conflict) status code. For example, if a request to create collection a/b/c/d/ is made, and
156: * neither a/b/ nor a/b/c/ exists, the request must fail.<br>
157: * <br><br>
158: * Possible return codes:
159: * 201 (Created) - The collection or structured resource was created in its entirety.<br>
160: * 403 (Forbidden) - This indicates at least one of two conditions: 1) the server does not allow the creation of
161: * collections at the given location in its namespace, or 2) the parent collection of the Request-URI exists but
162: * cannot accept members.<br>
163: * 405 (Method Not Allowed) - MKCOL can only be executed on a deleted/non-existent resource.<br>
164: * 409 (Conflict) - A collection cannot be made at the Request-URI until one or more intermediate collections have
165: * been created.<br>
166: * 507 (Insufficient Storage) - The resource does not have sufficient space to record the state of the resource
167: * after the execution of this method.<br>
168: * 423 (Locked) - The resource is locked
169: *
170: * @param name the absolute name of the collection, eg 'folder1/folder2/new_folder'
171: * @return the status code, WebdavStatus.SC_CREATED if the operation was successfull
172: */
173: public int createCollection(HttpServletRequest request, String name) {
174: return FxWebDavStatus.SC_NOT_IMPLEMENTED;
175: }
176:
177: /**
178: * Creates a resource.
179: *
180: * @param path the absolute path of the new resource, eg 'folder1/folder2/file.txt'
181: * @param request the request containing the data for the resource
182: * @return the status code, WebdavStatus.SC_CREATED if the operation was successfull
183: */
184: public int createResource(HttpServletRequest request, String path) {
185: return FxWebDavStatus.SC_NOT_IMPLEMENTED;
186:
187: }
188:
189: /**
190: * Moves a resource.
191: *
192: * @param src the absolute path of the source resource, eg 'folder1/folder2/file.txt'
193: * @param dest the absolute path of the destination resource, eg 'folder1/folder2/file_new.txt'
194: * @param request the request containing the data for the resource
195: */
196: public void moveResource(HttpServletRequest request, String src,
197: String dest) {
198: }
199:
200: /**
201: * Deletes a resource.
202: *
203: * @param path the absolute path of the new resource, eg 'folder1/folder2/file.txt'
204: * @param request the request containing the data for the resource
205: * @return the status code, FxWebDavStatus.SC_OK if the operation was successful
206: */
207: public int deleteResource(HttpServletRequest request, String path) {
208: return FxWebDavStatus.SC_NOT_IMPLEMENTED;
209: }
210:
211: /**
212: * Copies a resource.
213: *
214: * @param src the absolute path of the source resource, eg 'folder1/folder2/file.txt'
215: * @param dest the absolute path of the destination resource, eg 'folder1/folder2/file_new.txt'
216: * @param request the request containing the data for the resource
217: * @return the status code, FxWebDavStatus.SC_OK if the operation was successfull
218: */
219: public int copyResource(HttpServletRequest request, String src,
220: String dest) {
221: return FxWebDavStatus.SC_NOT_IMPLEMENTED;
222: }
223:
224: }
|