1 10 11 package org.mmbase.bridge.jsp.taglib; 12 import org.mmbase.bridge.jsp.taglib.util.Attribute; 13 import org.mmbase.bridge.jsp.taglib.containers.*; 14 import org.mmbase.bridge.Query; 15 16 import javax.servlet.jsp.JspTagException ; 17 import javax.servlet.jsp.tagext.Tag ; 18 import javax.servlet.jsp.JspException ; 19 import javax.servlet.jsp.jstl.core.*; 20 21 27 28 public class IndexTag extends ListReferrerTag implements Writer, QueryContainerReferrer { 29 30 private Attribute container = Attribute.NULL; 31 32 35 public void setContainer(String c) throws JspTagException { 36 container = getAttribute(c); 37 } 38 39 40 private Attribute offset = Attribute.NULL; 41 42 public void setOffset(String o) throws JspTagException { 43 offset = getAttribute(o); 44 } 45 protected int getOffset() throws JspTagException { 46 return offset.getInt(this, getList().getIndexOffset()); } 48 49 public int doStartTag() throws JspTagException { 50 51 int index; 52 if (container != Attribute.NULL) { 53 if (parentListId != Attribute.NULL) { 54 throw new JspTagException ("Cannot specify both 'container' and 'list' attributes"); 55 } 56 QueryContainer c = (QueryContainer) findParentTag(QueryContainer.class, (String ) container.getValue(this)); 57 Query query = c.getQuery(); 58 index = query.getOffset() / query.getMaxNumber() + offset.getInt(this, 0); 59 } else if (parentListId != Attribute.NULL) { 60 index = getList().getIndex() + getOffset();; 61 } else { 62 Tag tag = findLoopOrQuery(null, true); 63 if (tag instanceof QueryContainer) { 64 Query query = ((QueryContainer) tag).getQuery(); 65 index = query.getOffset() / query.getMaxNumber() + offset.getInt(this, 0); 66 } else { 67 LoopTagStatus status = ((LoopTag) tag).getLoopStatus(); 68 if (status == null) throw new TaglibException("The tag " + tag + " return loop status 'null'"); 69 index = status.getIndex(); 70 if (tag instanceof ListProvider) { 71 index += offset.getInt(this, ((ListProvider) tag).getIndexOffset()); 72 } else { 73 index += offset.getInt(this, 0); 74 } 75 } 76 } 77 78 helper.setValue(new Integer (index)); 79 if (getId() != null) { 80 getContextProvider().getContextContainer().register(getId(), helper.getValue()); 81 } 82 return EVAL_BODY_BUFFERED; 83 } 84 85 86 public int doAfterBody() throws JspException { 87 return helper.doAfterBody(); 88 } 89 90 93 public int doEndTag() throws JspTagException { 94 helper.doEndTag(); 95 return super.doEndTag(); 96 } 97 98 } 99 | Popular Tags |