Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 116   Methods: 7
NCLOC: 74   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ServletWebResponse.java 100% 95.2% 100% 96.7%
coverage coverage
 1   
 // Copyright 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.tapestry.web;
 16   
 
 17   
 import java.io.IOException;
 18   
 import java.io.OutputStream;
 19   
 import java.io.PrintWriter;
 20   
 
 21   
 import javax.servlet.http.HttpServletResponse;
 22   
 
 23   
 import org.apache.commons.logging.Log;
 24   
 import org.apache.commons.logging.LogFactory;
 25   
 import org.apache.hivemind.ApplicationRuntimeException;
 26   
 import org.apache.hivemind.util.Defense;
 27   
 import org.apache.tapestry.util.ContentType;
 28   
 
 29   
 /**
 30   
  * Adapts {@link javax.servlet.http.HttpServletResponse} as
 31   
  * {@link org.apache.tapestry.web.WebResponse}.
 32   
  * 
 33   
  * @author Howard M. Lewis Ship
 34   
  * @since 4.0
 35   
  */
 36   
 public class ServletWebResponse implements WebResponse
 37   
 {
 38   
     private static final Log LOG = LogFactory.getLog(ServletWebResponse.class);
 39   
 
 40   
     private final HttpServletResponse _servletResponse;
 41   
 
 42   
     private boolean _needsReset;
 43   
 
 44  154
     public ServletWebResponse(HttpServletResponse response)
 45   
     {
 46  154
         Defense.notNull(response, "response");
 47   
 
 48  154
         _servletResponse = response;
 49   
     }
 50   
 
 51  3
     public OutputStream getOutputStream(ContentType contentType)
 52   
     {
 53  3
         Defense.notNull(contentType, "contentType");
 54   
 
 55  3
         _servletResponse.setContentType(contentType.getMimeType());
 56   
 
 57  3
         try
 58   
         {
 59  3
             return _servletResponse.getOutputStream();
 60   
         }
 61   
         catch (IOException ex)
 62   
         {
 63  1
             throw new ApplicationRuntimeException(WebMessages.streamOpenError(contentType, ex),
 64   
                     null, ex);
 65   
         }
 66   
     }
 67   
 
 68  162
     public PrintWriter getPrintWriter(ContentType contentType) throws IOException
 69   
     {
 70  162
         Defense.notNull(contentType, "contentType");
 71   
 
 72  162
         if (_needsReset)
 73  12
             reset();
 74   
 
 75  162
         _needsReset = true;
 76   
 
 77  162
         _servletResponse.setContentType(contentType.toString());
 78   
 
 79  162
         try
 80   
         {
 81  162
             return _servletResponse.getWriter();
 82   
         }
 83   
         catch (IOException ex)
 84   
         {
 85  1
             throw new ApplicationRuntimeException(WebMessages.writerOpenError(contentType, ex),
 86   
                     null, ex);
 87   
         }
 88   
     }
 89   
 
 90  155
     public String encodeURL(String url)
 91   
     {
 92  155
         return _servletResponse.encodeURL(url);
 93   
     }
 94   
 
 95  13
     public void reset()
 96   
     {
 97  13
         try
 98   
         {
 99  13
             _servletResponse.reset();
 100   
         }
 101   
         catch (IllegalStateException ex)
 102   
         {
 103  0
             LOG.error(WebMessages.resetFailed(ex), ex);
 104   
         }
 105   
     }
 106   
 
 107  1
     public void setContentLength(int length)
 108   
     {
 109  1
         _servletResponse.setContentLength(length);
 110   
     }
 111   
 
 112  155
     public String getNamespace()
 113   
     {
 114  155
         return "";
 115   
     }
 116   
 }