KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > frontend > photoalbum > CmsPhotoAlbumBean


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/photoalbum/CmsPhotoAlbumBean.java,v $
3  * Date : $Date: 2006/03/27 14:52:22 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.frontend.photoalbum;
33
34 import org.opencms.file.CmsPropertyDefinition;
35 import org.opencms.file.CmsResource;
36 import org.opencms.file.CmsResourceFilter;
37 import org.opencms.file.types.CmsResourceTypeImage;
38 import org.opencms.i18n.CmsEncoder;
39 import org.opencms.i18n.CmsMessages;
40 import org.opencms.jsp.CmsJspActionElement;
41 import org.opencms.main.CmsException;
42 import org.opencms.main.CmsLog;
43 import org.opencms.util.CmsStringUtil;
44
45 import java.io.IOException JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.List JavaDoc;
48
49 import javax.servlet.http.HttpServletRequest JavaDoc;
50 import javax.servlet.http.HttpServletResponse JavaDoc;
51 import javax.servlet.jsp.PageContext JavaDoc;
52
53 import org.apache.commons.logging.Log;
54
55 /**
56  * Provides methods to generate frontend views of a photo album using a XML Content configuration file.<p>
57  *
58  * @author Andreas Zahner
59  *
60  * @version $Revision: 1.2 $
61  *
62  * @since 6.1.3
63  */

