1 13 package org.jahia.utils; 14 15 import javax.servlet.http.HttpServletRequest ; 16 import java.util.Map ; 17 import java.util.HashMap ; 18 19 20 24 25 public class I18n { 26 27 static Map w1252ToISO; 28 static { 29 w1252ToISO = new HashMap (); 30 w1252ToISO.put(new Character ('\u0080'), "Euro"); 31 w1252ToISO.put(new Character ('\u0082'), ","); 32 w1252ToISO.put(new Character ('\u0083'), "f"); 33 w1252ToISO.put(new Character ('\u0085'), "..."); 34 w1252ToISO.put(new Character ('\u0088'), "^"); 35 w1252ToISO.put(new Character ('\u008B'), "<"); 36 w1252ToISO.put(new Character ('\u008C'), "OE"); 37 w1252ToISO.put(new Character ('\u0091'), "'"); 38 w1252ToISO.put(new Character ('\u0092'), "'"); 39 w1252ToISO.put(new Character ('\u0093'), "\""); 40 w1252ToISO.put(new Character ('\u0094'), "\""); 41 w1252ToISO.put(new Character ('\u0095'), "."); 42 w1252ToISO.put(new Character ('\u0096'), "-"); 43 w1252ToISO.put(new Character ('\u0097'), "-"); 44 w1252ToISO.put(new Character ('\u0098'), "~"); 45 w1252ToISO.put(new Character ('\u009B'), ">"); 46 w1252ToISO.put(new Character ('\u009C'), "oe"); 47 } 48 49 52 public static String getText(HttpServletRequest request, String paramName ) { 53 54 if ( paramName == null ) 55 return null; 56 57 String value = request.getParameter(paramName); 58 if ( value == null ) 59 return null; 60 61 try{ 62 value = new String (value.getBytes(), request.getCharacterEncoding()); 63 }catch(java.io.UnsupportedEncodingException ex){ 64 System.err.println(ex); 65 }catch ( NullPointerException nex ){ 66 System.err.println(nex); 67 } 68 return value; 69 } 70 71 public static String windows1252ToISO(String windows1252encoded) { 72 StringBuffer transcodedValue = new StringBuffer (windows1252encoded.length()); 73 for (int i=0; i < windows1252encoded.length(); i++) { 74 char curChar = windows1252encoded.charAt(i); 75 if ((curChar >= 128) && (curChar <= 159)) { 76 Character charIndex = new Character (curChar); 80 String replacementStr = (String ) w1252ToISO.get(charIndex); 81 if (replacementStr != null) { 82 transcodedValue.append(replacementStr); 83 } 84 } else { 85 transcodedValue.append(curChar); 86 } 87 } 88 return transcodedValue.toString(); 89 } 90 } 91 92 | Popular Tags |