KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > webdav > WebDAVStatus


1 package com.ibm.webdav;
2
3 /*
4  * (C) Copyright IBM Corp. 2000 All rights reserved.
5  *
6  * The program is provided "AS IS" without any warranty express or
7  * implied, including the warranty of non-infringement and the implied
8  * warranties of merchantibility and fitness for a particular purpose.
9  * IBM will not be liable for any damages suffered by you as a result
10  * of using the Program. In no event will IBM be liable for any
11  * special, indirect or consequential damages or lost profits even if
12  * IBM has been advised of the possibility of their occurrence. IBM
13  * will not be liable for any third party claims against you.
14  */

15 import java.util.Hashtable JavaDoc;
16
17 public class WebDAVStatus
18 {
19    private int statusCode = 200;
20    
21    private static Hashtable JavaDoc messages = new Hashtable JavaDoc();
22
23    /*
24     * HTTP/1.1 status codes; see RFC 1945 and the WebDAV specification
25     */

26
27    // Provisional response:
28

29    /**
30     * Status code (100) indicating the client may continue with
31     * its request. This interim response is used to inform the
32     * client that the initial part of the request has been
33     * received and has not yet been rejected by the server.
34     */

35    public static final int SC_CONTINUE = 100;
36
37    /**
38     * Status code (101) indicating the server is switching protocols
39     * according to Upgrade header.
40     */

41    public static final int SC_SWITCHING_PROTOCOLS = 101;
42
43    /**
44     * Status code (102) indicating the server is still processing the request.
45     */

46    public static final int SC_PROCESSING = 102;
47
48
49
50    // Request was successfully received, understood, and accepted.
51

52    /**
53     * Status code (200) indicating the request succeeded normally.
54     */

55    public static final int SC_OK = 200;
56
57    /**
58     * Status code (201) indicating the request succeeded and created
59     * a new resource on the server.
60     */

61    public static final int SC_CREATED = 201;
62
63    /**
64     * Status code (202) indicating that a request was accepted for
65     * processing, but was not completed.
66     */

67    public static final int SC_ACCEPTED = 202;
68
69    /**
70     * Status code (203) indicating that the meta information presented
71     * by the client did not originate from the server.
72     */

73    public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203;
74
75    /**
76     * Status code (204) indicating that the request succeeded but that
77     * there was no new information to return.
78     */

79    public static final int SC_NO_CONTENT = 204;
80
81    /**
82     * Status code (205) indicating that the agent SHOULD reset the document
83     * view which caused the request to be sent.
84     */

85    public static final int SC_RESET_CONTENT = 205;
86
87    /**
88     * Status code (206) indicating that the server has fulfilled the partial
89     * GET request for the resource.
90     */

91    public static final int SC_PARTIAL_CONTENT = 206;
92
93    /**
94     * Status code (207) indicating that the response provides status for multiple
95     * independent operations.
96     */

97    public static final int SC_MULTI_STATUS = 207;
98
99
100
101    // Redirection: indicates further action needs to be taken by the user.
102

103    /** Status code (300) indicating that the requested resource corresponds to any one of
104     * a set of representations, each with its own specific location
105     */

106    public static final int SC_MULTIPLE_CHOICES = 300;
107
108    /**
109     * Status code (301) indicating that the resource has permanently
110     * moved to a new location, and that future references should use a
111     * new URI with their requests.
112     */

113    public static final int SC_MOVED_PERMANENTLY = 301;
114
115    /**
116     * Status code (302) indicating that the resource has temporarily
117     * moved to another location, but that future references should
118     * still use the original URI to access the resource.
119     */

120    public static final int SC_MOVED_TEMPORARILY = 302;
121
122    /**
123     * Status code (303) indicating that the response to the request can
124     * be found under a different URI.
125     */

126    public static final int SC_SEE_OTHER = 303;
127
128    /**
129     * Status code (304) indicating that a conditional GET operation
130     * found that the resource was available and not modified.
131     */

132    public static final int SC_NOT_MODIFIED = 304;
133
134    /**
135     * Status code (305) indicating that the requested resource MUST be accessed
136     * through the proxy given by the Location field.
137     */

138    public static final int SC_USE_PROXY = 305;
139
140
141
142    // Client error
143

144    /**
145     * Status code (400) indicating the request sent by the client was
146     * syntactically incorrect.
147     */

148    public static final int SC_BAD_REQUEST = 400;
149
150    /**
151     * Status code (401) indicating that the request requires HTTP
152     * authentication.
153     */

154    public static final int SC_UNAUTHORIZED = 401;
155
156    /**
157     * Status code (402) reserved for future use.
158     */

159    public static final int SC_PAYMENT_REQUIRED = 402;
160
161    /**
162     * Status code (403) indicating the server understood the request
163     * but refused to fulfill it.
164     */

165    public static final int SC_FORBIDDEN = 403;
166
167    /**
168     * Status code (404) indicating that the requested resource is not
169     * available.
170     */

171    public static final int SC_NOT_FOUND = 404;
172
173    /**
174     * Status code (405) indicating the method specified is not
175     * allowed for the resource.
176     */

177    public static final int SC_METHOD_NOT_ALLOWED = 405;
178
179    /**
180     * Status code (406) indicating the resource identified by the
181     * request is only capable of generating response entities
182     * which have content characteristics not acceptable according
183     * to the accept headerssent in the request.
184     */

185    public static final int SC_NOT_ACCEPTABLE = 406;
186
187    /**
188     * Status code (407) indicating the client MUST first authenticate
189     * itself with the proxy.
190     */

191    public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
192    
193    /**
194     * Status code (408) indicating the client did not produce a request within
195     * the time that the server was prepared to wait.
196     */

197    public static final int SC_REQUEST_TIMEOUT = 408;
198    
199    /**
200     * Status code (409) indicating that the request could not be
201     * completed due to a conflict with the current state of the
202     * resource.
203     */

204    public static final int SC_CONFLICT = 409;
205
206    /**
207     * Status code (410) indicating the server did not receive a timely
208     * response from the upstream server while acting as a gateway or proxy.
209     */

210    public static final int SC_GONE = 410;
211
212    /**
213     * Status code (411) indicating the request cannot be handled
214     * without a defined Content-Length.
215     */

216    public static final int SC_LENGTH_REQUIRED = 411;
217
218    /**
219     * Status code (412) indicating the precondition given in one
220     * or more of the request-header fields evaluated to false
221     * when it was tested on the server.
222     */

223    public static final int SC_PRECONDITION_FAILED = 412;
224
225    /**
226     * Status code (413) indicating the server is refusing to
227     * process a request because the request entity is larger
228     * than the server is willing or able to process.
229     */

230    public static final int SC_REQUEST_TOO_LONG = 413;
231
232    /**
233     * Status code (414) indicating the server is refusing to
234     * service the request because the Request-URI is longer
235     * than the server is willing to interpret.
236     */

237    public static final int SC_REQUEST_URI_TOO_LONG = 414;
238
239    /**
240     * Status code (415) indicating the server is refusing to service
241     * the request because the entity of the request is in a format
242     * not supported by the requested resource for the requested
243     * method.
244     */

245    public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
246
247    /**
248     * Status code (422) indicating the server understands the content type of the
249     * request entity, but was unable to process the contained instructions.
250     */

251    public static final int SC_UNPROCESSABLE_ENTITY = 422;
252
253    /**
254     * Status code (423) indicating the source or destination resource of a
255     * method is locked.
256     */

257    public static final int SC_LOCKED = 423;
258
259    /**
260     * Status code (424) indicating the method was not executed on
261     * a particular resource within its scope because some part of
262     * the method's execution failed causing the entire method to be
263     * aborted. (AKA Failed Dependency)
264     */

265    public static final int SC_FAILED_DEPENDENCY = 424;
266    
267    /**
268     * Status code (425) indicating that the resource does not have sufficient
269     * space to record the state of the resource after the executino of the method.
270     */

271    public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 425;
272
273
274
275    /**
276     * Status code (426) indicating that the resource does not have
277     * the specified target revision
278     */

279    public static final int SC_NO_SUCH_TARGET = 426;
280
281
282
283    // Server errors
284

285    /**
286     * Status code (500) indicating an error inside the HTTP service
287     * which prevented it from fulfilling the request.
288     */

289    public static final int SC_INTERNAL_SERVER_ERROR = 500;
290
291    /**
292     * Status code (501) indicating the HTTP service does not support
293     * the functionality needed to fulfill the request.
294     */

295    public static final int SC_NOT_IMPLEMENTED = 501;
296
297    /**
298     * Status code (502) indicating that the HTTP server received an
299     * invalid response from a server it consulted when acting as a
300     * proxy or gateway.
301     */

302    public static final int SC_BAD_GATEWAY = 502;
303
304    /**
305     * Status code (503) indicating that the HTTP service is
306     * temporarily overloaded, and unable to handle the request.
307     */

308    public static final int SC_SERVICE_UNAVAILABLE = 503;
309
310    /**
311     * Status code (504) indicating the server did not receive a
312     * timely response from the upstream server while acting as a
313     * gateway or proxy.
314     */

315    public static final int SC_GATEWAY_TIMEOUT = 504;
316
317    /**
318     * Status code (505) indicating the server does not support or
319     * refuses to support the HTTP protocol version that was used
320     * in the request message.
321     */

322    public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
323
324    //----------------------------------------------------------------
325

326    static {
327       messages.put(new Integer JavaDoc(SC_CONTINUE), "Continue");
328       messages.put(new Integer JavaDoc(SC_SWITCHING_PROTOCOLS), "Switching Protocols");
329       messages.put(new Integer JavaDoc(SC_PROCESSING), "Processing");
330       messages.put(new Integer JavaDoc(SC_OK), "OK");
331       messages.put(new Integer JavaDoc(SC_CREATED), "Created");
332       messages.put(new Integer JavaDoc(SC_ACCEPTED), "Accepted");
333       messages.put(new Integer JavaDoc(SC_NON_AUTHORITATIVE_INFORMATION), "Non-Authoritative Information");
334       messages.put(new Integer JavaDoc(SC_NO_CONTENT), "No Content");
335       messages.put(new Integer JavaDoc(SC_RESET_CONTENT), "Reset Content");
336       messages.put(new Integer JavaDoc(SC_PARTIAL_CONTENT), "Partial Content");
337       messages.put(new Integer JavaDoc(SC_MULTI_STATUS), "Multi-Status");
338       messages.put(new Integer JavaDoc(SC_MULTIPLE_CHOICES), "Multiple Choices");
339       messages.put(new Integer JavaDoc(SC_MOVED_PERMANENTLY), "Moved Permanently");
340       messages.put(new Integer JavaDoc(SC_MOVED_TEMPORARILY), "Moved Temporarily");
341       messages.put(new Integer JavaDoc(SC_SEE_OTHER), "See Other");
342       messages.put(new Integer JavaDoc(SC_NOT_MODIFIED), "Not Modified");
343       messages.put(new Integer JavaDoc(SC_USE_PROXY), "Use Proxy");
344       messages.put(new Integer JavaDoc(SC_BAD_REQUEST), "Bad Request");
345       messages.put(new Integer JavaDoc(SC_UNAUTHORIZED), "Unauthorized");
346       messages.put(new Integer JavaDoc(SC_PAYMENT_REQUIRED), "Payment Required");
347       messages.put(new Integer JavaDoc(SC_FORBIDDEN), "Forbidden");
348       messages.put(new Integer JavaDoc(SC_NOT_FOUND), "Not Found");
349       messages.put(new Integer JavaDoc(SC_METHOD_NOT_ALLOWED), "Method Not Allowed");
350       messages.put(new Integer JavaDoc(SC_NOT_ACCEPTABLE), "Not Acceptable");
351       messages.put(new Integer JavaDoc(SC_PROXY_AUTHENTICATION_REQUIRED), "Proxy Authentication Required");
352       messages.put(new Integer JavaDoc(SC_REQUEST_TIMEOUT), "Request Time-out");
353       messages.put(new Integer JavaDoc(SC_CONFLICT), "Conflict");
354       messages.put(new Integer JavaDoc(SC_GONE), "Gone");
355       messages.put(new Integer JavaDoc(SC_LENGTH_REQUIRED), "Length Required");
356       messages.put(new Integer JavaDoc(SC_PRECONDITION_FAILED), "Precondition Failed");
357       messages.put(new Integer JavaDoc(SC_REQUEST_TOO_LONG), "Request Entity Too Large");
358       messages.put(new Integer JavaDoc(SC_REQUEST_URI_TOO_LONG), "Request-URI Too Large");
359       messages.put(new Integer JavaDoc(SC_UNSUPPORTED_MEDIA_TYPE), "Unsupported Media Type");
360       messages.put(new Integer JavaDoc(SC_UNPROCESSABLE_ENTITY), "Unprocessable Entity");
361       messages.put(new Integer JavaDoc(SC_LOCKED), "Locked");
362       messages.put(new Integer JavaDoc(SC_FAILED_DEPENDENCY), "Failed Dependency");
363       messages.put(new Integer JavaDoc(SC_INSUFFICIENT_SPACE_ON_RESOURCE), "Inusfficient Space On Resource");
364       messages.put(new Integer JavaDoc(SC_NO_SUCH_TARGET), "No Such Target");
365       messages.put(new Integer JavaDoc(SC_INTERNAL_SERVER_ERROR), "Internal Server Error");
366       messages.put(new Integer JavaDoc(SC_NOT_IMPLEMENTED), "Not Implemented");
367       messages.put(new Integer JavaDoc(SC_BAD_GATEWAY), "Bad Gateway");
368       messages.put(new Integer JavaDoc(SC_SERVICE_UNAVAILABLE), "Service Unavailable");
369       messages.put(new Integer JavaDoc(SC_GATEWAY_TIMEOUT), "Gateway Time-out");
370       messages.put(new Integer JavaDoc(SC_HTTP_VERSION_NOT_SUPPORTED), "HTTP Version not supported");
371    }
372    
373
374 /**
375  * Get the value of this WebDAVStatus
376  * @return int
377  */

378 public int getStatusCode() {
379     return statusCode;
380 }
381 /** Get a message describing the status code of this WebDAVStatus
382 * @return the corresponding status message or "Unknown" if there is no message for
383 * the current status code
384 */

385 public String JavaDoc getStatusMessage() {
386     return getStatusMessage(statusCode);
387 }
388 /** Get a message describing the status code.
389 * @param statusCode an HTTP/1.1 or WebDAV status code
390 * @return the corresponding status message or "Unknown" if there is no message for
391 * the given status code
392 */

393 public static String JavaDoc getStatusMessage(int statusCode) {
394     String JavaDoc message = "Unknown";
395     if (statusCode > 0) {
396         message = (String JavaDoc) messages.get(new Integer JavaDoc(statusCode));
397     }
398     return message;
399 }
400 /**
401  * Set the value of this WebDAVStatus
402  * @param newStatusCode int
403  */

404 public void setStatusCode(int newStatusCode) {
405     statusCode = newStatusCode;
406 }
407 /**
408  * Convert a WebDAVStatus to a String for printing, etc.
409  * @param newStatusCode int
410  */

411 public String JavaDoc toString() {
412     return new String JavaDoc(getStatusMessage()+'('+statusCode+')');
413 }
414 }
415
Popular Tags