1 9 package org.jboss.portal.core.servlet.jsp.taglib; 10 11 import java.util.Iterator ; 12 import java.util.LinkedList ; 13 14 import javax.servlet.jsp.JspException ; 15 import javax.servlet.jsp.tagext.TagSupport ; 16 17 import org.jboss.portal.common.context.Context; 18 import org.jboss.portal.common.context.NamedContext; 19 import org.jboss.portal.core.servlet.jsp.PortalJsp; 20 21 26 public class IterateTag 27 extends TagSupport 28 { 29 32 private String ctx; 33 34 private Iterator children; 35 36 private LinkedList contextStack; 37 38 private boolean include; 39 40 43 public void setCtx(String ctx) 44 { 45 this.ctx = ctx; 46 } 47 48 49 public int doStartTag() throws JspException { 50 contextStack = (LinkedList )PortalJsp.contextStack.get(); 51 if (contextStack.isEmpty()) 52 { 53 include = false; 54 PortalJsp.log.debug("No context has been found"); 55 return SKIP_BODY; 56 } 57 58 Context currentContext = ((NamedContext)contextStack.getLast()).getContext(); 59 children = currentContext.childIterator(ctx); 60 61 if (children.hasNext()) { 62 include = true; 63 contextStack.addLast(new NamedContext(ctx, (Context)children.next())); 64 return EVAL_PAGE; 65 } else { 66 include = false; 67 return SKIP_BODY; 68 } 69 } 70 71 public int doAfterBody() { 72 if (children.hasNext()) { 73 Context context = (Context)children.next(); 74 contextStack.removeLast(); 75 contextStack.addLast(new NamedContext(ctx, context)); 76 return EVAL_BODY_AGAIN; 77 } else { 78 return SKIP_BODY; 79 } 80 } 81 82 public int doEndTag() { 83 if (include) { 84 contextStack.removeLast(); 85 } 86 return SKIP_BODY; 87 } 88 } 89 | Popular Tags |