1 package de.jwi.jgallery.tags; 2 3 21 22 import java.io.IOException ; 23 24 import javax.servlet.jsp.JspTagException ; 25 import javax.servlet.jsp.tagext.BodyContent ; 26 import javax.servlet.jsp.tagext.BodyTagSupport ; 27 28 import de.jwi.jgallery.Folder; 29 30 35 public class IndexIteratorTag extends BodyTagSupport 36 { 37 38 public static final String CURRENTINDEX = "index"; 39 40 private int totalIndexes; 41 42 private int index; 43 44 private Folder folder; 45 46 private IndexIteratorCursor cursor; 47 48 private void updateCursor() 49 { 50 int i = totalIndexes - index + 1; 51 52 String page = folder.getCalculatedIndexPage(i); 53 String number = Integer.toString(i); 54 String selected = folder.getIndexNum().equals(number) ? "selected" : ""; 55 56 cursor.setPage(page); 57 cursor.setNumber(number); 58 cursor.setSelected(selected); 59 } 60 61 public int doStartTag() throws JspTagException 62 { 63 folder = (Folder) pageContext.getRequest().getAttribute("folder"); 64 65 if (null == folder) { throw new JspTagException ( 66 "no folder Attribute found in request"); } 67 68 int i = 1; 69 try 70 { 71 i = Integer.parseInt(folder.getTotalIndexes()); 72 } 73 catch (NumberFormatException e1) 74 { 75 } 77 index = totalIndexes = i; 78 79 if (index > 0) 80 { 81 cursor = new IndexIteratorCursor(); 82 83 updateCursor(); 84 pageContext.setAttribute(CURRENTINDEX, cursor); 85 86 index--; 87 88 return (EVAL_BODY_AGAIN); 89 } 90 else 91 { 92 return SKIP_BODY; 93 } 94 } 95 96 public int doAfterBody() throws JspTagException 97 { 98 BodyContent body = getBodyContent(); 99 try 100 { 101 body.writeOut(getPreviousOut()); 102 } 103 catch (IOException e) 104 { 105 throw new JspTagException ("IterationTag: " + e.getMessage()); 106 } 107 108 body.clearBody(); 109 if (index > 0) 110 { 111 updateCursor(); 112 pageContext.setAttribute(CURRENTINDEX, cursor); 113 114 index--; 115 116 return (EVAL_BODY_AGAIN); 117 } 118 else 119 { 120 return SKIP_BODY; 121 } 122 } 123 } 124 | Popular Tags |