1 53 54 106 107 package com.Yasna.forum.tags; 108 109 import java.io.*; 110 import javax.servlet.*; 111 import javax.servlet.jsp.*; 112 import javax.servlet.jsp.tagext.*; 113 import javax.servlet.http.*; 114 import com.Yasna.forum.tags.*; 115 116 149 public class RotateTag extends TagSupport 150 { 151 private RotateTag rt = null; 153 private int index = 0; 155 private int size = 0; 156 private int total = 0; 157 private boolean total_set = false; 158 159 164 public final int doStartTag() throws JspException 165 { 166 Boolean res; 167 168 rt = (RotateTag)pageContext.getAttribute(id, 170 PageContext.PAGE_SCOPE); 171 if( rt == null ) { 172 rt = this; 174 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 175 } else { 176 index = rt.getIndex(); 178 total = rt.getTotal(); 179 } 180 return EVAL_BODY_INCLUDE; 181 } 182 183 189 public final int doEndTag() throws JspException 190 { 191 index++; 192 if( index >= total ) 193 index = 0; 194 total_set = true; 195 rt.setIndex(index); 196 return EVAL_PAGE; 197 } 198 199 205 public final boolean myTurn() 206 { 207 if( !rt.equals(this) )return rt.myTurn(); 208 size++; 209 if( !total_set ) { 210 total++; 211 if( total == 1 ) 212 return true; 213 } else { 214 if( index == ((size-1)%total) ) 215 return true; 216 } 217 return false; 218 } 219 220 223 229 public final int getTotal() 230 { 231 return total; 232 } 233 234 240 public final int getIndex() 241 { 242 return index; 243 } 244 245 249 public final void setIndex(int v) 250 { 251 index = v; 252 } 253 } 254 | Popular Tags |