1 58 package org.apache.ecs.filter; 59 60 import org.apache.ecs.Filter; 61 62 import org.apache.regexp.RE; 63 import org.apache.regexp.RESyntaxException; 64 65 import java.util.Hashtable; 66 import java.util.Enumeration; 67 68 96 public class RegexpFilter extends Hashtable implements Filter { 97 98 public RegexpFilter() 99 { 100 super(4); 101 } 102 103 104 public String getInfo() 105 { 106 return "RegexpFilter"; 107 } 108 109 110 113 public String process(String to_process) 114 { 115 if ( to_process == null || to_process.length() == 0 ) 116 { 117 return ""; 118 } 119 120 String substituteIn = to_process; 121 Enumeration enum = keys(); 122 123 while (enum.hasMoreElements()) { 124 RE r = (RE)enum.nextElement(); 125 String substitution = (String)get(r); 126 substituteIn = r.subst(substituteIn, substitution); 127 } 128 129 return substituteIn; 130 } 131 132 133 139 public Filter addAttribute(String expression,Object substitution) 140 { 141 try { 142 RE r = new RE(expression); 143 put(r, substitution); 144 } 145 catch (RESyntaxException e) { 146 return null; 147 } 148 149 return(this); 150 } 151 152 153 156 public Filter removeAttribute(String expression) 157 { 158 try 159 { 160 RE r = new RE(expression); 161 remove(r); 162 } 163 catch(Exception e) 164 { 165 } 166 return(this); 167 } 168 169 170 174 public boolean hasAttribute(String expression) 175 { 176 try { 177 RE r = new RE(expression); 178 return containsKey(r); 179 } 180 catch (Exception e) { 181 } 182 return false; 183 } 184 } 185
| Popular Tags
|