KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > webdav > OptionsMethod


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.webdav;
18
19 import org.alfresco.service.cmr.model.FileInfo;
20 import org.alfresco.service.cmr.model.FileNotFoundException;
21
22 /**
23  * Implements the WebDAV OPTIONS method
24  *
25  * @author Gavin Cornwell
26  */

27 public class OptionsMethod extends WebDAVMethod
28 {
29     private static final String JavaDoc DAV_HEADER = "DAV";
30     private static final String JavaDoc DAV_HEADER_CONTENT = "1,2";
31     private static final String JavaDoc ALLOW_HEADER = "Allow";
32     private static final String JavaDoc MS_HEADER = "MS-Author-Via";
33
34     private static final String JavaDoc FILE_METHODS = "OPTIONS, GET, HEAD, POST, DELETE, PROPFIND, COPY, MOVE, LOCK, UNLOCK";
35     private static final String JavaDoc COLLECTION_METHODS = FILE_METHODS + ", PUT";
36
37     /**
38      * Default constructor
39      */

40     public OptionsMethod()
41     {
42     }
43
44     /**
45      * Parse the request header fields
46      *
47      * @exception WebDAVServerException
48      */

49     protected void parseRequestHeaders() throws WebDAVServerException
50     {
51         // Nothing to do in this method
52
}
53
54     /**
55      * Parse the request main body
56      *
57      * @exception WebDAVServerException
58      */

59     protected void parseRequestBody() throws WebDAVServerException
60     {
61         // Nothing to do in this method
62
}
63
64     /**
65      * Perform the main request processing
66      *
67      * @exception WebDAVServerException
68      */

69     protected void executeImpl() throws WebDAVServerException
70     {
71         boolean isFolder;
72         try
73         {
74             FileInfo fileInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), getPath(), getServletPath());
75             isFolder = fileInfo.isFolder();
76         }
77         catch (FileNotFoundException e)
78         {
79             // Do nothing; just default to a folder
80
isFolder = true;
81         }
82         // Add the header to advertise the level of support the server has
83
m_response.addHeader(DAV_HEADER, DAV_HEADER_CONTENT);
84
85         // Add the proprietary Microsoft header to make Microsoft clients behave
86
m_response.addHeader(MS_HEADER, DAV_HEADER);
87
88         // Add the header to show what methods are allowed
89
m_response.addHeader(ALLOW_HEADER, isFolder ? COLLECTION_METHODS : FILE_METHODS);
90     }
91 }
92
Popular Tags