/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailboxManager.java |
---|
286,7 → 286,7 |
return listMailboxes(null, 0, 0, null, editor); |
} |
public Collection listMailboxes(CollectionInfo info, int pageSize, int pageNumber, |
public Collection listMailboxes(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User editor) |
throws ModelException |
{ |
293,11 → 293,12 |
try { |
if(editor.isSuperuser()) { |
if(info != null) { |
info.setSize(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Mailbox").next()).intValue()); |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Mailbox").next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableListSql(pageSize, pageNumber, |
return HibernateUtil.pageableListSql(rowsPerPage, pageNumber, |
"select {mb.*}, {d.*}, {o.*}, {su.*}" |
+ " from mailboxes as mb" |
+ " left join domains as d on mb.domain = d.id" |
322,10 → 323,11 |
+ ") as count_table", |
new Object[] { editor.getId(), editor.getId() }); |
info.setSize(((Long)countlist.get(0)).intValue()); |
info.init(((Long)countlist.get(0)).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableListSql(pageSize, pageNumber, |
return HibernateUtil.pageableListSql(rowsPerPage, pageNumber, |
"select {mb.*}, {d.*}, {o.*}, {su.*}" |
+ " from mailboxes as mb" |
+ " left join domains as d on mb.domain = d.id" |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/HasPrevPageTag.java |
---|
0,0 → 1,16 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class HasPrevPageTag |
extends ExistTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
return (info != null) && (info.getCurrentPage() > 0); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/NoPrevPageTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NoPrevPageTag |
extends HasPrevPageTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return !super.condition(); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/HasNextPageTag.java |
---|
0,0 → 1,16 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class HasNextPageTag |
extends ExistTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
return (info != null) && (info.getCurrentPage() < info.getTotalPages() - 1); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/PageTagBase.java |
---|
0,0 → 1,86 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.taglib.html.LinkTag; |
import org.apache.struts.util.RequestUtils; |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.CollectionInfo; |
public abstract class PageTagBase |
extends LinkTag |
{ |
public static String PAGE_PARAM_NAME = "pg"; |
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 BackPath findBackPath() |
throws JspException |
{ |
try { |
return BackPath.findBackPath((HttpServletRequest)pageContext.getRequest(), |
BackPath.DEFAULT_KEY, BackPath.DEFAULT_PARAM, |
new String[] { "backpath", PAGE_PARAM_NAME }, |
BackPath.DEFAULT_ZIP); |
} |
catch(Exception ex) { |
throw new JspException(ex); |
} |
} |
protected String calculateURL() |
throws JspException |
{ |
String urlStr = findBackPath().getCurrentUrl(); |
if(urlStr == null) return "/"; |
StringBuffer url = new StringBuffer(urlStr); |
boolean hasParams = (url.indexOf("?") > 0); |
if(hasParams) |
url.append("&").append(PAGE_PARAM_NAME + "=").append(getDisplayPage()); |
else |
url.append("?").append(PAGE_PARAM_NAME + "=").append(getDisplayPage()); |
return url.toString(); |
} |
protected abstract int getDisplayPage() |
throws JspException; |
protected CollectionInfo getCollectionInfo() |
throws JspException |
{ |
return (CollectionInfo) |
RequestUtils.lookup(pageContext, infoBean, infoProperty, null); |
} |
public void release() |
{ |
super.release(); |
infoBean = null; |
infoProperty = null; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/NoNextPageTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NoNextPageTag |
extends HasNextPageTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return !super.condition(); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/PrevPageTag.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class PrevPageTag |
extends PageTagBase |
{ |
protected int getDisplayPage() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
if(info == null) |
return 0; |
else |
return info.getPrevPage(); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/IsCurrentPageTag.java |
---|
0,0 → 1,22 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class IsCurrentPageTag |
extends IterateSubtagBase |
{ |
public int doStartTag() throws JspException |
{ |
findParent(); |
if(parent.getCollectionInfo().getCurrentPage() == parent.getDisplayPage()) |
return EVAL_BODY_INCLUDE; |
else |
return SKIP_BODY; |
} |
public int doEndTag() throws JspException |
{ |
return EVAL_PAGE; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/NextPageTag.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class NextPageTag |
extends PageTagBase |
{ |
protected int getDisplayPage() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
if(info == null) |
return 0; |
else |
return info.getNextPage(); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/CurrentPageTag.java |
---|
0,0 → 1,45 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.ResponseUtils; |
import org.apache.struts.util.RequestUtils; |
import ak.hostadmiral.util.CollectionInfo; |
public class CurrentPageTag |
extends TagSupport |
{ |
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; |
} |
public int doStartTag() throws JspException |
{ |
CollectionInfo info = (CollectionInfo) |
RequestUtils.lookup(pageContext, infoBean, infoProperty, null); |
ResponseUtils.write(pageContext, Integer.toString(info.getCurrentPage() + 1)); |
return SKIP_BODY; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/HasFirstPageTag.java |
---|
0,0 → 1,16 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class HasFirstPageTag |
extends ExistTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
return (info != null) && (info.getTotalPages() > 0); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/NoFirstPageTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NoFirstPageTag |
extends HasFirstPageTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return !super.condition(); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/FirstPageTag.java |
---|
0,0 → 1,14 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class FirstPageTag |
extends PageTagBase |
{ |
protected int getDisplayPage() |
throws JspException |
{ |
return 0; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/ExistTagBase.java |
---|
0,0 → 1,64 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.RequestUtils; |
import ak.hostadmiral.util.CollectionInfo; |
public abstract class ExistTagBase |
extends TagSupport |
{ |
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; |
} |
public int doStartTag() throws JspException |
{ |
if(condition()) |
return EVAL_BODY_INCLUDE; |
else |
return SKIP_BODY; |
} |
public int doEndTag() throws JspException |
{ |
return EVAL_PAGE; |
} |
protected abstract boolean condition() throws JspException; |
protected CollectionInfo getCollectionInfo() |
throws JspException |
{ |
return (CollectionInfo) |
RequestUtils.lookup(pageContext, infoBean, infoProperty, null); |
} |
public void release() |
{ |
super.release(); |
infoBean = null; |
infoProperty = null; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/PageLinkTag.java |
---|
0,0 → 1,63 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.Tag; |
import org.apache.struts.taglib.html.LinkTag; |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.CollectionInfo; |
public class PageLinkTag |
extends LinkTag |
{ |
public static String PAGE_PARAM_NAME = "pg"; |
protected PageIterateTag parent; |
protected void findParent() |
throws JspException |
{ |
Tag p = getParent(); |
while(p != null && !(p instanceof PageIterateTag)) |
p = p.getParent(); |
if(p == null) |
throw new JspException("This tag must be inside PageIterateTag"); |
parent = (PageIterateTag)p; |
} |
protected BackPath findBackPath() |
throws JspException |
{ |
try { |
return BackPath.findBackPath((HttpServletRequest)pageContext.getRequest(), |
BackPath.DEFAULT_KEY, BackPath.DEFAULT_PARAM, |
new String[] { "backpath", PAGE_PARAM_NAME }, |
BackPath.DEFAULT_ZIP); |
} |
catch(Exception ex) { |
throw new JspException(ex); |
} |
} |
protected String calculateURL() |
throws JspException |
{ |
String urlStr = findBackPath().getCurrentUrl(); |
if(urlStr == null) return "/"; |
StringBuffer url = new StringBuffer(urlStr); |
boolean hasParams = (url.indexOf("?") > 0); |
findParent(); |
if(hasParams) |
url.append("&").append(PAGE_PARAM_NAME + "=").append(parent.getDisplayPage()); |
else |
url.append("?").append(PAGE_PARAM_NAME + "=").append(parent.getDisplayPage()); |
return url.toString(); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/PageIterateTag.java |
---|
0,0 → 1,96 |
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 displayPage; |
public int getDisplayPage() |
{ |
return this.displayPage; |
} |
protected CollectionInfo collectionInfo; |
public CollectionInfo getCollectionInfo() |
{ |
return this.collectionInfo; |
} |
public int doStartTag() throws JspException |
{ |
displayPage = 0; |
collectionInfo = findCollectionInfo(); |
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(); |
} |
if(++displayPage < collectionInfo.getTotalPages()) |
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; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/HasLastPageTag.java |
---|
0,0 → 1,16 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class HasLastPageTag |
extends ExistTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
return (info != null) && (info.getTotalPages() > 0); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/NoLastPageTag.java |
---|
0,0 → 1,13 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NoLastPageTag |
extends HasLastPageTag |
{ |
protected boolean condition() |
throws JspException |
{ |
return !super.condition(); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/NotCurrentPageTag.java |
---|
0,0 → 1,22 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
public class NotCurrentPageTag |
extends IterateSubtagBase |
{ |
public int doStartTag() throws JspException |
{ |
findParent(); |
if(parent.getCollectionInfo().getCurrentPage() != parent.getDisplayPage()) |
return EVAL_BODY_INCLUDE; |
else |
return SKIP_BODY; |
} |
public int doEndTag() throws JspException |
{ |
return EVAL_PAGE; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/LastPageTag.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import ak.hostadmiral.util.CollectionInfo; |
public class LastPageTag |
extends PageTagBase |
{ |
protected int getDisplayPage() |
throws JspException |
{ |
CollectionInfo info = getCollectionInfo(); |
if(info == null) |
return 0; |
else |
return info.getLastPage(); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/IterateSubtagBase.java |
---|
0,0 → 1,25 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.Tag; |
import javax.servlet.jsp.tagext.TagSupport; |
public abstract class IterateSubtagBase |
extends TagSupport |
{ |
protected PageIterateTag parent; |
protected void findParent() |
throws JspException |
{ |
Tag p = getParent(); |
while(p != null && !(p instanceof PageIterateTag)) |
p = p.getParent(); |
if(p == null) |
throw new JspException("This tag must be inside PageIterateTag"); |
parent = (PageIterateTag)p; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/list/DisplayPageTag.java |
---|
0,0 → 1,17 |
package ak.hostadmiral.core.taglib.list; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.util.ResponseUtils; |
public class DisplayPageTag |
extends IterateSubtagBase |
{ |
public int doStartTag() throws JspException |
{ |
findParent(); |
ResponseUtils.write(pageContext, Integer.toString(parent.getDisplayPage() + 1)); |
return SKIP_BODY; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/util/CollectionInfo.java |
---|
2,6 → 2,7 |
public class CollectionInfo |
{ |
/** total number of rows in list */ |
private int size; |
public int getSize() |
12,5 → 13,85 |
public void setSize(int size) |
{ |
this.size = size; |
recalc(); |
} |
/** current selected page */ |
private int currentPage; |
protected int normPage(int page) |
{ |
if(totalPages <= 0 || page <= 0) |
return 0; |
else if(page < totalPages) |
return page; |
else |
return (totalPages - 1); |
} |
public int getCurrentPage() |
{ |
return normPage(currentPage); |
} |
public void setCurrentPage(int currentPage) |
{ |
this.currentPage = currentPage; |
} |
/** number of rows on one page */ |
private int rowsPerPage; |
public int getRowsPerPage() |
{ |
return rowsPerPage; |
} |
public void setRowsPerPage(int rowsPerPage) |
{ |
this.rowsPerPage = rowsPerPage; |
recalc(); |
} |
/** total number of pages */ |
private int totalPages; |
public int getTotalPages() |
{ |
return totalPages; |
} |
public int getFirstPage() |
{ |
return 0; |
} |
public int getLastPage() |
{ |
return normPage(totalPages - 1); |
} |
public int getPrevPage() |
{ |
return normPage(currentPage - 1); |
} |
public int getNextPage() |
{ |
return normPage(currentPage + 1); |
} |
protected void recalc() |
{ |
if(rowsPerPage > 0) |
totalPages = (int)Math.ceil((double)size / rowsPerPage); |
} |
public void init(int size, int currentPage, int rowsPerPage) |
{ |
this.size = size; |
this.currentPage = currentPage; |
this.rowsPerPage = rowsPerPage; |
recalc(); |
} |
} |