1 58 package org.apache.ecs.filter; 59 60 import org.apache.ecs.Filter; 61 import java.text.StringCharacterIterator ; 62 import java.text.CharacterIterator ; 63 import java.util.StringTokenizer ; 64 65 88 public class WordFilter extends java.util.Hashtable implements Filter 89 { 90 public WordFilter() 91 { 92 super(4); 93 } 94 95 96 public String getInfo() 97 { 98 return "WordFilter"; 99 } 100 101 104 public String process(String to_process) 105 { 106 if ( to_process == null || to_process.length() == 0 ) 107 return ""; 108 109 String tmp = ""; 110 StringTokenizer st = new StringTokenizer (to_process, " ", true); 112 StringBuffer newValue = new StringBuffer (to_process.length() + 50); 113 while ( st.hasMoreTokens() ) 114 { 115 tmp = st.nextToken(); 116 if (hasAttribute(tmp)) 117 newValue.append((String )get(tmp)); 118 else 119 newValue.append(tmp); 120 } 121 return newValue.toString(); 122 } 123 124 127 public Filter addAttribute(String attribute,Object entity) 128 { 129 put(attribute,entity); 130 return(this); 131 } 132 133 136 public Filter removeAttribute(String attribute) 137 { 138 try 139 { 140 remove(attribute); 141 } 142 catch(NullPointerException exc) 143 { } 145 return(this); 146 } 147 148 151 public boolean hasAttribute(String attribute) 152 { 153 return(containsKey(attribute)); 154 } 155 } 156 | Popular Tags |