64 public class CmsPhotoAlbumBean extends CmsJspActionElement {
65
66     /** Request parameter value for the album action: show detail view. */
67     public static final int ACTION_DETAIL = 1;
68
69     /** Request parameter value for the album action: show original image. */
70     public static final int ACTION_ORIGINAL = 2;
71
72     /** Request parameter value for the album action: show thumbnail view. */
73     public static final int ACTION_THUMBNAIL = 0;
74
75     /** Request parameter name for the action parameter. */
76     public static final String JavaDoc PARAM_ACTION = "action";
77
78     /** Request parameter name for the image parameter. */
79     public static final String JavaDoc PARAM_IMAGE = "image";
80
81     /** Request parameter name for the album page parameter. */
82     public static final String JavaDoc PARAM_PAGE = "thumbpage";
83
84     /** Request parameter value for the album action: show detail view. */
85     public static final String JavaDoc VALUE_ACTION_DETAIL = "detail";
86
87     /** Request parameter value for the album action: show original image. */
88     public static final String JavaDoc VALUE_ACTION_ORIGINAL = "original";
89
90     /** Request parameter value for the album action: show thumbnail view. */
91     public static final String JavaDoc VALUE_ACTION_THUMBNAIL = "thumbnail";
92
93     /** The log object for this class. */
94     private static final Log LOG = CmsLog.getLog(CmsPhotoAlbumBean.class);
95
96     /** The list of all photos to display in the photo album. */
97     private List JavaDoc m_albumPhotos;
98
99     /** Holds possible configuration error messages. */
100     private List JavaDoc m_configErrors;
101
102     /** The photo album configuration. */
103     private CmsPhotoAlbumConfiguration m_configuration;
104
105     /** The current page to display for the thumbnail view. */
106     private int m_currentPage;
107
108     /** The display action to determine the view to generate. */
109     private int m_displayAction;
110
111     /** The messages to use. */
112     private CmsMessages m_messages;
113
114     /** The number of pages to display for the thumbnail view. */
115     private int m_pageCount;
116
117     /** The number of photos to display on a single thumbnail overview page. */
118     private int m_photosPerPage;
119
120     /** The CSS style object that is used to format the photo album output. */
121     private CmsPhotoAlbumStyle m_style;
122
123     /**
124      * Constructor, creates the necessary photo album configuration objects.<p>
125      *
126      * @param context the JSP page context object
127      * @param req the JSP request
128      * @param res the JSP response
129      */

130     public CmsPhotoAlbumBean(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
131
132         this(context, req, res, null);
133     }
134
135     /**
136      * Constructor, creates the necessary photo album configuration objects using a given configuration file URI.<p>
137      *
138      * @param context the JSP page context object
139      * @param req the JSP request
140      * @param res the JSP response
141      * @param configUri URI of the photo album configuration file, if not provided, current URI is used for configuration
142      */

143     public CmsPhotoAlbumBean(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, String JavaDoc configUri) {
144
145         super(context, req, res);
146         init(configUri);
147     }
148
149     /**
150      * Builds the HTML to display the photo album.<p>
151      *
152      * @return the HTML to display the photo album
153      * @throws IOException if writing the output fails
154      */

155     public String JavaDoc displayAlbum() throws IOException JavaDoc {
156
157         // show eventual configuration errors
158
buildHtmlConfigurationErrors();
159         // show selected album view
160
switch (getDisplayAction()) {
161             case ACTION_DETAIL:
162                 return buildHtmlViewDetail();
163             case ACTION_ORIGINAL:
164                 return "";
165             case ACTION_THUMBNAIL:
166             default:
167                 return buildHtmlViewThumbNail();
168         }
169     }
170
171     /**
172      * Returns the list of all photos to display in the photo album.<p>
173      *
174      * @return the list of all photos to display in the photo album
175      */

176     public List JavaDoc getAlbumPhotos() {
177
178         if (m_albumPhotos == null) {
179             CmsResourceFilter filter = CmsResourceFilter.DEFAULT.addRequireType(CmsResourceTypeImage.getStaticTypeId());
180             try {
181                 m_albumPhotos = getCmsObject().readResources(getConfiguration().getVfsPathGallery(), filter, false);
182             } catch (CmsException e) {
183                 // create empty photo list
184
m_albumPhotos = new ArrayList JavaDoc(0);
185                 // log error
186
if (LOG.isErrorEnabled()) {
187                     LOG.error(Messages.get().getBundle().key(
188                         Messages.LOG_ERR_IMAGEFOLDER_NOT_FOUND_1,
189                         getConfiguration().getVfsPathGallery()));
190                 }
191                 addConfigError(m_messages.key(
192                     Messages.LOG_ERR_IMAGEFOLDER_NOT_FOUND_1,
193                     getConfiguration().getVfsPathGallery()));
194             }
195         }
196         return m_albumPhotos;
197     }
198
199     /**
200      * Returns the photo album configuration.<p>
201      *
202      * @return the photo album configuration
203      */

204     public CmsPhotoAlbumConfiguration getConfiguration() {
205
206         return m_configuration;
207     }
208
209     /**
210      * Returns the current page to display for the thumbnail view.<p>
211      *
212      * @return the current page to display for the thumbnail view
213      */

214     public int getCurrentPage() {
215
216         return m_currentPage;
217     }
218
219     /**
220      * Returns the display action to determine the view to generate.<p>
221      *
222      * @return the display action to determine the view to generate
223      */

224     public int getDisplayAction() {
225
226         return m_displayAction;
227     }
228
229     /**
230      * Returns the number of pages to display for the thumbnail view.<p>
231      *
232      * @return the number of pages to display for the thumbnail view
233      */

234     public int getPageCount() {
235
236         return m_pageCount;
237     }
238
239     /**
240      * Returns the number of photos to display on a single thumbnail overview page.<p>
241      *
242      * @return the number of photos to display on a single thumbnail overview page
243      */

244     public int getPhotosPerPage() {
245
246         return m_photosPerPage;
247     }
248
249     /**
250      * Returns the CSS style object that is used to format the photo album output.<p>
251      *
252      * @return the CSS style object that is used to format the photo album output
253      */

254     public CmsPhotoAlbumStyle getStyle() {
255
256         return m_style;
257     }
258
259     /**
260      * Initializes the photo album configuration and determines the display action.<p>
261      *
262      * @param configUri URI of the photo album configuration file, if not provided, current URI is used for configuration
263      */

264     public void init(String JavaDoc configUri) {
265
266         // set messages
267
m_messages = Messages.get().getBundle(getRequestContext().getLocale());
268         // initialize empty list of configuration errors
269
setConfigErrors(new ArrayList JavaDoc());
270         // initialize the photo album CSS styles
271
setStyle(new CmsPhotoAlbumStyle());
272         // initialize the photo album configuration
273
try {
274             setConfiguration(new CmsPhotoAlbumConfiguration(this, configUri));
275         } catch (Exception JavaDoc e) {
276             // set empty configuration
277
setConfiguration(new CmsPhotoAlbumConfiguration());
278             if (e instanceof CmsException) {
279                 // for Cms exceptions, show detailed error message
280
addConfigError(((CmsException)e).getLocalizedMessage(getRequestContext().getLocale()));
281             } else {
282                 addConfigError(e.getLocalizedMessage());
283             }
284         }
285         // determine the album view to display depending on request parameter
286
String JavaDoc action = getRequest().getParameter(PARAM_ACTION);
287         if (VALUE_ACTION_DETAIL.equals(action)) {
288             // show the detail view
289
setDisplayAction(ACTION_DETAIL);
290         } else if (VALUE_ACTION_ORIGINAL.equals(action)) {
291             // show the original image
292
setDisplayAction(ACTION_ORIGINAL);
293         } else {
294             // default action: show the thumbnail overview
295
setDisplayAction(ACTION_THUMBNAIL);
296         }
297         // determine the necessary page data to build navigation elements
298
calculatePageData();
299     }
300
301     /**
302      * Sets the photo album configuration.<p>
303      *
304      * @param configuration the photo album configuration
305      */

306     public void setConfiguration(CmsPhotoAlbumConfiguration configuration) {
307
308         m_configuration = configuration;
309     }
310
311     /**
312      * Sets the CSS style object that is used to format the photo album output.<p>
313      *
314      * @param style the CSS style object that is used to format the photo album output
315      */

316     public void setStyle(CmsPhotoAlbumStyle style) {
317
318         m_style = style;
319     }
320
321     /**
322      * Adds an error to the list of configuration errors.<p>
323      *
324      * @param configError error to add to the list of configuration errors
325      */

326     protected void addConfigError(String JavaDoc configError) {
327
328         m_configErrors.add(configError);
329     }
330
331     /**
332      * Returns the HTML for the photo album title.<p>
333      *
334      * @return the HTML for the photo album title
335      */

336     protected String JavaDoc buildHtmlAlbumTitle() {
337
338         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getConfiguration().getAlbumTitle())) {
339             // show the title
340
StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
341             result.append("<h1");
342             result.append(getStyle().getClassPageTitle());
343             result.append(">");
344             result.append(getConfiguration().getAlbumTitle());
345             result.append("</h1>\n");
346             return result.toString();
347         }
348         return "";
349     }
350
351     /**
352      * Writes the HTML for the configuration error output.<p>
353      *
354      * Writes the found configuration errors directly to the JSP writer.<p>
355      *
356      * @throws IOException if writing the output fails
357      */

