1 17 18 19 package org.apache.commons.digester; 20 21 22 import org.xml.sax.Attributes ; 23 24 import org.apache.commons.collections.ArrayStack; 25 26 27 44 45 public class CallParamRule extends Rule { 46 47 49 50 66 public CallParamRule(Digester digester, int paramIndex) { 67 68 this(paramIndex); 69 70 } 71 72 73 84 public CallParamRule(Digester digester, int paramIndex, 85 String attributeName) { 86 87 this(paramIndex, attributeName); 88 89 } 90 91 103 public CallParamRule(int paramIndex) { 104 105 this(paramIndex, null); 106 107 } 108 109 110 117 public CallParamRule(int paramIndex, 118 String attributeName) { 119 120 this.paramIndex = paramIndex; 121 this.attributeName = attributeName; 122 123 } 124 125 126 132 public CallParamRule(int paramIndex, boolean fromStack) { 133 134 this.paramIndex = paramIndex; 135 this.fromStack = fromStack; 136 137 } 138 139 147 public CallParamRule(int paramIndex, int stackIndex) { 148 149 this.paramIndex = paramIndex; 150 this.fromStack = true; 151 this.stackIndex = stackIndex; 152 } 153 154 156 157 160 protected String attributeName = null; 161 162 163 166 protected int paramIndex = 0; 167 168 169 172 protected boolean fromStack = false; 173 174 177 protected int stackIndex = 0; 178 179 183 protected ArrayStack bodyTextStack; 184 185 187 188 193 public void begin(Attributes attributes) throws Exception { 194 195 Object param = null; 196 197 if (attributeName != null) { 198 199 param = attributes.getValue(attributeName); 200 201 } else if(fromStack) { 202 203 param = digester.peek(stackIndex); 204 205 if (digester.log.isDebugEnabled()) { 206 207 StringBuffer sb = new StringBuffer ("[CallParamRule]{"); 208 sb.append(digester.match); 209 sb.append("} Save from stack; from stack?").append(fromStack); 210 sb.append("; object=").append(param); 211 digester.log.debug(sb.toString()); 212 } 213 } 214 215 221 if(param != null) { 222 Object parameters[] = (Object []) digester.peekParams(); 223 parameters[paramIndex] = param; 224 } 225 } 226 227 228 233 public void body(String bodyText) throws Exception { 234 235 if (attributeName == null && !fromStack) { 236 if (bodyTextStack == null) { 240 bodyTextStack = new ArrayStack(); 241 } 242 bodyTextStack.push(bodyText.trim()); 243 } 244 245 } 246 247 250 public void end(String namespace, String name) { 251 if (bodyTextStack != null && !bodyTextStack.empty()) { 252 Object parameters[] = (Object []) digester.peekParams(); 254 parameters[paramIndex] = bodyTextStack.pop(); 255 } 256 } 257 258 261 public String toString() { 262 263 StringBuffer sb = new StringBuffer ("CallParamRule["); 264 sb.append("paramIndex="); 265 sb.append(paramIndex); 266 sb.append(", attributeName="); 267 sb.append(attributeName); 268 sb.append(", from stack="); 269 sb.append(fromStack); 270 sb.append("]"); 271 return (sb.toString()); 272 273 } 274 275 276 } 277 | Popular Tags |