| 1 16 17 import org.apache.commons.digester.Digester; 18 19 29 30 public class SubstituteTransform implements Transform { 31 private String from; 32 private String to; 33 34 public void setFrom(String from) { 35 this.from = from; 36 } 37 38 public void setTo(String to) { 39 this.to = to; 40 } 41 42 public String transform(String s) { 43 StringBuffer buf = new StringBuffer (s); 44 while (true) { 45 int idx = buf.indexOf(from); 46 if (idx == -1) 47 break; 48 49 StringBuffer buf2 = buf.replace(idx, idx+from.length(), to); 50 } 51 return buf.toString(); 52 } 53 54 public static void addRules(Digester d, String patternPrefix) { 55 d.addCallMethod(patternPrefix+"/from", "setFrom", 0); 56 d.addCallMethod(patternPrefix+"/to", "setTo", 0); 57 } 58 } 59 | Popular Tags |