358     protected void buildHtmlConfigurationErrors() throws IOException JavaDoc {
359
360         if (!getRequestContext().currentProject().isOnlineProject() && getConfigErrors().size() > 0) {
361             // configuration error(s) found, show them in offline projects
362
getJspContext().getOut().print("<h1>");
363             getJspContext().getOut().print(m_messages.key(Messages.GUI_CONFIG_ERRORS_HEADLINE_0));
364             getJspContext().getOut().print("</h1>");
365             getJspContext().getOut().print("<p>");
366             // loop error messages
367
for (int i = 0; i < getConfigErrors().size(); i++) {
368                 if (i > 0) {
369                     getJspContext().getOut().println("<br>");
370                 }
371                 getJspContext().getOut().print(getConfigErrors().get(i));
372             }
373             getJspContext().getOut().print("</p>");
374         }
375     }
376
377     /**
378      * Returns the HTML for the image navigation on the photo album detail page.<p>
379      *
380      * @param currentNavigationPosition the current navigation position to display the navigation
381      * @param photoIndex the index of the photo to display
382      * @param photo the photo to display as CmsResource object
383      * @return the HTML for the image navigation on the photo album detail page
384      */

385     protected String JavaDoc buildHtmlImageNavigation(String JavaDoc currentNavigationPosition, int photoIndex, CmsResource photo) {
386
387         if (!checkNavigationPosition(currentNavigationPosition)) {
388             // wrong position to insert the navigation elements, do not show navigation at this position
389
return "";
390         }
391
392         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
393         StringBuffer JavaDoc link = new StringBuffer JavaDoc(256);
394         result.append("<tr>\n\t<td");
395         result.append(getStyle().getClassNavigation());
396         result.append(getConfiguration().getStyleAlignAttribute(getConfiguration().getAlignNavigation()));
397         result.append(">");
398         if (photoIndex > 0) {
399             // build the "Back" link
400
result.append("<a");
401             result.append(getStyle().getClassLink());
402             result.append(" HREF=\"");
403             link.append(getRequestContext().getUri());
404             link.append("?");
405             link.append(PARAM_ACTION).append("=").append(VALUE_ACTION_DETAIL);
406             link.append("&");
407             link.append(PARAM_IMAGE).append("=").append(photoIndex - 1);
408             result.append(link(link.toString()));
409             result.append("\">");
410             result.append(m_messages.key(Messages.GUI_NAVIGATION_BACK_0));
411             result.append("</a>");
412             result.append(" - ");
413         } else {
414             result.append(fillNavSpaces(m_messages.key(Messages.GUI_NAVIGATION_BACK_0) + " - "));
415         }
416         // build the image index information
417
Object JavaDoc[] args = new Object JavaDoc[] {new Integer JavaDoc(photoIndex + 1), new Integer JavaDoc(getAlbumPhotos().size())};
418         result.append(m_messages.key(Messages.GUI_DETAIL_IMAGEINFO_2, args));
419         if (photoIndex < (getAlbumPhotos().size() - 1)) {
420             // build the "Next" link
421
result.append(" - ");
422             result.append("<a");
423             result.append(getStyle().getClassLink());
424             result.append(" HREF=\"");
425             link = new StringBuffer JavaDoc(256);
426             link.append(getRequestContext().getUri());
427             link.append("?");
428             link.append(PARAM_ACTION).append("=").append(VALUE_ACTION_DETAIL);
429             link.append("&");
430             link.append(PARAM_IMAGE).append("=").append(photoIndex + 1);
431             result.append(link(link.toString()));
432             result.append("\">");
433             result.append(m_messages.key(Messages.GUI_NAVIGATION_NEXT_0));
434             result.append("</a>");
435         } else {
436             result.append(fillNavSpaces(" - " + m_messages.key(Messages.GUI_NAVIGATION_NEXT_0)));
437         }
438         result.append("<br>");
439
440         // build the link to the thumbnail overview
441
int thumbPage = 1;
442         if (getConfiguration().showPageNavigation()) {
443             // calculate the page to show
444
thumbPage = (photoIndex / getPhotosPerPage()) + 1;
445         }
446         result.append("<a");
447         result.append(getStyle().getClassLink());
448         result.append(" HREF=\"");
449         link = new StringBuffer JavaDoc(256);
450         link.append(getRequestContext().getUri());
451         link.append("?");
452         link.append(PARAM_ACTION).append("=").append(VALUE_ACTION_THUMBNAIL);
453         link.append("&");
454         link.append(PARAM_PAGE).append("=").append(thumbPage);
455         result.append(link(link.toString()));
456         result.append("\">");
457         result.append(m_messages.key(Messages.GUI_NAVIGATION_OVERVIEW_0));
458         result.append("</a>");
459
460         // build the link to the original image if configured
461
if (getConfiguration().showDetailOriginalLink()) {
462             result.append(" - <a");
463             result.append(getStyle().getClassLink());
464             result.append(" HREF=\"");
465             result.append(link(getCmsObject().getSitePath(photo)));
466             result.append("\" target=\"originalphoto\">");
467             result.append(m_messages.key(Messages.GUI_NAVIGATION_ORIGINAL_0));
468             result.append("</a>");
469         }
470         result.append("</td>\n</tr>\n");
471
472         return result.toString();
473     }
474
475     /**
476      * Returns the HTML for the page navigation on the thumbnail overview pages.<p>
477      *
478      * @param currentNavigationPosition the current navigation position to display the navigation
479      * @return the HTML for the page navigation on the thumbnail overview pages
480      */

