1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.ginp.tags;
20
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.jsp.JspException;
23 import javax.servlet.jsp.JspTagException;
24
25 import net.sf.ginp.GinpModel;
26 import net.sf.ginp.Picture;
27 import net.sf.ginp.config.ModelUtil;
28 import net.sf.ginp.config.Configuration;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 /**
33 * For use to display a film strip of the mini thumbnails around the current
34 * picture. This can be a nice navigation aid.
35 *
36 *@author Doug Culnane
37 *@version $Revision: 303 $
38 */
39 public class NavFilmStrip extends javax.servlet.jsp.tagext.TagSupport {
40
41 /**
42 *
43 */
44 private static final long serialVersionUID = -549406121527380761L;
45 private int boderhorizontal = 50;
46 private int boderpicture = 10;
47 private String collAbsPath = "";
48 private int count;
49 private String dateformatpattern = "";
50 private int end;
51 private GinpModel model;
52 private Picture pic;
53 private Log log = LogFactory.getLog(NavFilmStrip.class);
54
55
56 /**
57 * Sets the borderhorizontal attribute of the GetPictures object
58 *
59 *@param i The new borderhorizontal value
60 */
61 public void setBoderhorizontal(int i) {
62 boderhorizontal = i;
63 }
64
65
66 /**
67 * Sets the boderpicture attribute of the GetPictures object
68 *
69 *@param i The new boderpicture value
70 */
71 public void setBoderpicture(int i) {
72 boderpicture = i;
73 }
74
75
76 /**
77 * Sets the dateformatpattern attribute of the GetPictures object
78 *
79 *@param s The new dateformatpattern value
80 */
81 public void setDateformatpattern(String s) {
82 dateformatpattern = s;
83 }
84
85
86 /**
87 * Description of the Method
88 *
89 *@return Description of the Return Value
90 *@exception JspTagException Description of the Exception
91 */
92 public int doAfterBody() throws JspTagException {
93
94 count++;
95
96 if (count < end) {
97
98 pic = new Picture(collAbsPath, model.getCollection().getPicture(count));
99
100
101 pageContext.setAttribute("filename", pic.getFileName());
102 pageContext.setAttribute("date", pic.getDate(dateformatpattern, model.getLocale()));
103 pageContext.setAttribute("time", pic.getTime());
104 pageContext.setAttribute("number", "" + (count + 1));
105 pageContext.setAttribute("title", pic.getTitle());
106 pageContext.setAttribute("description", pic.getDescription(model.getLocale()));
107
108 pageContext.setAttribute("link",
109 "ginpservlet?cmd=showpicture&colid="
110 + model.getCurrCollectionId() + "&path="
111 + model.getCollection().getPath() + "&name="
112 + model.getCollection().getPicture(count));
113
114 pageContext.setAttribute("src",
115 ((HttpServletRequest) pageContext.getRequest()).getContextPath()
116 + "/ginppic?name=" + model.getCollection().getPicture(count)
117 + "&maxsize=" + Configuration.getFilmStripThumbSize());
118
119 model.setPagePosition(count);
120 return EVAL_BODY_AGAIN;
121 } else {
122 return SKIP_BODY;
123 }
124 }
125
126
127
128 /**
129 * Description of the Method
130 *
131 *@return Description of the Return Value
132 *@exception JspException Description of the Exception
133 */
134 public int doEndTag()
135 throws JspException {
136 return EVAL_PAGE;
137 }
138
139
140
141 /**
142 * Description of the Method
143 *
144 *@return Description of the Return Value
145 *@exception JspException Description of the Exception
146 */
147 public int doStartTag() throws JspException {
148
149 try {
150 model = ModelUtil.getModel((HttpServletRequest) pageContext.getRequest());
151 } catch (Exception e) {
152 log.error(e);
153 throw new JspException(e);
154 }
155 if (model.getCollection() != null) {
156
157 count = 0;
158 int columbs = (model.getPageWidth() - boderhorizontal)
159 / (Configuration.getFilmStripThumbSize() + boderpicture);
160
161 String[] picNames = model.getCollection().getPictures();
162 String currPic = ((HttpServletRequest)
163 pageContext.getRequest()).getParameter("name");
164
165 for (int i = 0; i < picNames.length; i++) {
166 if (picNames[i].equals(currPic)) {
167 count = i - (columbs / 2) + 1;
168 if (count < 0) {
169 count = 0;
170 }
171 }
172 }
173 end = count + columbs;
174
175
176 if (end > picNames.length) {
177 count = picNames.length - columbs;
178 end = picNames.length;
179 if (count < 0) {
180 count = 0;
181 }
182 }
183
184 if (end > count) {
185
186
187
188
189
190 collAbsPath = model.getCollection().getRoot()
191 + model.getCollection().getPath();
192
193 pageContext.setAttribute("maxsize", "" + Configuration.getFilmStripThumbSize());
194
195 pic = new Picture(collAbsPath, model.getCollection().getPicture(count));
196
197
198 pageContext.setAttribute("filename", pic.getFileName());
199 pageContext.setAttribute("date", pic.getDate(dateformatpattern, model.getLocale()));
200 pageContext.setAttribute("time", pic.getTime());
201 pageContext.setAttribute("number", "" + (count + 1));
202 pageContext.setAttribute("title", pic.getTitle());
203 pageContext.setAttribute("description", pic.getDescription(model.getLocale()));
204
205 pageContext.setAttribute("link", "ginpservlet?cmd=showpicture&colid="
206 + model.getCurrCollectionId() + "&path="
207 + model.getCollection().getPath() + "&name="
208 + model.getCollection().getPicture(count));
209 pageContext.setAttribute("src", ((HttpServletRequest) pageContext.getRequest()).getContextPath()
210 + "/ginppic?name=" + model.getCollection().getPicture(count)
211 + "&maxsize=" + Configuration.getFilmStripThumbSize());
212
213 return EVAL_BODY_INCLUDE;
214 } else {
215 return SKIP_BODY;
216 }
217 } else {
218 return SKIP_BODY;
219 }
220
221 }
222
223
224 /**
225 * Description of the Method
226 */
227 public void release() {
228 }
229
230 }
231
232