📄 clistpaginationtag.java
字号:
package org.jahia.taglibs.pagination;import org.jahia.data.JahiaData;import org.jahia.data.containers.JahiaContainerList;import org.jahia.data.containers.JahiaContainerListPagination;import org.jahia.exceptions.JahiaException;import org.jahia.services.usermanager.JahiaUser;import org.jahia.taglibs.container.ContainerListTag;import org.jahia.taglibs.util.Utils;import org.jahia.utils.JahiaConsole;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;/** * Lookup for the ContainerListPagination instance of the enclosing ContainerListTag and iterate through the list of paginated pages. * * <pre> * <<next -->1 2 3<-- next>> * </pre> * * @author NK * @version 1.0 */public class CListPaginationTag extends BodyTagSupport { private JahiaContainerListPagination cPagination = null; private int pageNumber = 0; private boolean isCurrentPage = false; private Iterator iterator; private int nbStepPerPage = -1; // by default, display all page step. private String skipOnePageOnly = "true"; // by default skip displaying pagination if there is only one page private int startPageIndex = 0; private int stopPageIndex = 0; /** * Return the number of step per displayed page. */ public int getNbStepPerPage(){ return this.nbStepPerPage; } /** * Set the number of step per displayed page. */ public void setNbStepPerPage( int nbStepPerPage ){ this.nbStepPerPage = nbStepPerPage; } /** * Return the value of the status skipOnePageOnly. */ public String skipOnePageOnly(){ return this.skipOnePageOnly; } /** * Set the value of the status skipOnePageOnly ( true/false ). */ public void setSkipOnePageOnly(String val){ if ( val != null ){ this.skipOnePageOnly = val.toLowerCase(); } } /** * The next iterated page number from the list of paginated pages. */ public int getPageNumber(){ return this.pageNumber; } /** * Return true if the pageIndex is equals to the current displayed page. */ public boolean isCurrentPage(){ return isCurrentPage; } /** * Return the stop page index. */ public int getStopPageIndex(){ return this.stopPageIndex; } /** * Return the start page index. */ public int getStartPageIndex(){ return this.startPageIndex; } public int doStartTag() { //JahiaConsole.println("CListPaginationTag.doStartTag", "Started"); // gets the enclosing tag ContainerListTag ContainerListTag containerListTag = (ContainerListTag) findAncestorWithClass(this, ContainerListTag.class); if (containerListTag != null && !containerListTag.isDeclarationPass()) { JahiaContainerList cList = containerListTag.getContainerList(); if ( cList != null ) { cPagination = cList.getCtnListPagination(); if ( cPagination != null && cPagination.isValid() ) { if ( cPagination.getNbPages()==1 && this.skipOnePageOnly.equals("true") ){ return SKIP_BODY; } if ( this.nbStepPerPage<=0 ){ this.startPageIndex = 1; this.stopPageIndex = cPagination.getNbPages(); this.pageNumber =1; } else { if ( cPagination.getCurrentPageIndex()<=this.nbStepPerPage ){ this.startPageIndex = 1; this.stopPageIndex = this.nbStepPerPage; } else { if ( (cPagination.getCurrentPageIndex()%this.nbStepPerPage)==0 ){ this.startPageIndex = ( cPagination.getCurrentPageIndex() - this.nbStepPerPage ) + 1; } else { this.startPageIndex = cPagination.getCurrentPageIndex() - ( cPagination.getCurrentPageIndex() % this.nbStepPerPage ) + 1; } this.stopPageIndex = this.startPageIndex + this.nbStepPerPage-1; } } iterator = cPagination.getPages().iterator(); while (iterator.hasNext() && (this.pageNumber<this.startPageIndex-1) ){ iterator.next(); this.pageNumber +=1; } if ( iterator.hasNext() ){ Integer I = (Integer)iterator.next(); this.pageNumber = I.intValue(); this.isCurrentPage = ( this.pageNumber == cPagination.getCurrentPageIndex() ); return EVAL_BODY_BUFFERED; } else { return SKIP_BODY; } } } } return SKIP_BODY; } public int doAfterBody() throws JspTagException { BodyContent body = getBodyContent(); try { body.writeOut(getPreviousOut()); } catch (IOException e) { throw new JspTagException("CListPaginationTag.doAfterBody : " + e.getMessage()); } // clear up so the next time the body content is empty body.clearBody(); if (iterator.hasNext() && (this.pageNumber<this.stopPageIndex) ) { Integer I = (Integer)iterator.next(); this.pageNumber = I.intValue(); this.isCurrentPage = ( this.pageNumber == cPagination.getCurrentPageIndex() ); return EVAL_BODY_BUFFERED; } return SKIP_BODY; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -