1 64 65 package com.jcorporate.expresso.core.security.filters; 66 67 import com.jcorporate.expresso.core.misc.ReusableChar; 68 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 69 import org.apache.log4j.Category; 70 71 import java.util.HashMap ; 72 import java.util.Iterator ; 73 74 75 87 public class FilterTreeNode 88 implements java.io.Serializable { 89 private String replacementString = null; 90 private HashMap subnodes = null; 91 92 public FilterTreeNode() { 93 } 94 95 98 public String getReplacementString() { 99 return replacementString; 100 } 101 102 109 public void setReplacementString(String newReplacementString) 110 throws Exception { 111 112 replacementString = (newReplacementString); 117 } 118 119 127 public void setSubnode(ReusableChar key, FilterTreeNode newSubnode) 128 throws Exception { 129 if (subnodes == null) { 130 subnodes = new HashMap (); 131 } 132 133 subnodes.put(key, newSubnode); 137 } 138 139 142 public boolean subnodeExists(ReusableChar key) { 143 if (subnodes == null) { 144 return false; 145 } 146 147 return subnodes.containsKey(key); 148 } 149 150 154 public FilterTreeNode getSubnode(ReusableChar key) { 155 if (subnodes == null) { 156 return null; 157 } 158 if (subnodes.containsKey(key)) { 159 return (FilterTreeNode) subnodes.get(key); 160 } else { 161 return null; 162 } 163 } 164 165 171 public void dumpNode(Category log) { 172 if (log.isDebugEnabled()) { 173 FastStringBuffer fsb = FastStringBuffer.getInstance(); 174 try { 175 dumpNode(fsb, 0); 176 log.debug(fsb.toString()); 177 } finally { 178 fsb.release(); 179 fsb = null; 180 } 181 } 182 } 183 184 187 public void dumpNode() { 188 FastStringBuffer fsb = FastStringBuffer.getInstance(); 189 try { 190 dumpNode(fsb, 0); 191 System.out.println(fsb.toString()); 192 } finally { 193 fsb.release(); 194 fsb = null; 195 } 196 } 197 198 202 public void dumpNode(FastStringBuffer stringBuffer, int depth) { 203 if (replacementString != null) { 204 this.padWithTabs(stringBuffer, depth); 205 stringBuffer.append("Node's ReplacementString:" + 206 replacementString + "\n"); 207 } 208 if (subnodes != null) { 209 for (Iterator i = subnodes.keySet().iterator(); i.hasNext();) { 210 Character c = (Character ) i.next(); 211 FilterTreeNode ftn = (FilterTreeNode) subnodes.get(c); 212 213 if (ftn != null) { 214 this.padWithTabs(stringBuffer, depth); 215 stringBuffer.append("dump for subnode: " + c + "\n"); 216 ftn.dumpNode(stringBuffer, depth + 1); 217 } 218 } 219 } 220 } 221 222 225 private void padWithTabs(FastStringBuffer stringBuffer, int numTabs) { 226 for (int i = 0; i < numTabs; i++) { 227 stringBuffer.append('\t'); 228 } 229 } 230 } | Popular Tags |