Coverage Report - org.apache.tapestry.services.impl.SetupRequestEncoding
 
Classes in this File Line Coverage Branch Coverage Complexity
SetupRequestEncoding
0%
0/18
0%
0/4
3
 
 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  0
 public class SetupRequestEncoding implements ServletRequestServicerFilter
 35  
 {
 36  
     private boolean _skipSet;
 37  
 
 38  
     private String _outputEncoding;
 39  
 
 40  
     public void service(HttpServletRequest request, HttpServletResponse response,
 41  
             ServletRequestServicer servicer) throws IOException, ServletException
 42  
     {
 43  0
         if (!_skipSet)
 44  
         {
 45  0
             String encoding = request.getCharacterEncoding();
 46  
 
 47  0
             if (encoding == null)
 48  0
                 setRequestEncodingToOutputEncoding(request);
 49  
         }
 50  
 
 51  
         // Next in chain
 52  
 
 53  0
         servicer.service(request, response);
 54  0
     }
 55  
 
 56  
     private void setRequestEncodingToOutputEncoding(HttpServletRequest request)
 57  
     {
 58  
         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  0
             request.setCharacterEncoding(_outputEncoding);
 65  
         }
 66  0
         catch (UnsupportedEncodingException ex)
 67  
         {
 68  0
             throw new ApplicationRuntimeException(
 69  
                     ImplMessages.invalidEncoding(_outputEncoding, ex), ex);
 70  
         }
 71  0
         catch (NoSuchMethodError ex)
 72  
         {
 73  0
             _skipSet = true;
 74  
         }
 75  0
         catch (AbstractMethodError ex)
 76  
         {
 77  0
             _skipSet = true;
 78  0
         }
 79  0
     }
 80  
 
 81  
     public void setOutputEncoding(String outputEncoding)
 82  
     {
 83  0
         _outputEncoding = outputEncoding;
 84  0
     }
 85  
 }