481     protected String JavaDoc buildHtmlPageNavigation(String JavaDoc currentNavigationPosition) {
482
483         if (!checkNavigationPosition(currentNavigationPosition)) {
484             // wrong position to insert the navigation elements, do not show navigation at this position
485
return "";
486         }
487
488         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
489
490         if (getConfiguration().showPageNavigation() && getPageCount() > 1) {
491             // show navigation and number of pages greater than 1
492
result.append("<tr>\n\t<td colspan=\"");
493             result.append(getConfiguration().getThumbCols());
494             result.append("\"");
495             result.append(getStyle().getClassNavigation());
496             result.append(getConfiguration().getStyleAlignAttribute(getConfiguration().getAlignNavigation()));
497             result.append(">");
498             StringBuffer JavaDoc link = new StringBuffer JavaDoc(256);
499             if (getCurrentPage() > 1) {
500                 // build the "Back" link
501
result.append("<a");
502                 result.append(getStyle().getClassLink());
503                 result.append(" HREF=\"");
504                 link.append(getRequestContext().getUri());
505                 link.append("?");
506                 link.append(PARAM_ACTION).append("=").append(VALUE_ACTION_THUMBNAIL);
507                 link.append("&");
508                 link.append(PARAM_PAGE).append("=").append(getCurrentPage() - 1);
509                 result.append(link(link.toString()));
510                 result.append("\">");
511                 result.append(m_messages.key(Messages.GUI_NAVIGATION_BACK_0));
512                 result.append("</a>");
513                 result.append(" - ");
514             } else {
515                 result.append(fillNavSpaces(m_messages.key(Messages.GUI_NAVIGATION_BACK_0) + " - "));
516             }
517             // build the page index information
518
result.append(m_messages.key(Messages.GUI_THUMB_PAGEINFO_2, new Integer JavaDoc(getCurrentPage()), new Integer JavaDoc(
519                 getPageCount())));
520             if (getCurrentPage() < getPageCount()) {
521                 // build the "Next" link
522
result.append(" - ");
523                 result.append("<a class=\"");
524                 result.append(getStyle().getClassLink());
525                 result.append("\" HREF=\"");
526                 link = new StringBuffer JavaDoc(256);
527                 link.append(getRequestContext().getUri());
528                 link.append("?");
529                 link.append(PARAM_ACTION).append("=").append(VALUE_ACTION_THUMBNAIL);
530                 link.append("&");
531                 link.append(PARAM_PAGE).append("=").append(getCurrentPage() + 1);
532                 result.append(link(link.toString()));
533                 result.append("\">");
534                 result.append(m_messages.key(Messages.GUI_NAVIGATION_NEXT_0));
535                 result.append("</a>");
536             } else {
537                 result.append(fillNavSpaces(" - " + m_messages.key(Messages.GUI_NAVIGATION_NEXT_0)));
538             }
539             result.append("</td>\n</tr>\n");
540         }
541         return result.toString();
542     }
543
544     /**
545      * Returns the HTML for a text row on the thumbnail overview page of the photo album.<p>
546      *
547      * @param text the text to display in the row
548      * @return the HTML for a text row on the thumbnail overview page of the photo album
549      */

