Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 274   Methods: 2
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WebdavStatus.java 50% 96.8% 100% 94.3%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: WebdavStatus.java 541515 2007-05-25 02:45:06Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.webadmin.webdav;
 21   
 22    import java.util.Map;
 23    import java.util.HashMap;
 24    import javax.servlet.http.HttpServletResponse;
 25   
 26    /**
 27    * Wraps the HttpServletResponse class to abstract the specific protocol
 28    * used. To support other protocols we would only need to modify this class.
 29    *
 30    * @author Marc Eaddy
 31    * @version $Revision: 541515 $, $Date: 2007-05-24 19:45:06 -0700 (Thu, 24 May 2007) $
 32    */
 33    public class WebdavStatus {
 34   
 35    // ------------------------------------------------------ HTTP Status Codes
 36   
 37    /**
 38    * Status code (200) indicating the request succeeded normally.
 39    */
 40    public static final int SC_OK = HttpServletResponse.SC_OK;
 41   
 42    /**
 43    * Status code (201) indicating the request succeeded and created
 44    * a new resource on the server.
 45    */
 46    public static final int SC_CREATED = HttpServletResponse.SC_CREATED;
 47   
 48    /**
 49    * Status code (202) indicating that a request was accepted for
 50    * processing, but was not completed.
 51    */
 52    public static final int SC_ACCEPTED = HttpServletResponse.SC_ACCEPTED;
 53   
 54    /**
 55    * Status code (204) indicating that the request succeeded but that
 56    * there was no new information to return.
 57    */
 58    public static final int SC_NO_CONTENT = HttpServletResponse.SC_NO_CONTENT;
 59   
 60    /**
 61    * Status code (301) indicating that the resource has permanently
 62    * moved to a new location, and that future references should use a
 63    * new URI with their requests.
 64    */
 65    public static final int SC_MOVED_PERMANENTLY = HttpServletResponse.SC_MOVED_PERMANENTLY;
 66   
 67    /**
 68    * Status code (302) indicating that the resource has temporarily
 69    * moved to another location, but that future references should
 70    * still use the original URI to access the resource.
 71    */
 72    public static final int SC_MOVED_TEMPORARILY = HttpServletResponse.SC_MOVED_TEMPORARILY;
 73   
 74    /**
 75    * Status code (304) indicating that a conditional GET operation
 76    * found that the resource was available and not modified.
 77    */
 78    public static final int SC_NOT_MODIFIED = HttpServletResponse.SC_NOT_MODIFIED;
 79   
 80    /**
 81    * Status code (400) indicating the request sent by the client was
 82    * syntactically incorrect.
 83    */
 84    public static final int SC_BAD_REQUEST = HttpServletResponse.SC_BAD_REQUEST;
 85   
 86    /**
 87    * Status code (401) indicating that the request requires HTTP
 88    * authentication.
 89    */
 90    public static final int SC_UNAUTHORIZED = HttpServletResponse.SC_UNAUTHORIZED;
 91   
 92    /**
 93    * Status code (403) indicating the server understood the request
 94    * but refused to fulfill it.
 95    */
 96    public static final int SC_FORBIDDEN = HttpServletResponse.SC_FORBIDDEN;
 97   
 98    /**
 99    * Status code (404) indicating that the requested resource is not
 100    * available.
 101    */
 102    public static final int SC_NOT_FOUND = HttpServletResponse.SC_NOT_FOUND;
 103   
 104    /**
 105    * Status code (500) indicating an error inside the HTTP service
 106    * which prevented it from fulfilling the request.
 107    */
 108    public static final int SC_INTERNAL_SERVER_ERROR = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
 109   
 110    /**
 111    * Status code (501) indicating the HTTP service does not support
 112    * the functionality needed to fulfill the request.
 113    */
 114    public static final int SC_NOT_IMPLEMENTED = HttpServletResponse.SC_NOT_IMPLEMENTED;
 115   
 116    /**
 117    * Status code (502) indicating that the HTTP server received an
 118    * invalid response from a server it consulted when acting as a
 119    * proxy or gateway.
 120    */
 121    public static final int SC_BAD_GATEWAY = HttpServletResponse.SC_BAD_GATEWAY;
 122   
 123    /**
 124    * Status code (503) indicating that the HTTP service is
 125    * temporarily overloaded, and unable to handle the request.
 126    */
 127    public static final int SC_SERVICE_UNAVAILABLE = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
 128   
 129    /**
 130    * Status code (100) indicating the client may continue with
 131    * its request. This interim response is used to inform the
 132    * client that the initial part of the request has been
 133    * received and has not yet been rejected by the server.
 134    */
 135    public static final int SC_CONTINUE = HttpServletResponse.SC_CONTINUE;
 136   
 137    /**
 138    * Status code (405) indicating the method specified is not
 139    * allowed for the resource.
 140    */
 141    public static final int SC_METHOD_NOT_ALLOWED = HttpServletResponse.SC_METHOD_NOT_ALLOWED;
 142   
 143    /**
 144    * Status code (409) indicating that the request could not be
 145    * completed due to a conflict with the current state of the
 146    * resource.
 147    */
 148    public static final int SC_CONFLICT = HttpServletResponse.SC_CONFLICT;
 149   
 150    /**
 151    * Status code (412) indicating the precondition given in one
 152    * or more of the request-header fields evaluated to false
 153    * when it was tested on the server.
 154    */
 155    public static final int SC_PRECONDITION_FAILED = HttpServletResponse.SC_PRECONDITION_FAILED;
 156   
 157    /**
 158    * Status code (413) indicating the server is refusing to
 159    * process a request because the request entity is larger
 160    * than the server is willing or able to process.
 161    */
 162    public static final int SC_REQUEST_ENTITY_TOO_LARGE = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;
 163   
 164    /**
 165    * Status code (415) indicating the server is refusing to service
 166    * the request because the entity of the request is in a format
 167    * not supported by the requested resource for the requested
 168    * method.
 169    */
 170    public static final int SC_UNSUPPORTED_MEDIA_TYPE = HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE;
 171   
 172    // -------------------------------------------- Extended WebDav status code
 173   
 174    /**
 175    * Status code (207) indicating that the response requires
 176    * providing status for multiple independent operations.
 177    */
 178    public static final int SC_MULTI_STATUS = 207;
 179   
 180    /**
 181    * Status code (422) indicating the entity body submitted with
 182    * the PATCH method was not understood by the resource.
 183    */
 184    public static final int SC_UNPROCESSABLE_ENTITY = 422;
 185   
 186    /**
 187    * Status code (507) indicating that the resource does not have
 188    * sufficient space to record the state of the resource after the
 189    * execution of this method.
 190    */
 191    public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 507;
 192   
 193    /**
 194    * Status code (424) indicating the method was not executed on
 195    * a particular resource within its scope because some part of
 196    * the method's execution failed causing the entire method to be
 197    * aborted.
 198    */
 199    public static final int SC_FAILED_DEPENDENCY = 424;
 200   
 201    /**
 202    * Status code (423) indicating the destination resource of a
 203    * method is locked, and either the request did not contain a
 204    * valid Lock-Info header, or the Lock-Info header identifies
 205    * a lock held by another principal.
 206    */
 207    public static final int SC_LOCKED = 423;
 208   
 209    /**
 210    * This Hashtable contains the mapping of HTTP and WebDAV
 211    * status codes to descriptive text.
 212    */
 213    private static Map mapStatusCodes = new HashMap();
 214    static {
 215    // HTTP 1.1 status codes
 216  1 addStatusCodeMap(SC_OK, "OK");
 217  1 addStatusCodeMap(SC_CREATED, "Created");
 218  1 addStatusCodeMap(SC_ACCEPTED, "Accepted");
 219  1 addStatusCodeMap(SC_NO_CONTENT, "No Content");
 220  1 addStatusCodeMap(SC_MOVED_PERMANENTLY, "Moved Permanently");
 221  1 addStatusCodeMap(SC_MOVED_TEMPORARILY, "Moved Temporarily");
 222  1 addStatusCodeMap(SC_NOT_MODIFIED, "Not Modified");
 223  1 addStatusCodeMap(SC_BAD_REQUEST, "Bad Request");
 224  1 addStatusCodeMap(SC_UNAUTHORIZED, "Unauthorized");
 225  1 addStatusCodeMap(SC_FORBIDDEN, "Forbidden");
 226  1 addStatusCodeMap(SC_NOT_FOUND, "Not Found");
 227  1 addStatusCodeMap(SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
 228  1 addStatusCodeMap(SC_NOT_IMPLEMENTED, "Not Implemented");
 229  1 addStatusCodeMap(SC_BAD_GATEWAY, "Bad Gateway");
 230  1 addStatusCodeMap(SC_SERVICE_UNAVAILABLE, "Service Unavailable");
 231  1 addStatusCodeMap(SC_CONTINUE, "Continue");
 232  1 addStatusCodeMap(SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
 233  1 addStatusCodeMap(SC_CONFLICT, "Conflict");
 234  1 addStatusCodeMap(SC_PRECONDITION_FAILED, "Precondition Failed");
 235  1 addStatusCodeMap(SC_REQUEST_ENTITY_TOO_LARGE, "Request Too Long");
 236  1 addStatusCodeMap(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
 237    // WebDav status sodes
 238  1 addStatusCodeMap(SC_MULTI_STATUS, "Multi-Status");
 239  1 addStatusCodeMap(SC_UNPROCESSABLE_ENTITY, "Unprocessable Entity");
 240  1 addStatusCodeMap(SC_INSUFFICIENT_SPACE_ON_RESOURCE, "Insufficient Space On Resource");
 241  1 addStatusCodeMap(SC_FAILED_DEPENDENCY, "Failed Dependency");
 242  1 addStatusCodeMap(SC_LOCKED, "Locked");
 243    }
 244   
 245    /**
 246    * Returns the HTTP status text for the HTTP or WebDav status code
 247    * specified by looking it up in the mapping.
 248    *
 249    * @param statusCode HTTP or WebDAV status code
 250    * @return A string with a short descriptive phrase for the
 251    * HTTP status code (e.g., "OK").
 252    */
 253  16 public static String getStatusText(int statusCode) {
 254  16 Integer intKey = new Integer(statusCode);
 255   
 256  16 if (!mapStatusCodes.containsKey(intKey)) {
 257  0 return "";
 258    } else {
 259  16 return (String) mapStatusCodes.get(intKey);
 260    }
 261    }
 262   
 263    /**
 264    * Adds a new status code -> status text mapping. This is a static
 265    * method because the mapping is a static variable.
 266    *
 267    * @param key HTTP or WebDAV status code
 268    * @param strVal HTTP status text
 269    */
 270  26 private static void addStatusCodeMap(int key, String strVal) {
 271  26 mapStatusCodes.put(new Integer(key), strVal);
 272    }
 273    }
 274