1 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 34 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 if (!_skipSet) 44 { 45 String encoding = request.getCharacterEncoding(); 46 47 if (encoding == null) 48 setRequestEncodingToOutputEncoding(request); 49 } 50 51 53 servicer.service(request, response); 54 } 55 56 private void setRequestEncodingToOutputEncoding(HttpServletRequest request) 57 { 58 try 59 { 60 64 request.setCharacterEncoding(_outputEncoding); 65 } 66 catch (UnsupportedEncodingException ex) 67 { 68 throw new ApplicationRuntimeException( 69 ImplMessages.invalidEncoding(_outputEncoding, ex), ex); 70 } 71 catch (NoSuchMethodError ex) 72 { 73 _skipSet = true; 74 } 75 catch (AbstractMethodError ex) 76 { 77 _skipSet = true; 78 } 79 } 80 81 public void setOutputEncoding(String outputEncoding) 82 { 83 _outputEncoding = outputEncoding; 84 } 85 } | Popular Tags |