1 58 package org.apache.ecs.filter; 59 60 import org.apache.ecs.Filter; 61 import org.apache.ecs.Entities; 62 import java.text.StringCharacterIterator ; 63 import java.text.CharacterIterator ; 64 88 public class CharacterFilter extends java.util.Hashtable implements Filter 89 { 90 94 { 95 addAttribute("\"",Entities.QUOT); 96 addAttribute("'",Entities.LSQUO); 97 addAttribute("&",Entities.AMP); 98 addAttribute("<",Entities.LT); 99 addAttribute(">",Entities.GT); 100 } 101 102 public CharacterFilter() 103 { 104 super(4); 105 } 106 107 108 public String getInfo() 109 { 110 return "CharacterFilter"; 111 } 112 113 116 public Filter addAttribute(String name,Object attribute) 117 { 118 this.put(name,attribute); 119 return this; 120 } 121 122 125 public Filter removeAttribute(String name) 126 { 127 try 128 { 129 this.remove(name); 130 } 131 catch ( Exception e ) 132 { 133 } 134 return this; 135 } 136 137 140 public boolean hasAttribute(String key) 141 { 142 return(this.containsKey(key)); 143 } 144 145 148 public String process(String to_process) 149 { 150 if ( to_process == null || to_process.length() == 0 ) 151 return ""; 152 153 StringBuffer bs = new StringBuffer (to_process.length() + 50); 154 StringCharacterIterator sci = new StringCharacterIterator (to_process); 155 String tmp = null; 156 157 for (char c = sci.first(); c != CharacterIterator.DONE; c = sci.next()) 158 { 159 tmp = String.valueOf(c); 160 161 if (hasAttribute(tmp)) 162 tmp = (String ) this.get(tmp); 163 164 bs.append(tmp); 165 } 166 return(bs.toString()); 167 } 168 } 169 | Popular Tags |