| 1 64 65 70 package com.jcorporate.expresso.ext.taglib; 71 72 import com.jcorporate.expresso.core.controller.ControllerElement; 73 74 import javax.servlet.jsp.JspException ; 75 import javax.servlet.jsp.JspTagException ; 76 import javax.servlet.jsp.tagext.IterationTag ; 77 import java.util.Enumeration ; 78 79 80 83 public class ElementIterator 84 extends ExpressoBodyTagSupport { 85 protected ControllerElement oneElement = null; 86 protected Enumeration elements = null; 87 88 public ElementIterator() { 89 super(); 90 } 91 92 public int doAfterBody() 93 throws JspException { 94 if (elements.hasMoreElements()) { 95 oneElement = (ControllerElement) elements.nextElement(); 96 97 return IterationTag.EVAL_BODY_AGAIN; 99 } else { 100 return SKIP_BODY; 101 } 102 } 103 104 public int doEndTag() 105 throws JspTagException { 106 try { 107 if (bodyContent != null) { 108 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 109 } 110 } catch (java.io.IOException e) { 111 throw new JspTagException ("IO Error: " + e.getMessage()); 112 } 113 114 return EVAL_PAGE; 115 } 116 117 public void doInitBody() 118 throws JspException { 119 oneElement = (ControllerElement) elements.nextElement(); 120 } 121 122 public int doStartTag() 123 throws javax.servlet.jsp.JspTagException { 124 try { 125 ElementCollection ancestorCollection = (ElementCollection) getAncestor( 126 "com.jcorporate.expresso.ext.taglib.ElementCollection"); 127 128 if (ancestorCollection == null) { 129 throw new JspTagException ("ElementIterator Tag can only be used nested in a ElementCollection tag"); 130 } 131 132 elements = ancestorCollection.getElements(); 133 } catch (Exception e) { 134 throw new JspTagException ("ElementIterator Tag Error: " + 135 e.getMessage()); 136 } 137 if (elements == null || !elements.hasMoreElements()) { 138 return SKIP_BODY; 139 } else { 140 return IterationTag.EVAL_BODY_AGAIN; 142 } 143 } 144 145 public ControllerElement getElement() { 146 return oneElement; 147 } 148 } 149 | Popular Tags |