1 15 package org.apache.tapestry.util.text; 16 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 29 public class DefaultCharacterTranslatorSource implements ICharacterTranslatorSource 30 { 31 private static final ICharacterTranslator DEFAULT_TRANSLATOR = new MarkupCharacterTranslator(); 32 private static final ICharacterTranslator UNICODE_TRANSLATOR = new MarkupCharacterTranslator(false); 33 34 private final static Map _translators; 35 36 static { 37 _translators = new HashMap (); 38 _translators.put("UTF-8", UNICODE_TRANSLATOR); 39 _translators.put("UTF-7", UNICODE_TRANSLATOR); 40 _translators.put("UTF-16", UNICODE_TRANSLATOR); 41 _translators.put("UTF-16BE", UNICODE_TRANSLATOR); 42 _translators.put("UTF-16LE", UNICODE_TRANSLATOR); 43 } 44 45 50 public ICharacterTranslator getDefaultTranslator() { 51 return DEFAULT_TRANSLATOR; 52 } 53 54 61 public ICharacterTranslator getTranslator(String encoding) { 62 ICharacterTranslator translator = (ICharacterTranslator) _translators.get(encoding.toUpperCase()); 63 if (translator != null) 64 return translator; 65 return getDefaultTranslator(); 66 } 67 68 } 69 | Popular Tags |