1 16 package org.apache.jetspeed.util.parser; 17 18 import javax.servlet.http.HttpServletRequest ; 19 20 import org.apache.turbine.util.parser.DefaultParameterParser; 21 22 import org.apache.jetspeed.om.registry.MediaTypeEntry; 23 import org.apache.jetspeed.services.Registry; 24 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 25 import org.apache.jetspeed.services.logging.JetspeedLogger; 26 import org.apache.jetspeed.capability.CapabilityMap; 27 import org.apache.jetspeed.capability.CapabilityMapFactory; 28 import org.apache.jetspeed.services.resources.JetspeedResources; 29 30 52 public class DefaultJetspeedParameterParser extends DefaultParameterParser 53 { 54 57 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(DefaultJetspeedParameterParser.class.getName()); 58 59 public DefaultJetspeedParameterParser() 60 { 61 super(); 62 } 63 64 public DefaultJetspeedParameterParser(String characterEncoding) 65 { 66 super (characterEncoding); 67 } 68 69 82 public void setRequest(HttpServletRequest req) 83 { 84 super.setRequest(req); 85 86 String enc = JetspeedResources.getString(JetspeedResources.CONTENT_ENCODING_KEY,"US-ASCII"); 87 CapabilityMap cm = CapabilityMapFactory.getCapabilityMap( req.getHeader("User-Agent") ); 88 String mimeCode = cm.getPreferredType().getCode(); 89 if ( mimeCode != null ) 90 { 91 MediaTypeEntry media = (MediaTypeEntry)Registry.getEntry(Registry.MEDIA_TYPE, mimeCode); 92 if ( media != null && media.getCharacterSet() != null) 93 { 94 enc = media.getCharacterSet(); 95 } 96 97 } 98 if ( req.getCharacterEncoding() != null ) 99 { 100 enc = req.getCharacterEncoding(); 101 } 102 setCharacterEncoding( enc ); 103 } 104 105 112 public String getString(String name) 113 { 114 String str = super.getString(name); 115 if (str == null) return null; 116 117 try 118 { 119 return new String (str.getBytes("8859_1"), getCharacterEncoding()); 120 } 121 catch (Exception e) 122 { 123 logger.warn("DefaultJetspeedParameterParser: Exception: " + e.toString()); 124 return str; 125 } 126 127 } 128 129 } 130 131 | Popular Tags |