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 java.io.*;
22 import javax.servlet.http.*;
23 import javax.servlet.jsp.*;
24 import net.sf.ginp.*;
25 import net.sf.ginp.config.ModelUtil;
26 import net.sf.ginp.config.Configuration;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 /**
31 * Get a table of Pictures.
32 *
33 *@author Doug Culnane
34 *@version $Revision: 303 $
35 */
36 public class GetPictures extends javax.servlet.jsp.tagext.TagSupport {
37
38 /**
39 *
40 */
41 private static final long serialVersionUID = -4525493921727086037L;
42 private int startAt = 0;
43 private int boderhorizontal = 50;
44 private int bodervertical = 50;
45 private int boderpicture = 10;
46 int columbs = 4;
47 int rows = 4;
48 private boolean showpages = false;
49 private int count;
50 private int end;
51 private String collAbsPath = "";
52 private String dateformatpattern = "";
53 private Picture pic;
54 private GinpModel model;
55 private String newrow = "\n\t</tr>\n\t<tr>";
56
57 private Log log = LogFactory.getLog(GetPictures.class);
58
59 /**
60 * Sets the borderhorizontal attribute of the GetPictures object
61 *
62 *@param i The new borderhorizontal value
63 */
64 public void setBoderhorizontal(int i) {
65 boderhorizontal = i;
66 }
67
68
69 /**
70 * Description of the Method
71 *
72 *@param b Description of the Parameter
73 */
74 public void setShowpages(boolean b) {
75 showpages = b;
76 }
77
78
79 /**
80 * Sets the bodervertical attribute of the GetPictures object
81 *
82 *@param i The new bodervertical value
83 */
84 public void setBodervertical(int i) {
85 bodervertical = i;
86 }
87
88
89 /**
90 * Sets the boderpicture attribute of the GetPictures object
91 *
92 *@param i The new boderpicture value
93 */
94 public void setBoderpicture(int i) {
95 boderpicture = i;
96 }
97
98
99 /**
100 * Sets the dateformatpattern attribute of the GetPictures object
101 *
102 *@param s The new dateformatpattern value
103 */
104 public void setDateformatpattern(String s) {
105 dateformatpattern = s;
106 }
107
108
109 /**
110 * Sets the newrow attribute of the GetPictures object
111 *
112 *@param s The new newrow value
113 */
114 public void setNewrow(String s) {
115 newrow = s;
116 }
117
118
119 /**
120 * Description of the Method
121 *
122 *@return Description of the Return Value
123 *@exception JspTagException Description of the Exception
124 */
125 public int doAfterBody() throws JspTagException {
126
127 boolean showPicture = true;
128
129 count++;
130
131
132 if ((showpages) && ((count - startAt) >= rows * columbs)) {
133 showPicture = false;
134 model.setPagePosition(count);
135 }
136
137
138 if (count >= end) {
139 showPicture = false;
140 }
141
142 if (showPicture) {
143
144 pic = new Picture(collAbsPath, model.getCollection().getPicture(count));
145
146 if (log.isDebugEnabled()) {
147 log.debug("doAfterBody() - filename: " + pic.getFileName());
148 }
149
150 setAttributes(pic);
151
152 if (((count - startAt) % columbs) == 0) {
153 try {
154 pageContext.getOut().write(newrow);
155 } catch (IOException ioe) {
156 log.error(ioe);
157 }
158 }
159 model.setPagePosition(count);
160 return EVAL_BODY_AGAIN;
161 } else {
162 return SKIP_BODY;
163 }
164 }
165
166
167
168 /**
169 * Description of the Method
170 *
171 *@return Description of the Return Value
172 *@exception JspException Description of the Exception
173 */
174 public int doEndTag()
175 throws JspException {
176 return EVAL_PAGE;
177 }
178
179
180
181 /**
182 * Description of the Method
183 *
184 *@return Description of the Return Value
185 *@exception JspException Description of the Exception
186 */
187 public int doStartTag() throws JspException {
188
189 try {
190 model = ModelUtil.getModel((HttpServletRequest) pageContext.getRequest());
191 } catch (Exception e) {
192 log.error(e);
193 throw new JspException(e);
194 }
195 columbs = (model.getPageWidth() - boderhorizontal) / (Configuration.getThumbSize() + boderpicture);
196 rows = (model.getPageHeight() - bodervertical) / (Configuration.getThumbSize() + boderpicture);
197
198 if (model.getCollection() != null) {
199
200 if (showpages) {
201 count = model.getPagePosition();
202
203
204 if (model.getPageOffset() == (-2)) {
205 count = count - (columbs * rows * 2);
206 model.setPageOffset(0);
207 }
208
209
210 if (count < 0) {
211 count = 0;
212 } else if (model.getCollection().getPictureLength() <= (count + 1)) {
213 count = model.getCollection().getPictureLength() - (columbs * rows);
214 if (count < 0) {
215 count = 0;
216 }
217 }
218 } else {
219 count = 0;
220 }
221
222 startAt = count;
223 if (model.getCollection().getPictureLength() > count) {
224
225 collAbsPath = model.getCollection().getRoot()
226 + model.getCollection().getPath();
227
228 if (model.getCurrCollectionId() == -1) {
229 return SKIP_BODY;
230 }
231 end = model.getCollection().getPictureLength();
232
233 pic = new Picture(collAbsPath, model.getCollection().getPicture(count));
234
235 if (log.isDebugEnabled()) {
236 log.debug("doStartTag() - filename: " + pic.getFileName());
237 }
238
239
240 setAttributes(pic);
241
242 return EVAL_BODY_INCLUDE;
243
244 }
245 return SKIP_BODY;
246 }
247 return SKIP_BODY;
248
249
250 }
251
252 /**
253 * Sets the page Context Attributes for the Picture
254 */
255 void setAttributes(Picture pic) {
256
257 pageContext.setAttribute("maxsize", "" + Configuration.getThumbSize());
258 pageContext.setAttribute("filename", pic.getFileName());
259 pageContext.setAttribute("date", pic.getDate(dateformatpattern, model.getLocale()));
260 pageContext.setAttribute("time", pic.getTime());
261 pageContext.setAttribute("number", "" + (count + 1));
262 pageContext.setAttribute("title", pic.getTitle());
263 pageContext.setAttribute("description", pic.getDescription(model.getLocale()));
264 pageContext.setAttribute("link", "ginpservlet?cmd=showpicture&colid="
265 + model.getCurrCollectionId() + "&path="
266 + model.getCollection().getPath()
267 + "&name=" + model.getCollection().getPicture(count));
268 pageContext.setAttribute("src",
269 ((HttpServletRequest) pageContext.getRequest()).getContextPath()
270 + "/ginppic?&name=" + model.getCollection().getPicture(count)
271 + "&maxsize=" + Configuration.getThumbSize());
272
273 }
274
275
276 /**
277 * Description of the Method
278 */
279 public void release() {
280
281 }
282
283 }
284
285