1 16 17 package org.apache.taglibs.standard.tag.el.core; 18 19 import java.util.ArrayList ; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.jstl.core.LoopTag; 23 import javax.servlet.jsp.tagext.IterationTag ; 24 25 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 26 import org.apache.taglibs.standard.tag.common.core.ForEachSupport; 27 import org.apache.taglibs.standard.tag.common.core.NullAttributeException; 28 29 35 36 public class ForEachTag 37 extends ForEachSupport 38 implements LoopTag, IterationTag 39 { 40 41 44 private String begin_; private String end_; private String step_; private String items_; 49 50 53 public ForEachTag() { 54 super(); 55 init(); 56 } 57 58 59 62 63 public int doStartTag() throws JspException { 64 65 evaluateExpressions(); 67 68 return super.doStartTag(); 70 } 71 72 73 public void release() { 75 super.release(); 76 init(); 77 } 78 79 80 83 public void setBegin(String begin_) { 85 this.begin_ = begin_; 86 this.beginSpecified = true; 87 } 88 89 public void setEnd(String end_) { 91 this.end_ = end_; 92 this.endSpecified = true; 93 } 94 95 public void setStep(String step_) { 97 this.step_ = step_; 98 this.stepSpecified = true; 99 } 100 101 public void setItems(String items_) { 102 this.items_ = items_; 103 } 104 105 108 private void init() { 110 begin_ = null; end_ = null; step_ = null; items_ = null; } 116 117 118 private void evaluateExpressions() throws JspException { 119 126 127 if (begin_ != null) { 128 Object r = ExpressionEvaluatorManager.evaluate( 129 "begin", begin_, Integer .class, this, pageContext); 130 if (r == null) 131 throw new NullAttributeException("forEach", "begin"); 132 begin = ((Integer ) r).intValue(); 133 validateBegin(); 134 } 135 136 if (end_ != null) { 137 Object r = ExpressionEvaluatorManager.evaluate( 138 "end", end_, Integer .class, this, pageContext); 139 if (r == null) 140 throw new NullAttributeException("forEach", "end"); 141 end = ((Integer ) r).intValue(); 142 validateEnd(); 143 } 144 145 if (step_ != null) { 146 Object r = ExpressionEvaluatorManager.evaluate( 147 "step", step_, Integer .class, this, pageContext); 148 if (r == null) 149 throw new NullAttributeException("forEach", "step"); 150 step = ((Integer ) r).intValue(); 151 validateStep(); 152 } 153 154 if (items_ != null) { 155 rawItems = ExpressionEvaluatorManager.evaluate( 156 "items", items_, Object .class, this, pageContext); 157 if (rawItems == null) 159 rawItems = new ArrayList (); 160 } 161 } 162 } 163 | Popular Tags |