550     protected String JavaDoc buildHtmlThumbTextRow(String JavaDoc text) {
551
552         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(text)) {
553             StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
554             result.append("<tr>\n\t<td colspan=\"");
555             result.append(getConfiguration().getThumbCols());
556             result.append("\"");
557             result.append(getStyle().getClassThumbText());
558             result.append(">");
559             result.append(text);
560             result.append("</td>\n</tr>\n");
561             return result.toString();
562         }
563         return "";
564     }
565
566     /**
567      * Returns the HTML to build the detail view of a selected photo album image.<p>
568      *
569      * @return the HTML to build the detail view of a selected photo album image
570      */

571     protected String JavaDoc buildHtmlViewDetail() {
572
573         StringBuffer JavaDoc result = new StringBuffer JavaDoc(4096);
574
575         //show the photo gallery title
576
result.append(buildHtmlAlbumTitle());
577
578         // get the photo index number to show
579
String JavaDoc indexParam = getRequest().getParameter(PARAM_IMAGE);
580         int photoIndex = 0;
581         if (CmsStringUtil.isNotEmpty(indexParam)) {
582             // check the index parameter and set it to valid value if necessary
583
photoIndex = Integer.parseInt(indexParam);
584             if (photoIndex > (getAlbumPhotos().size() - 1)) {
585                 photoIndex = getAlbumPhotos().size() - 1;
586             }
587         }
588
589         // get the photo to show
590
CmsResource photo = (CmsResource)getAlbumPhotos().get(photoIndex);
591         String JavaDoc resourceName = getCmsObject().getSitePath(photo);
592
593         // determine the photo title
594
String JavaDoc title = "";
595         if (getConfiguration().showResourceNameAsTitle()) {
596             title = CmsResource.getName(resourceName);
597         }
598         title = property(CmsPropertyDefinition.PROPERTY_TITLE, resourceName, title);
599         title = CmsEncoder.escapeXml(title);
600
601         result.append("<table border=\"0\"");
602         result.append(getStyle().getClassThumbTable());
603         result.append(" width=\"");
604         result.append(getConfiguration().getDetailImageScaler().getWidth());
605         result.append("\">\n");
606
607         // show the navigation if configured position is top above text
608
result.append(buildHtmlImageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_TOP_ABOVE, photoIndex, photo));
609
610         // show the image title if configured
611
if (getConfiguration().showDetailTitle() && CmsStringUtil.isNotEmptyOrWhitespaceOnly(title)) {
612             result.append("<tr>\n\t<td");
613             result.append(getStyle().getClassDetailImageTitle());
614             result.append(getConfiguration().getStyleAlignAttribute(getConfiguration().getDetailAlignTitle()));
615             result.append(">");
616             result.append(title);
617             result.append("</td>\n</tr>\n");
618
619         }
620
621         // show the navigation if configured position is top below text
622
result.append(buildHtmlImageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_TOP_BELOW, photoIndex, photo));
623
624         // show image row
625
result.append("<tr>\n\t<td>");
626         // create the image
627
result.append("<img SRC=\"");
628         StringBuffer JavaDoc link = new StringBuffer JavaDoc(256);
629         link.append(resourceName);
630         link.append(getConfiguration().getDetailImageScaler().toRequestParam());
631         result.append(link(link.toString()));
632         result.append("\" border=\"0\" width=\"");
633         result.append(getConfiguration().getDetailImageScaler().getWidth());
634         result.append("\" height=\"");
635         result.append(getConfiguration().getDetailImageScaler().getHeight());
636         result.append("\" alt=\"");
637         result.append(title);
638         result.append("\" title=\"");
639         result.append(title);
640         result.append("\">");
641         result.append("</td>\n</tr>\n");
642
643         // show the navigation if configured position is bottom above text
644
result.append(buildHtmlImageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_BOTTOM_ABOVE, photoIndex, photo));
645
646         // show the image description if configured and present
647
if (getConfiguration().showDetailDescription()) {
648             String JavaDoc description = property(CmsPropertyDefinition.PROPERTY_DESCRIPTION, resourceName, "");
649             if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(description)) {
650                 result.append("<tr>\n\t<td");
651                 result.append(getStyle().getClassDetailImageDescription());
652                 result.append(getConfiguration().getStyleAlignAttribute(getConfiguration().getDetailAlignTitle()));
653                 result.append(">");
654                 result.append(description);
655                 result.append("</td>\n</tr>\n");
656             }
657         }
658
659         // show the navigation if configured position is bottom below text
660
result.append(buildHtmlImageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_BOTTOM_BELOW, photoIndex, photo));
661
662         result.append("</table>");
663         return result.toString();
664     }
665
666     /**
667      * Returns the HTML to build a thumbnail overview page of the photo album.<p>
668      *
669      * @return the HTML to build a thumbnail overview page of the photo album
670      */

