1 package de.jwi.jgallery.tags; 2 3 24 25 import java.io.IOException ; 26 27 import javax.servlet.jsp.JspException ; 28 import javax.servlet.jsp.JspTagException ; 29 import javax.servlet.jsp.tagext.BodyContent ; 30 import javax.servlet.jsp.tagext.BodyTagSupport ; 31 32 import de.jwi.jgallery.Folder; 33 import de.jwi.jgallery.GalleryException; 34 import de.jwi.jgallery.Image; 35 36 42 public class RowIteratorTag extends BodyTagSupport 43 { 44 45 private int cols; 46 47 private int imagesLeft; 48 49 private int currentImageNum; 50 51 private Folder folder; 52 53 int getColsLeft() 55 { 56 int n = Math.min(imagesLeft, cols); 57 imagesLeft -= n; 58 return n; 59 } 60 61 Image getNextImage() 63 throws GalleryException 64 { 65 return folder.getSubDirOrImage(currentImageNum++); 66 } 67 68 public int doStartTag() throws JspException 69 { 70 folder = (Folder) pageContext.getRequest().getAttribute( 71 "folder"); 72 73 if (null == folder) { throw new JspException ( 74 "no folder Attribute found in request"); } 75 76 imagesLeft = folder.getCurrentImagesPerPage(); 77 78 if (imagesLeft > 0) 79 { 80 cols = folder.getColsI(); 81 currentImageNum = folder.getImageNumI(); 82 83 return (EVAL_BODY_AGAIN); 84 } 85 else 86 { 87 return SKIP_BODY; 88 } 89 } 90 91 public int doAfterBody() throws JspTagException 92 { 93 BodyContent body = getBodyContent(); 94 try 95 { 96 body.writeOut(getPreviousOut()); 97 } 98 catch (IOException e) 99 { 100 throw new JspTagException ("IterationTag: " + e.getMessage()); 101 } 102 103 body.clearBody(); 104 if (imagesLeft > 0) 105 { 106 return EVAL_BODY_AGAIN; 107 } 108 else 109 { 110 return SKIP_BODY; 111 } 112 113 } 114 } 115 | Popular Tags |