1 package org.jahia.deprecated.taglibs.pagination; 2 3 import java.io.IOException ; 4 import java.util.Iterator ; 5 6 import javax.servlet.jsp.JspException ; 7 import javax.servlet.jsp.JspTagException ; 8 import javax.servlet.jsp.tagext.BodyContent ; 9 import javax.servlet.jsp.tagext.BodyTagSupport ; 10 11 import org.jahia.data.containers.JahiaContainerList; 12 import org.jahia.data.containers.JahiaContainerListPagination; 13 import org.jahia.deprecated.taglibs.container.ContainerListTag; 14 15 25 26 public class CListPaginationTag extends BodyTagSupport { 27 28 private JahiaContainerListPagination cPagination = null; 29 private int pageNumber = 0; 30 private boolean isCurrentPage = false; 31 private Iterator iterator; 32 33 private int nbStepPerPage = -1; private String skipOnePageOnly = "true"; 36 private int startPageIndex = 0; 37 private int stopPageIndex = 0; 38 39 42 public int getNbStepPerPage(){ 43 return this.nbStepPerPage; 44 } 45 46 49 public void setNbStepPerPage( int nbStepPerPage ){ 50 this.nbStepPerPage = nbStepPerPage; 51 } 52 53 56 public String skipOnePageOnly(){ 57 return this.skipOnePageOnly; 58 } 59 60 63 public void setSkipOnePageOnly(String val){ 64 if ( val != null ){ 65 this.skipOnePageOnly = val.toLowerCase(); 66 } 67 } 68 69 72 public int getPageNumber(){ 73 return this.pageNumber; 74 } 75 76 79 public boolean isCurrentPage(){ 80 return isCurrentPage; 81 } 82 83 86 public int getStopPageIndex(){ 87 return this.stopPageIndex; 88 } 89 90 93 public int getStartPageIndex(){ 94 return this.startPageIndex; 95 } 96 97 public int doStartTag() { 98 100 ContainerListTag containerListTag = (ContainerListTag) findAncestorWithClass(this, ContainerListTag.class); 102 if (containerListTag != null && !containerListTag.isDeclarationPass()) { 103 JahiaContainerList cList = containerListTag.getContainerList(); 104 if ( cList != null ) 105 { 106 cPagination = cList.getCtnListPagination(); 107 if ( cPagination != null && cPagination.isValid() ) 108 { 109 if ( cPagination.getNbPages()==1 && this.skipOnePageOnly.equals("true") ){ 110 return SKIP_BODY; 111 } 112 if ( this.nbStepPerPage<=0 ){ 113 this.startPageIndex = 1; 114 this.stopPageIndex = cPagination.getNbPages(); 115 this.pageNumber =1; 116 } else { 117 if ( cPagination.getCurrentPageIndex()<=this.nbStepPerPage ){ 118 this.startPageIndex = 1; 119 this.stopPageIndex = this.nbStepPerPage; 120 } else { 121 if ( (cPagination.getCurrentPageIndex()%this.nbStepPerPage)==0 ){ 122 this.startPageIndex = ( cPagination.getCurrentPageIndex() - this.nbStepPerPage ) + 1; 123 } else { 124 this.startPageIndex = cPagination.getCurrentPageIndex() - ( cPagination.getCurrentPageIndex() % this.nbStepPerPage ) + 1; 125 } 126 this.stopPageIndex = this.startPageIndex + this.nbStepPerPage-1; 127 } 128 } 129 iterator = cPagination.getPages().iterator(); 130 while (iterator.hasNext() && (this.pageNumber<this.startPageIndex-1) ){ 131 iterator.next(); 132 this.pageNumber +=1; 133 } 134 if ( iterator.hasNext() ){ 135 Integer I = (Integer )iterator.next(); 136 this.pageNumber = I.intValue(); 137 this.isCurrentPage = ( this.pageNumber == cPagination.getCurrentPageIndex() ); 138 return EVAL_BODY_BUFFERED; 139 } else { 140 return SKIP_BODY; 141 } 142 } 143 } 144 } 145 return SKIP_BODY; 146 } 147 148 149 public int doAfterBody() throws JspTagException { 150 BodyContent body = getBodyContent(); 151 try { 152 body.writeOut(getPreviousOut()); 153 } catch (IOException e) { 154 throw new JspTagException ("CListPaginationTag.doAfterBody : " + 155 e.getMessage()); 156 } 157 158 body.clearBody(); 160 if (iterator.hasNext() && (this.pageNumber<this.stopPageIndex) ) 161 { 162 Integer I = (Integer )iterator.next(); 163 this.pageNumber = I.intValue(); 164 this.isCurrentPage = ( this.pageNumber == cPagination.getCurrentPageIndex() ); 165 return EVAL_BODY_BUFFERED; 166 } 167 return SKIP_BODY; 168 } 169 170 public int doEndTag() throws JspException { 171 cPagination = null; 174 pageNumber = 0; 175 isCurrentPage = false; 176 Iterator iterator = null; 177 178 nbStepPerPage = -1; skipOnePageOnly = "true"; 181 startPageIndex = 0; 182 stopPageIndex = 0; 183 return EVAL_PAGE; 184 } 185 186 187 } | Popular Tags |