671     protected String JavaDoc buildHtmlViewThumbNail() {
672
673         StringBuffer JavaDoc result = new StringBuffer JavaDoc(4096);
674
675         // determine photo indizes to display and the number of thumb rows
676
int startIndex = (getCurrentPage() - 1) * getPhotosPerPage();
677         int endIndex = 0;
678         int rowCount = getConfiguration().getThumbRows();
679         if (getConfiguration().showPageNavigation()) {
680             // navigation is shown, calculate end index
681
endIndex = (getCurrentPage() * getPhotosPerPage()) - 1;
682             if (endIndex > (getAlbumPhotos().size() - 1)) {
683                 endIndex = getAlbumPhotos().size() - 1;
684             }
685         } else {
686             // all photos on one page
687
endIndex = getAlbumPhotos().size() - 1;
688         }
689         int photoCount = endIndex - startIndex + 1;
690         rowCount = photoCount / getConfiguration().getThumbCols();
691         if ((photoCount % getConfiguration().getThumbCols()) > 0) {
692             rowCount += 1;
693         }
694
695         // show the photo album title
696
result.append(buildHtmlAlbumTitle());
697
698         result.append("<table border=\"0\"");
699         result.append(getStyle().getClassThumbTable());
700         result.append(" width=\"");
701         result.append(getConfiguration().getThumbCols() * getConfiguration().getThumbNailScaler().getWidth());
702         result.append("\">\n");
703
704         // show the navigation if configured position is top above text
705
result.append(buildHtmlPageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_TOP_ABOVE));
706
707         // show the top text if present
708
result.append(buildHtmlThumbTextRow(getConfiguration().getThumbTextTop()));
709
710         // show the navigation if configured position is top below text
711
result.append(buildHtmlPageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_TOP_BELOW));
712
713         String JavaDoc styleAttr = getConfiguration().getStyleAlignAttribute(getConfiguration().getThumbAlignTitle());
714
715         int photoIndex = startIndex;
716         for (int i = 1; i <= rowCount; i++) {
717             // build the table thumbnail rows
718
result.append("<tr>\n");
719             for (int k = 1; k <= getConfiguration().getThumbCols(); k++) {
720                 // build the tumbnail table data cell
721
result.append("\t<td width=\"");
722                 result.append(getConfiguration().getThumbNailScaler().getWidth());
723                 result.append("\"");
724                 result.append(getStyle().getClassThumbImageTitle());
725                 result.append(styleAttr);
726                 result.append(">");
727                 if (photoIndex <= endIndex) {
728                     // current photo is in list range, show it
729
CmsResource photo = (CmsResource)getAlbumPhotos().get(photoIndex);
730                     String JavaDoc resourceName = getCmsObject().getSitePath(photo);
731                     String JavaDoc title = "";
732                     if (getConfiguration().showResourceNameAsTitle()) {
733                         title = CmsResource.getName(resourceName);
734                     }
735                     title = property(CmsPropertyDefinition.PROPERTY_TITLE, resourceName, title);
736                     title = CmsEncoder.escapeXml(title);
737                     // create the link to the detail view
738
result.append("<a HREF=\"");
739                     StringBuffer JavaDoc link = new StringBuffer JavaDoc(256);
740                     link.append(getRequestContext().getUri());
741                     link.append("?");
742                     link.append(PARAM_ACTION).append("=").append(VALUE_ACTION_DETAIL);
743                     link.append("&").append(PARAM_IMAGE).append("=").append(photoIndex);
744                     result.append(link(link.toString()));
745                     result.append("\">");
746                     // create the scaled thumbnail
747
result.append("<img SRC=\"");
748                     link = new StringBuffer JavaDoc(256);
749                     link.append(resourceName);
750                     link.append(getConfiguration().getThumbNailScaler().toRequestParam());
751                     result.append(link(link.toString()));
752                     result.append("\" border=\"0\" width=\"");
753                     result.append(getConfiguration().getThumbNailScaler().getWidth());
754                     result.append("\" height=\"");
755                     result.append(getConfiguration().getThumbNailScaler().getHeight());
756                     result.append("\" alt=\"");
757                     result.append(title);
758                     result.append("\" title=\"");
759                     result.append(title);
760                     result.append("\">");
761                     result.append("</a>");
762                     if (getConfiguration().showThumbTitle() && CmsStringUtil.isNotEmptyOrWhitespaceOnly(title)) {
763                         // show title below the thumbnail
764
result.append("<br clear=\"all\"><span");
765                         result.append(getStyle().getClassThumbImageTitle());
766                         result.append(">");
767                         result.append(title);
768                         result.append("</span>");
769                     }
770                     photoIndex++;
771                 }
772                 result.append("</td>\n");
773             }
774             result.append("</tr>\n");
775         }
776
777         // show the navigation if configured position is bottom above text
778
result.append(buildHtmlPageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_BOTTOM_ABOVE));
779
780         // show the bottom text if present
781
result.append(buildHtmlThumbTextRow(getConfiguration().getThumbTextBottom()));
782
783         // show the navigation if configured position is bottom below text
784
result.append(buildHtmlPageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_BOTTOM_BELOW));
785
786         result.append("</table>");
787         return result.toString();
788     }
789
790     /**
791      * Determines the necessary page information to build the navigation elements for the album pages.<p>
792      *
793      * Calculates the following values and stores them in members:
794      * <ul>
795      * <li>the number of photos to display on one overview page</li>
796      * <li>the current thumbnail page to show</li>
797      * <li>the number of pages to create to show all images of the selected gallery</li>
798      * </ul>
799      */

