KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > method > AbstractMultistatusResponseMethod


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractMultistatusResponseMethod.java,v 1.36 2004/08/03 09:37:48 ozeigermann Exp $
3  * $Revision: 1.36 $
4  * $Date: 2004/08/03 09:37:48 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.webdav.method;
25
26 import org.apache.slide.common.NamespaceAccessToken;
27 import org.apache.slide.common.NestedSlideException;
28 import org.apache.slide.common.SlideException;
29 import org.apache.slide.webdav.WebdavException;
30 import org.apache.slide.webdav.WebdavServletConfig;
31 import org.apache.slide.webdav.util.WebdavStatus;
32
33 /**
34  * Abstract class for methods which return a multistatus error report, like
35  * MOVE, DELETE, COPY, LOCK.
36  *
37  */

38 public abstract class AbstractMultistatusResponseMethod extends AbstractWebdavMethod {
39
40
41     // ----------------------------------------------------- Instance Variables
42

43
44     /**
45      * Id of the resosurce or collection which is to be copied.
46      */

47     protected String JavaDoc sourceUri;
48
49
50     /**
51      * Uri of the target.
52      */

53     protected String JavaDoc destinationUri;
54
55
56     /**
57      * Overwrite.
58      */

59     protected boolean overwrite;
60
61
62     // ----------------------------------------------------------- Constructors
63

64
65     /**
66      * Constructor.
67      *
68      * @param token the token for accessing the namespace
69      * @param config configuration of the WebDAV servlet
70      */

71     public AbstractMultistatusResponseMethod(NamespaceAccessToken token,
72                                              WebdavServletConfig config) {
73         super(token, config);
74     }
75
76
77     // ------------------------------------------------------ Protected Methods
78

79
80     /**
81      * Parse request.
82      *
83      * @exception WebdavException Does not happen
84      */

85     protected void parseRequest()
86         throws WebdavException {
87
88         sourceUri = requestUri;
89         if (sourceUri == null) {
90             sourceUri = "/";
91         }
92
93         destinationUri = requestHeaders.getDestination();
94
95         if (destinationUri == null) {
96             int statusCode = WebdavStatus.SC_BAD_REQUEST;
97             sendError( statusCode, getClass().getName()+".missingDestinationHeader" );
98             throw new WebdavException( statusCode );
99         }
100
101         destinationUri = parseUri(destinationUri);
102         overwrite = requestHeaders.getOverwrite(true);
103     }
104
105     /**
106      * Checks if a 207 should be generated. A 207 is generated when the request URI is a
107      * collection and exactely one nested exception is present and the request URI and
108      * the nested exception URI are identical.
109      *
110      * @return boolean return true, if a 207 response code should be generated
111      */

112
113     public static boolean generateMultiStatusResponse(boolean isCollection, NestedSlideException causeException, String JavaDoc resourceURI) {
114         boolean isMultiStatus = false;
115         if (isCollection) {
116             if (causeException.getExceptionsCount() > 1) {
117                 isMultiStatus = true;
118             }
119             else if (causeException.getExceptionsCount() == 1) {
120                 SlideException unpackedException = causeException.unpackSingleException();
121                 isMultiStatus = ! resourceURI.equals(MethodUtil.getURI(unpackedException));
122             }
123         }
124         return isMultiStatus;
125     }
126 }
127
128
Popular Tags