Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1222 → Rev 1223

/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/taglib/list/PageIterateTag.java
0,0 → 1,119
package ak.hostadmiral.core.taglib.list;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;
import ak.hostadmiral.util.CollectionInfo;
 
public class PageIterateTag
extends BodyTagSupport
{
protected String infoBean = null;
 
public String getInfoBean()
{
return this.infoBean;
}
 
public void setInfoBean(String infoBean)
{
this.infoBean = infoBean;
}
 
protected String infoProperty = null;
 
public String getInfoProperty()
{
return this.infoProperty;
}
 
public void setInfoProperty(String infoProperty)
{
this.infoProperty = infoProperty;
}
 
protected int max = 0;
 
public String getMax()
{
return Integer.toString(this.max);
}
 
public void setMax(String max)
{
this.max = Integer.parseInt(max);
}
 
protected int displayPage;
 
public int getDisplayPage()
{
return this.displayPage;
}
 
protected CollectionInfo collectionInfo;
 
public CollectionInfo getCollectionInfo()
{
return this.collectionInfo;
}
 
public int doStartTag() throws JspException
{
collectionInfo = findCollectionInfo();
displayPage = (max == 0) ? 0
: Math.max(0, collectionInfo.getCurrentPage() - max/2);
 
if(collectionInfo == null) return SKIP_BODY;
 
if(collectionInfo.getTotalPages() > 0)
return EVAL_BODY_TAG;
else
return SKIP_BODY;
}
 
public int doAfterBody() throws JspException
{
// Render the output from this iteration to the output stream
if(bodyContent != null) {
ResponseUtils.writePrevious(pageContext, bodyContent.getString());
bodyContent.clearBody();
}
 
displayPage++;
 
if(max == 0 && displayPage < collectionInfo.getTotalPages()) {
return EVAL_BODY_TAG;
}
else if(max > 0 && displayPage < collectionInfo.getTotalPages()
&& displayPage < collectionInfo.getCurrentPage() + max/2)
{
return EVAL_BODY_TAG;
}
else {
return SKIP_BODY;
}
}
 
public int doEndTag() throws JspException
{
return EVAL_PAGE;
}
 
protected CollectionInfo findCollectionInfo()
throws JspException
{
return (CollectionInfo)
RequestUtils.lookup(pageContext, infoBean, infoProperty, null);
}
 
public void release()
{
super.release();
infoBean = null;
infoProperty = null;
max = 0;
}
}