1 18 19 20 package org.apache.tomcat.util.digester; 21 22 23 import org.xml.sax.Attributes ; 24 25 26 43 44 public class CallParamRule extends Rule { 45 46 48 49 59 public CallParamRule(Digester digester, int paramIndex) { 60 61 this(paramIndex); 62 63 } 64 65 66 77 public CallParamRule(Digester digester, int paramIndex, 78 String attributeName) { 79 80 this(paramIndex, attributeName); 81 82 } 83 84 90 public CallParamRule(int paramIndex) { 91 92 this(paramIndex, null); 93 94 } 95 96 97 104 public CallParamRule(int paramIndex, 105 String attributeName) { 106 107 this.paramIndex = paramIndex; 108 this.attributeName = attributeName; 109 110 } 111 112 113 119 public CallParamRule(int paramIndex, boolean fromStack) { 120 121 this.paramIndex = paramIndex; 122 this.fromStack = fromStack; 123 124 } 125 126 134 public CallParamRule(int paramIndex, int stackIndex) { 135 136 this.paramIndex = paramIndex; 137 this.fromStack = true; 138 this.stackIndex = stackIndex; 139 } 140 141 143 144 147 protected String attributeName = null; 148 149 150 153 protected int paramIndex = 0; 154 155 156 159 protected boolean fromStack = false; 160 161 164 protected int stackIndex = 0; 165 166 170 protected ArrayStack bodyTextStack; 171 172 174 175 180 public void begin(Attributes attributes) throws Exception { 181 182 Object param = null; 183 184 if (attributeName != null) { 185 186 param = attributes.getValue(attributeName); 187 188 } else if(fromStack) { 189 190 param = digester.peek(stackIndex); 191 192 if (digester.log.isDebugEnabled()) { 193 194 StringBuffer sb = new StringBuffer ("[CallParamRule]{"); 195 sb.append(digester.match); 196 sb.append("} Save from stack; from stack?").append(fromStack); 197 sb.append("; object=").append(param); 198 digester.log.debug(sb.toString()); 199 } 200 } 201 202 208 if(param != null) { 209 Object parameters[] = (Object []) digester.peekParams(); 210 parameters[paramIndex] = param; 211 } 212 } 213 214 215 220 public void body(String bodyText) throws Exception { 221 222 if (attributeName == null && !fromStack) { 223 if (bodyTextStack == null) { 227 bodyTextStack = new ArrayStack(); 228 } 229 bodyTextStack.push(bodyText.trim()); 230 } 231 232 } 233 234 237 public void end(String namespace, String name) { 238 if (bodyTextStack != null && !bodyTextStack.empty()) { 239 Object parameters[] = (Object []) digester.peekParams(); 241 parameters[paramIndex] = bodyTextStack.pop(); 242 } 243 } 244 245 248 public String toString() { 249 250 StringBuffer sb = new StringBuffer ("CallParamRule["); 251 sb.append("paramIndex="); 252 sb.append(paramIndex); 253 sb.append(", attributeName="); 254 sb.append(attributeName); 255 sb.append(", from stack="); 256 sb.append(fromStack); 257 sb.append("]"); 258 return (sb.toString()); 259 260 } 261 262 263 } 264 | Popular Tags |