1 package org.objectweb.modfact.jmi.xmi; 2 3 import java.util.*; 4 5 public class CharTranslator { 6 7 Collection set = new Vector(); 8 9 public CharTranslator() { 10 set.add(new TranslationEntry("<","<")); 11 set.add(new TranslationEntry(">",">")); 12 } 13 14 15 public String encode(String s) { 16 Iterator it = set.iterator(); 17 while(it.hasNext()) { 18 TranslationEntry entry = (TranslationEntry) it.next(); 19 s = replaceAll(s, entry.view ,entry.encode); 20 } 21 return s; 22 } 23 24 public String view(String s) { 25 Iterator it = set.iterator(); 26 while(it.hasNext()) { 27 TranslationEntry entry = (TranslationEntry) it.next(); 28 s = replaceAll(s, entry.encode ,entry.view); 29 } 30 return s; 31 } 32 33 34 public static String replaceAll(String in, String replace, String by) { 35 int i; 36 while((i=in.indexOf(replace))>=0) { 37 in = in.substring(0, i) 38 + by 39 + in.substring(i + replace.length()); 40 } 41 return in; 42 } 43 44 45 static class TranslationEntry { 46 String view; 47 String encode; 48 TranslationEntry(String v, String en) { 49 view = v; 50 encode = en; 51 } 52 } 53 54 } 55 | Popular Tags |