1 15 package org.apache.tapestry.util.text; 16 17 23 public class AsciiCharacterTranslator implements ICharacterTranslator 24 { 25 private String [] _charMap; 26 27 35 public AsciiCharacterTranslator(String [][] characterMap) 36 { 37 _charMap = new String [128]; 38 39 int pairCount = characterMap.length; 40 for (int i = 0; i < pairCount; i++) { 41 String [] pair = characterMap[i]; 42 if (pair.length != 2) 43 continue; 44 String key = pair[0]; 45 String value = pair[1]; 46 if (key.length() != 1) 47 continue; 48 char ch = key.charAt(0); 49 if (ch >= 128) 50 continue; 51 52 _charMap[ch] = value; 53 } 54 } 55 56 59 public String translate(char ch) { 60 if (ch >= 128) 61 return null; 62 return _charMap[ch]; 63 } 64 } 65 | Popular Tags |