Clover coverage report - Code Coverage for tapestry release 4.0-beta-9
Coverage timestamp: Sat Oct 1 2005 08:36:20 EDT
file stats: LOC: 85   Methods: 3
NCLOC: 48   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SetupRequestEncoding.java 100% 100% 100% 100%
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.services.impl;
 16   
 17    import java.io.IOException;
 18    import java.io.UnsupportedEncodingException;
 19   
 20    import javax.servlet.ServletException;
 21    import javax.servlet.http.HttpServletRequest;
 22    import javax.servlet.http.HttpServletResponse;
 23   
 24    import org.apache.hivemind.ApplicationRuntimeException;
 25    import org.apache.tapestry.services.ServletRequestServicer;
 26    import org.apache.tapestry.services.ServletRequestServicerFilter;
 27   
 28    /**
 29    * Analyzes the incoming request to set the correct output encoding.
 30    *
 31    * @author Howard M. Lewis Ship
 32    * @since 4.0
 33    */
 34    public class SetupRequestEncoding implements ServletRequestServicerFilter
 35    {
 36    private boolean _skipSet;
 37   
 38    private String _outputEncoding;
 39   
 40  140 public void service(HttpServletRequest request, HttpServletResponse response,
 41    ServletRequestServicer servicer) throws IOException, ServletException
 42    {
 43  140 if (!_skipSet)
 44    {
 45  138 String encoding = request.getCharacterEncoding();
 46   
 47  138 if (encoding == null)
 48  137 setRequestEncodingToOutputEncoding(request);
 49    }
 50   
 51    // Next in chain
 52   
 53  139 servicer.service(request, response);
 54    }
 55   
 56  137 private void setRequestEncodingToOutputEncoding(HttpServletRequest request)
 57    {
 58  137 try
 59    {
 60    // We compile against the 2.3 API but allow
 61    // the code to execute against the 2.2 In the
 62    // later case, we can get some interesting errors.
 63   
 64  137 request.setCharacterEncoding(_outputEncoding);
 65    }
 66    catch (UnsupportedEncodingException ex)
 67    {
 68  1 throw new ApplicationRuntimeException(
 69    ImplMessages.invalidEncoding(_outputEncoding, ex), ex);
 70    }
 71    catch (NoSuchMethodError ex)
 72    {
 73  1 _skipSet = true;
 74    }
 75    catch (AbstractMethodError ex)
 76    {
 77  1 _skipSet = true;
 78    }
 79    }
 80   
 81  46 public void setOutputEncoding(String outputEncoding)
 82    {
 83  46 _outputEncoding = outputEncoding;
 84    }
 85    }