800     protected void calculatePageData() {
801
802         if (getConfiguration().showPageNavigation()) {
803             // show page navigation, do calculations
804
setPhotosPerPage(getConfiguration().getThumbCols() * getConfiguration().getThumbRows());
805             int pageCount = getAlbumPhotos().size() / getPhotosPerPage();
806             if ((getAlbumPhotos().size() % getPhotosPerPage()) != 0) {
807                 pageCount++;
808             }
809             setPageCount(pageCount);
810             // determine page to show
811
String JavaDoc page = getRequest().getParameter(PARAM_PAGE);
812             if (CmsStringUtil.isNotEmpty(page) && getPageCount() > 1) {
813                 int currentPage = Integer.parseInt(page);
814                 if (currentPage > getPageCount()) {
815                     currentPage = getPageCount();
816                 }
817                 setCurrentPage(currentPage);
818             } else {
819                 setCurrentPage(1);
820             }
821         } else {
822             // no navigation shown, set to default values
823
setPhotosPerPage(0);
824             setPageCount(1);
825             setCurrentPage(1);
826         }
827     }
828
829     /**
830      * Returns if the current navigation position to check is the configured position.<p>
831      *
832      * @param currentPosition the current navigation position to check
833      * @return true if the current navigation position to check is the configured position, otherwise false
834      */

