1 package info.magnolia.cms.taglibs; 2 3 import info.magnolia.cms.core.Content; 4 import info.magnolia.cms.core.ItemType; 5 import info.magnolia.cms.util.Resource; 6 7 import java.util.Collection ; 8 import java.util.Iterator ; 9 10 import javax.servlet.http.HttpServletRequest ; 11 import javax.servlet.jsp.JspException ; 12 import javax.servlet.jsp.tagext.TagSupport ; 13 14 15 19 public class PageIterator extends TagSupport { 20 21 24 private static final long serialVersionUID = 222L; 25 26 private Iterator contentIterator; 27 28 private String hiddenAttribute = "hidden"; 29 30 public int doAfterBody() throws JspException { 31 boolean hasNext = nextContent(); 32 33 if (hasNext) { 34 return EVAL_BODY_AGAIN; 35 } 36 37 return SKIP_BODY; 38 } 39 40 public int doEndTag() throws JspException { 41 HttpServletRequest request = (HttpServletRequest ) this.pageContext.getRequest(); 42 Resource.restoreCurrentActivePage(request); 43 44 return EVAL_PAGE; 45 } 46 47 public int doStartTag() throws JspException { 48 initContentIterator(); 49 50 boolean hasNext = nextContent(); 51 if (hasNext) { 52 return EVAL_BODY_INCLUDE; 53 } 54 55 return SKIP_BODY; 56 } 57 58 public void release() { 59 this.contentIterator = null; 60 super.release(); 61 } 62 63 public void setHiddenAttribute(String hiddenAttribute) { 64 this.hiddenAttribute = hiddenAttribute; 65 } 66 67 private void initContentIterator() { 68 HttpServletRequest req = (HttpServletRequest ) this.pageContext.getRequest(); 69 Content activePage = Resource.getCurrentActivePage(req); 70 Collection children = activePage.getChildren(ItemType.CONTENT); 71 72 for (Iterator i = children.iterator(); i.hasNext();) { 73 Content c = (Content) i.next(); 74 boolean hidden = c.getNodeData(this.hiddenAttribute).getBoolean(); 75 if (hidden) { 76 i.remove(); 77 } 78 } 79 80 this.contentIterator = children.iterator(); 81 } 82 83 86 private boolean nextContent() { 87 if (this.contentIterator.hasNext()) { 88 HttpServletRequest request = (HttpServletRequest ) this.pageContext.getRequest(); 89 Content page = (Content) this.contentIterator.next(); 90 91 Resource.setCurrentActivePage(request, page); 92 93 return true; 94 } 95 96 return false; 97 } 98 } 99 | Popular Tags |