1 16 17 package org.apache.taglibs.standard.tag.common.xml; 18 19 import java.util.List ; 20 21 import javax.servlet.jsp.JspTagException ; 22 import javax.servlet.jsp.jstl.core.LoopTagSupport; 23 24 import org.apache.taglibs.standard.resources.Resources; 25 26 32 public class ForEachTag extends LoopTagSupport { 33 34 37 private String select; private List nodes; private int nodesIndex; private org.w3c.dom.Node current; 42 45 47 protected void prepare() throws JspTagException { 48 nodesIndex = 0; 49 XPathUtil xu = new XPathUtil(pageContext); 50 nodes = xu.selectNodes(XPathUtil.getContext(this), select); 51 } 52 53 protected boolean hasNext() throws JspTagException { 54 return (nodesIndex < nodes.size()); 55 } 56 57 protected Object next() throws JspTagException { 58 Object o = nodes.get(nodesIndex++); 59 if (!(o instanceof org.w3c.dom.Node )) 60 throw new JspTagException ( 61 Resources.getMessage("FOREACH_NOT_NODESET")); 62 current = (org.w3c.dom.Node ) o; 63 return current; 64 } 65 66 67 70 public void release() { 72 init(); 73 super.release(); 74 } 75 76 77 80 public void setSelect(String select) { 81 this.select = select; 82 } 83 84 public void setBegin(int begin) throws JspTagException { 85 this.beginSpecified = true; 86 this.begin = begin; 87 validateBegin(); 88 } 89 90 public void setEnd(int end) throws JspTagException { 91 this.endSpecified = true; 92 this.end = end; 93 validateEnd(); 94 } 95 96 public void setStep(int step) throws JspTagException { 97 this.stepSpecified = true; 98 this.step = step; 99 validateStep(); 100 } 101 102 105 106 public org.w3c.dom.Node getContext() throws JspTagException { 107 return current; 109 } 110 111 112 115 private void init() { 116 select = null; 117 nodes = null; 118 nodesIndex = 0; 119 current = null; 120 } 121 } 122 123 | Popular Tags |