835     protected boolean checkNavigationPosition(String JavaDoc currentPosition) {
836
837         return getConfiguration().getNavigationPosition().indexOf(currentPosition) > -1;
838     }
839
840     /**
841      * Returns non breakable spaces (<code>&amp;nbsp;</code>) as replacement for the given replace value.<p>
842      *
843      * @param replaceValue the value to replace with spaces
844      * @return non breakable spaces as replacement
845      */

846     protected String JavaDoc fillNavSpaces(String JavaDoc replaceValue) {
847
848         int centerIndex = getConfiguration().getAlignNavigation().indexOf("center");
849         if (centerIndex > -1 && CmsStringUtil.isNotEmpty(replaceValue)) {
850             int length = replaceValue.length();
851             StringBuffer JavaDoc result = new StringBuffer JavaDoc(6 * length);
852             for (int i = 0; i < length; i++) {
853                 result.append("&nbsp;");
854             }
855             return result.toString();
856         }
857         return "";
858     }
859
860     /**
861      * Returns the configuration errors that occured.<p>
862      *
863      * @return the configuration errors that occured
864      */

865     protected List JavaDoc getConfigErrors() {
866
867         return m_configErrors;
868     }
869
870     /**
871      * Sets the configuration errors that occured.<p>
872      *
873      * @param configErrors the configuration errors that occured
874      */

875     protected void setConfigErrors(List JavaDoc configErrors) {
876
877         m_configErrors = configErrors;
878     }
879
880     /**
881      * Sets the current page to display for the thumbnail view.<p>
882      *
883      * @param currentPage the current page to display for the thumbnail view
884      */

885     protected void setCurrentPage(int currentPage) {
886
887         m_currentPage = currentPage;
888     }
889
890     /**
891      * Sets the display action to determine the view to generate.<p>
892      *
893      * @param displayAction the display action to determine the view to generate
894      */

895     protected void setDisplayAction(int displayAction) {
896
897         m_displayAction = displayAction;
898     }
899
900     /**
901      * Sets the number of pages to display for the thumbnail view.<p>
902      *
903      * @param pageCount the number of pages to display for the thumbnail view
904      */

905     protected void setPageCount(int pageCount) {
906
907         m_pageCount = pageCount;
908     }
909
910     /**
911      * Sets the number of photos to display on a single thumbnail overview page.<p>
912      *
913      * @param photosPerPage the number of photos to display on a single thumbnail overview page
914      */

915     protected void setPhotosPerPage(int photosPerPage) {
916
917         m_photosPerPage = photosPerPage;
918     }
919
920 }
921
Popular Tags