Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 180   Methods: 13
NCLOC: 71   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DAVResponse.java 83.3% 68% 46.2% 63.6%
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   
 18    package org.apache.xindice.webadmin.webdav;
 19   
 20    import org.apache.commons.logging.Log;
 21    import org.apache.commons.logging.LogFactory;
 22    import org.apache.xindice.webadmin.PartialResponse;
 23   
 24    import javax.servlet.ServletOutputStream;
 25    import javax.servlet.http.HttpServletResponse;
 26   
 27    import java.io.IOException;
 28    import java.io.Writer;
 29    import java.io.OutputStreamWriter;
 30   
 31    /**
 32    * This is a wrapper class that provides additional DAV-specific functionality
 33    *
 34    * @version $Revision: 712322 $, $Date: 2008-11-08 00:29:06 +0000 (Sat, 08 Nov 2008) $
 35    */
 36    public class DAVResponse {
 37    public static final String DAV_NS = "DAV:";
 38   
 39    private static final Log log = LogFactory.getLog(DAVResponse.class);
 40   
 41    private final HttpServletResponse response;
 42   
 43    protected final Writer out;
 44    private boolean isMultistatus;
 45    private String protocol;
 46   
 47    /**
 48    * Creates new instance of DAVRequest.
 49    *
 50    * @param response HttpServletResponse
 51    * @throws IOException Servlet IOException
 52    */
 53  36 public DAVResponse(HttpServletResponse response) throws IOException {
 54  36 this.response = response;
 55  36 this.out = new OutputStreamWriter(response.getOutputStream(), "utf-8");
 56    }
 57   
 58    /**
 59    * For multi-status responses, send a partial response. This method resets
 60    * HTTP response status to 207 (Multi-Status).
 61    *
 62    * @param res partial response information
 63    * @throws IOException Servlet IOException
 64    */
 65  12 public void sendMultiStatusResponse(PartialResponse res) throws IOException {
 66  12 if (!isMultistatus) {
 67  4 if (log.isDebugEnabled()) {
 68  0 log.debug("Sending response for HREF " + res.getHref());
 69    }
 70  4 response.setStatus(WebdavStatus.SC_MULTI_STATUS);
 71  4 out.write("<?xml version='1.0' encoding='utf-8'?>\n");
 72  4 out.write("<multistatus xmlns='DAV:'>\n");
 73  4 isMultistatus = true;
 74    }
 75   
 76  12 out.write(res.toString());
 77  12 out.write("\n");
 78    }
 79   
 80    /**
 81    * For multi-status responses, close the response document. Method does not
 82    * affect not multi-status responses.
 83    * HTTP response status to 207 (Multi-Status).
 84    *
 85    * @throws IOException Servlet IOException
 86    */
 87  5 public void closeMultistatusResponse() throws IOException {
 88  5 if (isMultistatus) {
 89  4 out.write("</multistatus>");
 90  4 out.write("\n");
 91  4 out.flush();
 92    }
 93    }
 94   
 95    /**
 96    * Wrapper method, sets HTTP response status.
 97    * @param status HTTP status code
 98    */
 99  38 public void setStatus(int status) {
 100  38 response.setStatus(status);
 101    }
 102   
 103    /**
 104    * Wrapper method, sends an error with HTTP response status.
 105    * @param status HTTP status code
 106    * @throws IOException Servlet IOException
 107    */
 108  0 public void sendError(int status) throws IOException {
 109  0 response.sendError(status);
 110    }
 111   
 112    /**
 113    * Wrapper method, adds header to HTTP response.
 114    * @param header Header name
 115    * @param value Header value
 116    */
 117  0 public void addHeader(String header, String value) {
 118  0 response.addHeader(header, value);
 119    }
 120   
 121    /**
 122    * Wrapper method, adds date header to HTTP response.
 123    * @param header Header name
 124    * @param date Header value
 125    */
 126  0 public void addDateHeader(String header, long date) {
 127  0 response.addDateHeader(header, date);
 128    }
 129   
 130    /**
 131    * Wrapper method, sets HTTP response content type
 132    * @param mimeType MIME type of the content
 133    */
 134  0 public void setContentType(String mimeType) {
 135  0 response.setContentType(mimeType);
 136    }
 137   
 138    /**
 139    * Wrapper method, sets HTTP response content length
 140    * @param contentLength Integer that specify length of the content
 141    */
 142  0 public void setContentLength(int contentLength) {
 143  0 response.setContentLength(contentLength);
 144    }
 145   
 146    /**
 147    * Wrapper method, returns HTTP response output stream
 148    * @return Servlet output stream
 149    * @throws IOException Servlet IOException
 150    */
 151  0 public ServletOutputStream getOutputStream() throws IOException {
 152  0 return response.getOutputStream();
 153    }
 154   
 155    /**
 156    * Wrapper method, sends redirect
 157    * @param redirect Location URL
 158    * @throws IOException Servlet IOException
 159    */
 160  0 public void sendRedirect(String redirect) throws IOException {
 161  0 response.sendRedirect(redirect);
 162    }
 163   
 164    /**
 165    * Sets protocol/version string that is used for multi status responses.
 166    *
 167    * @param protocol Protocol name and version (e.g. HTTP/1.1)
 168    */
 169  5 public void setProtocol(String protocol) {
 170  5 this.protocol = protocol;
 171    }
 172   
 173    /**
 174    * Returns protocol/version.
 175    * @return Protocol name and version (e.g. HTTP/1.1)
 176    */
 177  16 public String getProtocol() {
 178  16 return protocol;
 179    }
 180    }