001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/photoalbum/CmsPhotoAlbumConfiguration.java,v $
003: * Date : $Date: 2008-02-27 12:05:55 $
004: * Version: $Revision: 1.4 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.frontend.photoalbum;
033:
034: import com.alkacon.simapi.Simapi;
035:
036: import org.opencms.file.CmsFile;
037: import org.opencms.file.CmsObject;
038: import org.opencms.jsp.CmsJspActionElement;
039: import org.opencms.loader.CmsImageScaler;
040: import org.opencms.main.CmsException;
041: import org.opencms.util.CmsStringUtil;
042: import org.opencms.xml.content.CmsXmlContent;
043: import org.opencms.xml.content.CmsXmlContentFactory;
044: import org.opencms.xml.types.CmsXmlHtmlValue;
045:
046: import java.awt.Color;
047: import java.util.List;
048: import java.util.Locale;
049:
050: /**
051: * Represents the frontend configuration of a photo album.<p>
052: *
053: * @author Andreas Zahner
054: *
055: * @version $Revision: 1.4 $
056: *
057: * @since 6.1.3
058: */
059: public class CmsPhotoAlbumConfiguration {
060:
061: /** Image filter: delimiter character. */
062: public static final String FILTER_DELIMITER = ".";
063:
064: /** Image filter: no filter selected. */
065: public static final String FILTER_NONE = "none";
066:
067: /** Navigation element position: on the bottom, above the editable text element. */
068: public static final String NAVPOS_BOTTOM_ABOVE = "b_a";
069:
070: /** Navigation element position: on the bottom, below the editable text element. */
071: public static final String NAVPOS_BOTTOM_BELOW = "b_b";
072:
073: /** Navigation element position: on top, above the editable text element. */
074: public static final String NAVPOS_TOP_ABOVE = "t_a";
075:
076: /** Navigation element position: on top, below the editable text element. */
077: public static final String NAVPOS_TOP_BELOW = "t_b";
078:
079: /** Configuration node name for the align navigation node. */
080: public static final String NODE_ALIGN_NAVIGATION = "AlignNavigation";
081:
082: /** Configuration node name for the align navigation node. */
083: public static final String NODE_ALIGN_TITLE = "AlignTitle";
084:
085: /** Configuration node name for the background node. */
086: public static final String NODE_BACKGROUND = "Background";
087:
088: /** Configuration node name for the columns node. */
089: public static final String NODE_COLS = "Cols";
090:
091: /** Configuration node name for the detail node. */
092: public static final String NODE_DETAIL = "Details";
093:
094: /** Configuration node name for the filter node. */
095: public static final String NODE_FILTER = "Filter";
096:
097: /** Configuration node name for the high quality node. */
098: public static final String NODE_HIGHQUALITY = "HighQuality";
099:
100: /** Configuration node name for the navigation position node. */
101: public static final String NODE_NAVIGATION_POSITION = "NavigationPosition";
102:
103: /** Configuration node name for the rows node. */
104: public static final String NODE_ROWS = "Rows";
105:
106: /** Configuration node name for the show description node. */
107: public static final String NODE_SHOWDESCRIPTION = "ShowDescription";
108:
109: /** Configuration node name for the show original link node. */
110: public static final String NODE_SHOWLINKORIGINAL = "ShowLinkOriginal";
111:
112: /** Configuration node name for the show resource name as title node. */
113: public static final String NODE_SHOWRESOURCENAMEASTITLE = "ShowResourceNameAsTitle";
114:
115: /** Configuration node name for the show title node. */
116: public static final String NODE_SHOWTITLE = "ShowTitle";
117:
118: /** Configuration node name for the size node. */
119: public static final String NODE_SIZE = "Size";
120:
121: /** Configuration node name for the bottom text node. */
122: public static final String NODE_TEXTBOTTOM = "TextBottom";
123:
124: /** Configuration node name for the top text node. */
125: public static final String NODE_TEXTTOP = "TextTop";
126:
127: /** Configuration node name for the thumbs node. */
128: public static final String NODE_THUMBS = "Thumbs";
129:
130: /** Configuration node name for the title node. */
131: public static final String NODE_TITLE = "Title";
132:
133: /** Configuration node name for the vfs folder node. */
134: public static final String NODE_VFSFOLDER = "VfsFolder";
135:
136: /** The image album title. */
137: private String m_albumTitle;
138:
139: /** The alignment of the album navigation elements. */
140: private String m_alignNavigation;
141:
142: /** The alignment of the image titles on the detail view. */
143: private String m_detailAlignTitle;
144:
145: /** The image scaler for the detail image. */
146: private CmsImageScaler m_detailImageScaler;
147:
148: /** The navigation element position on the pages. */
149: private String m_navigationPosition;
150:
151: /** The flag if the image description is shown on the detail view. */
152: private boolean m_showDetailDescription;
153:
154: /** The flag if the image original link is shown on the detail view. */
155: private boolean m_showDetailOriginalLink;
156:
157: /** The flag if the image title is shown on the detail view. */
158: private boolean m_showDetailTitle;
159:
160: /** The flag if the image resource name is shown as title if no title is found. */
161: private boolean m_showResourceNameAsTitle;
162:
163: /** The flag if the image title is shown on the thumbnail overview. */
164: private boolean m_showThumbTitle;
165:
166: /** The alignment of the image titles on the thumbnail overview. */
167: private String m_thumbAlignTitle;
168:
169: /** The number of image columns on the thumbnail overview. */
170: private int m_thumbCols;
171:
172: /** The image scaler for the thumbnails. */
173: private CmsImageScaler m_thumbNailScaler;
174:
175: /** The number of image rows on the thumbnail overview. */
176: private int m_thumbRows;
177:
178: /** The optional bottom text on the thumbnail overview. */
179: private String m_thumbTextBottom;
180:
181: /** The optional top text on the thumbnail overview. */
182: private String m_thumbTextTop;
183:
184: /** The OpenCms VFS path of the image gallery to use. */
185: private String m_vfsPathGallery;
186:
187: /**
188: * Empty constructor that does no initialization.<p>
189: */
190: public CmsPhotoAlbumConfiguration() {
191:
192: // initialize member objects
193: initMembers();
194: }
195:
196: /**
197: * Constructor that initializes the configuration using the currently requested URI.<p>
198: *
199: * @param jsp the initialized CmsJspActionElement to access the OpenCms API
200: * @throws Exception if parsing the configuration fails
201: */
202: public CmsPhotoAlbumConfiguration(CmsJspActionElement jsp)
203: throws Exception {
204:
205: init(jsp, null);
206: }
207:
208: /**
209: * Constructor that initializes the configuration from the given configuration URI.<p>
210: *
211: * @param jsp the initialized CmsJspActionElement to access the OpenCms API
212: * @param configUri URI of the configuration file, if not provided, current URI is used for configuration
213: * @throws Exception if parsing the configuration fails
214: */
215: public CmsPhotoAlbumConfiguration(CmsJspActionElement jsp,
216: String configUri) throws Exception {
217:
218: init(jsp, configUri);
219: }
220:
221: /**
222: * Returns the image album title.<p>
223: *
224: * @return the image album title
225: */
226: public String getAlbumTitle() {
227:
228: return m_albumTitle;
229: }
230:
231: /**
232: * Returns the alignment of the album navigation elements.<p>
233: *
234: * @return the alignment of the album navigation elements
235: */
236: public String getAlignNavigation() {
237:
238: return m_alignNavigation;
239: }
240:
241: /**
242: * Returns the alignment of the image titles on the detail view.<p>
243: *
244: * @return the alignment of the image titles on the detail view
245: */
246: public String getDetailAlignTitle() {
247:
248: return m_detailAlignTitle;
249: }
250:
251: /**
252: * Returns the image scaler for the detail image.<p>
253: *
254: * @return the image scaler for the detail image
255: */
256: public CmsImageScaler getDetailImageScaler() {
257:
258: return m_detailImageScaler;
259: }
260:
261: /**
262: * Returns the navigation element position on the pages.<p>
263: *
264: * @return the navigation element position on the pages
265: */
266: public String getNavigationPosition() {
267:
268: return m_navigationPosition;
269: }
270:
271: /**
272: * Returns the alignment of the image titles on the thumbnail overview.<p>
273: *
274: * @return the alignment of the image titles on the thumbnail overview
275: */
276: public String getThumbAlignTitle() {
277:
278: return m_thumbAlignTitle;
279: }
280:
281: /**
282: * Returns the number of image columns on the thumbnail overview.<p>
283: *
284: * @return the number of image columns on the thumbnail overview
285: */
286: public int getThumbCols() {
287:
288: return m_thumbCols;
289: }
290:
291: /**
292: * Returns the image scaler for the thumbnails.<p>
293: *
294: * @return the image scaler for the thumbnails
295: */
296: public CmsImageScaler getThumbNailScaler() {
297:
298: return m_thumbNailScaler;
299: }
300:
301: /**
302: * Returns the number of image rows on the thumbnail overview.<p>
303: *
304: * @return the number of image rows on the thumbnail overview
305: */
306: public int getThumbRows() {
307:
308: return m_thumbRows;
309: }
310:
311: /**
312: * Returns the optional bottom text on the thumbnail overview.<p>
313: *
314: * @return the optional bottom text on the thumbnail overview
315: */
316: public String getThumbTextBottom() {
317:
318: return m_thumbTextBottom;
319: }
320:
321: /**
322: * Returns the optional top text on the thumbnail overview.<p>
323: *
324: * @return the optional top text on the thumbnail overview
325: */
326: public String getThumbTextTop() {
327:
328: return m_thumbTextTop;
329: }
330:
331: /**
332: * Returns the OpenCms VFS path of the image gallery to use.<p>
333: *
334: * @return the OpenCms VFS path of the image gallery to use
335: */
336: public String getVfsPathGallery() {
337:
338: return m_vfsPathGallery;
339: }
340:
341: /**
342: * Initializes the album configuration.<p>
343: *
344: * @param jsp the initialized CmsJspActionElement to access the OpenCms API
345: * @param configUri URI of the form configuration file, if not provided, current URI is used for configuration
346: *
347: * @throws Exception if parsing the configuration fails
348: */
349: public void init(CmsJspActionElement jsp, String configUri)
350: throws Exception {
351:
352: // initialize member objects
353: initMembers();
354:
355: // read the album configuration file from VFS
356: if (CmsStringUtil.isEmpty(configUri)) {
357: configUri = jsp.getRequestContext().getUri();
358: }
359: CmsFile file = jsp.getCmsObject().readFile(configUri);
360: CmsXmlContent content = CmsXmlContentFactory.unmarshal(jsp
361: .getCmsObject(), file);
362:
363: // get locale from request context
364: Locale locale = jsp.getRequestContext().getLocale();
365: // get the cms object
366: CmsObject cms = jsp.getCmsObject();
367:
368: // get the album title
369: String stringValue = content.getStringValue(cms, NODE_TITLE,
370: locale);
371: setAlbumTitle(getConfigurationValue(stringValue, ""));
372:
373: // get the gallery vfs folder
374: stringValue = content.getStringValue(cms, NODE_VFSFOLDER,
375: locale);
376: setVfsPathGallery(getConfigurationValue(stringValue, ""));
377:
378: // get the alignment of navigation elements
379: stringValue = content.getStringValue(cms,
380: NODE_ALIGN_NAVIGATION, locale);
381: setAlignNavigation(getConfigurationValue(stringValue, "left"));
382:
383: // get the position of navigation elements
384: stringValue = content.getStringValue(cms,
385: NODE_NAVIGATION_POSITION, locale);
386: setNavigationPosition(getConfigurationValue(stringValue,
387: NAVPOS_BOTTOM_BELOW));
388:
389: // get the show resource name as title flag
390: stringValue = content.getStringValue(cms,
391: NODE_SHOWRESOURCENAMEASTITLE, locale);
392: setShowResourceNameAsTitle(Boolean.valueOf(stringValue)
393: .booleanValue());
394:
395: // get the thumbnail configuration parameters
396: String nodePrefix = NODE_THUMBS + "/";
397:
398: // get the show thumbs title flag
399: stringValue = content.getStringValue(cms, nodePrefix
400: + NODE_SHOWTITLE, locale);
401: setShowThumbTitle(Boolean.valueOf(stringValue).booleanValue());
402:
403: // get the alignment of thumbs title
404: stringValue = content.getStringValue(cms, nodePrefix
405: + NODE_ALIGN_TITLE, locale);
406: setThumbAlignTitle(getConfigurationValue(stringValue, "left"));
407:
408: // get the number of displayed columns
409: stringValue = content.getStringValue(cms, nodePrefix
410: + NODE_COLS, locale);
411: setThumbCols(Integer.parseInt(getConfigurationValue(
412: stringValue, "1")));
413:
414: // get the number of rows per page
415: stringValue = content.getStringValue(cms, nodePrefix
416: + NODE_ROWS, locale);
417: setThumbRows(Integer.parseInt(getConfigurationValue(
418: stringValue, "-1")));
419:
420: // get the thumbnail background color
421: stringValue = content.getStringValue(cms, nodePrefix
422: + NODE_BACKGROUND, locale);
423: stringValue = getConfigurationValue(stringValue, "#FFFFFF");
424: Color color = Color.WHITE;
425: try {
426: color = Color.decode(stringValue);
427: } catch (NumberFormatException e) {
428: throw new CmsException(Messages.get()
429: .container(Messages.LOG_ERR_WRONG_THUMB_BGCOLOR_1,
430: stringValue));
431: }
432: getThumbNailScaler().setColor(color);
433:
434: // get the thumbs high quality flag
435: stringValue = content.getStringValue(cms, nodePrefix
436: + NODE_HIGHQUALITY, locale);
437: if (Boolean.valueOf(stringValue).booleanValue()) {
438: // use high quality for thumbnails
439: getThumbNailScaler().setQuality(85);
440: } else {
441: // use speed render settings for thumbnails
442: getThumbNailScaler().setQuality(50);
443: getThumbNailScaler().setRenderMode(Simapi.RENDER_SPEED);
444: }
445:
446: // get the thumbnail size
447: stringValue = content.getStringValue(cms, nodePrefix
448: + NODE_SIZE, locale);
449: setImageSize(stringValue, true);
450:
451: // get the thumbnail filter
452: stringValue = content.getStringValue(cms, nodePrefix
453: + NODE_FILTER, locale);
454: setImageFilter(stringValue, true);
455:
456: // get the top and bottom texts for the thumbnail pages
457: CmsXmlHtmlValue textValue = (CmsXmlHtmlValue) content.getValue(
458: nodePrefix + NODE_TEXTTOP, locale);
459: if (textValue != null) {
460: // get the top text
461: stringValue = textValue.getStringValue(cms);
462: setThumbTextTop(getConfigurationValue(stringValue, ""));
463: } else {
464: setThumbTextTop("");
465: }
466: textValue = (CmsXmlHtmlValue) content.getValue(nodePrefix
467: + NODE_TEXTBOTTOM, locale);
468: if (textValue != null) {
469: // get the top text
470: stringValue = textValue.getStringValue(cms);
471: setThumbTextBottom(getConfigurationValue(stringValue, ""));
472: } else {
473: setThumbTextBottom("");
474: }
475:
476: // get the detail configuration parameters
477: nodePrefix = NODE_DETAIL + "/";
478:
479: // get the show detail title flag
480: stringValue = content.getStringValue(cms, nodePrefix
481: + NODE_SHOWTITLE, locale);
482: setShowDetailTitle(Boolean.valueOf(stringValue).booleanValue());
483:
484: // get the show detail description flag
485: stringValue = content.getStringValue(cms, nodePrefix
486: + NODE_SHOWDESCRIPTION, locale);
487: setShowDetailDescription(Boolean.valueOf(stringValue)
488: .booleanValue());
489:
490: // get the alignment of detail title
491: stringValue = content.getStringValue(cms, nodePrefix
492: + NODE_ALIGN_TITLE, locale);
493: setDetailAlignTitle(getConfigurationValue(stringValue, "left"));
494:
495: // get the show detail link to original flag
496: stringValue = content.getStringValue(cms, nodePrefix
497: + NODE_SHOWLINKORIGINAL, locale);
498: setShowDetailOriginalLink(Boolean.valueOf(stringValue)
499: .booleanValue());
500:
501: // get the detail image size
502: stringValue = content.getStringValue(cms, nodePrefix
503: + NODE_SIZE, locale);
504: setImageSize(stringValue, false);
505:
506: // get the detail image filter
507: stringValue = content.getStringValue(cms, nodePrefix
508: + NODE_FILTER, locale);
509: setImageFilter(stringValue, false);
510:
511: // get the detail image background color
512: stringValue = content.getStringValue(cms, nodePrefix
513: + NODE_BACKGROUND, locale);
514: stringValue = getConfigurationValue(stringValue, "#FFFFFF");
515: color = Color.WHITE;
516: try {
517: color = Color.decode(stringValue);
518: } catch (NumberFormatException e) {
519: throw new CmsException(Messages.get().container(
520: Messages.LOG_ERR_WRONG_DETAIL_BGCOLOR_1,
521: stringValue));
522: }
523: getDetailImageScaler().setColor(color);
524: }
525:
526: /**
527: * Returns if the image description is shown on the detail view.<p>
528: *
529: * @return true if the image description is shown on the detail view, otherwise false
530: */
531: public boolean showDetailDescription() {
532:
533: return m_showDetailDescription;
534: }
535:
536: /**
537: * Returns if the image original link is shown on the detail view.<p>
538: *
539: * @return true if the image original link is shown on the detail view, otherwise false
540: */
541: public boolean showDetailOriginalLink() {
542:
543: return m_showDetailOriginalLink;
544: }
545:
546: /**
547: * Returns if the image title is shown on the detail view.<p>
548: *
549: * @return true if the image title is shown on the detail view, otherwise false
550: */
551: public boolean showDetailTitle() {
552:
553: return m_showDetailTitle;
554: }
555:
556: /**
557: * Returns if a page navigation should be shown on the tumbnail overview.<p>
558: *
559: * @return true if a page navigation should be shown on the tumbnail overview, otherwise false
560: */
561: public boolean showPageNavigation() {
562:
563: return getThumbRows() > 0;
564: }
565:
566: /**
567: * Returns if the image resource name is shown as title if no title is found.<p>
568: *
569: * @return true if the image resource name is shown as title if no title is found, otherwise false
570: */
571: public boolean showResourceNameAsTitle() {
572:
573: return m_showResourceNameAsTitle;
574: }
575:
576: /**
577: * Returns if the optional bottom text on the thumbnail overview is shown.<p>
578: *
579: * @return true if the optional bottom text on the thumbnail overview is shown, otherwise false
580: */
581: public boolean showThumbTextBottom() {
582:
583: return CmsStringUtil.isNotEmpty(getThumbTextBottom());
584: }
585:
586: /**
587: * Returns if the optional top text on the thumbnail overview is shown.<p>
588: *
589: * @return true if the optional top text on the thumbnail overview is shown, otherwise false
590: */
591: public boolean showThumbTextTop() {
592:
593: return CmsStringUtil.isNotEmpty(getThumbTextTop());
594: }
595:
596: /**
597: * Returns if the image title is shown on the thumbnail overview.<p>
598: *
599: * @return true if the image title is shown on the thumbnail overview, otherwise false
600: */
601: public boolean showThumbTitle() {
602:
603: return m_showThumbTitle;
604: }
605:
606: /**
607: * Returns the style attribute value to use for alignment configurations.<p>
608: *
609: * @param alignment the alignment (left, center or right)
610: * @return the style attribute value to use for alignment configurations
611: */
612: protected String getStyleAlignAttribute(String alignment) {
613:
614: StringBuffer result = new StringBuffer(32);
615: result.append(" style=\"text-align: ");
616: result.append(alignment);
617: result.append(";\"");
618: return result.toString();
619: }
620:
621: /**
622: * Initializes the members variables.<p>
623: */
624: protected void initMembers() {
625:
626: // initialize member image scaler objects
627: setDetailImageScaler(new CmsImageScaler());
628: setThumbNailScaler(new CmsImageScaler());
629:
630: // set defaults
631: setVfsPathGallery("/");
632: setThumbCols(3);
633: setThumbRows(3);
634: setNavigationPosition(NAVPOS_TOP_BELOW);
635:
636: }
637:
638: /**
639: * Sets the image album title.<p>
640: *
641: * @param albumTitle the image album title
642: */
643: protected void setAlbumTitle(String albumTitle) {
644:
645: m_albumTitle = albumTitle;
646: }
647:
648: /**
649: * Sets the alignment of the album navigation elements.<p>
650: *
651: * @param alignNavigation the alignment of the album navigation elements
652: */
653: protected void setAlignNavigation(String alignNavigation) {
654:
655: m_alignNavigation = alignNavigation;
656: }
657:
658: /**
659: * Sets the alignment of the image titles on the detail view.<p>
660: *
661: * @param detailAlignTitle the alignment of the image titles on the detail view
662: */
663: protected void setDetailAlignTitle(String detailAlignTitle) {
664:
665: m_detailAlignTitle = detailAlignTitle;
666: }
667:
668: /**
669: * Sets the image scaler for the detail image.<p>
670: *
671: * @param detailImageScaler the image scaler for the detail image
672: */
673: protected void setDetailImageScaler(CmsImageScaler detailImageScaler) {
674:
675: m_detailImageScaler = detailImageScaler;
676: }
677:
678: /**
679: * Sets the navigation element position on the pages.<p>
680: *
681: * @param navigationPosition the navigation element position on the pages
682: */
683: protected void setNavigationPosition(String navigationPosition) {
684:
685: m_navigationPosition = navigationPosition;
686: }
687:
688: /**
689: * Sets if the image description is shown on the detail view.<p>
690: *
691: * @param showDetailDescription true if the image description is shown on the detail view, otherwise false
692: */
693: protected void setShowDetailDescription(
694: boolean showDetailDescription) {
695:
696: m_showDetailDescription = showDetailDescription;
697: }
698:
699: /**
700: * Sets if the image original link is shown on the detail view.<p>
701: *
702: * @param showDetailOriginalLink true if the image original link is shown on the detail view, otherwise false
703: */
704: protected void setShowDetailOriginalLink(
705: boolean showDetailOriginalLink) {
706:
707: m_showDetailOriginalLink = showDetailOriginalLink;
708: }
709:
710: /**
711: * Sets if the image title is shown on the detail view.<p>
712: *
713: * @param showDetailTitle true if the image title is shown on the detail view, otherwise false
714: */
715: protected void setShowDetailTitle(boolean showDetailTitle) {
716:
717: m_showDetailTitle = showDetailTitle;
718: }
719:
720: /**
721: * Sets if the image resource name is shown as title if no title is found.<p>
722: *
723: * @param showResourceNameAsTitle true if the image resource name is shown as title if no title is found, otherwise false
724: */
725: protected void setShowResourceNameAsTitle(
726: boolean showResourceNameAsTitle) {
727:
728: m_showResourceNameAsTitle = showResourceNameAsTitle;
729: }
730:
731: /**
732: * Sets if the image title is shown on the thumbnail overview.<p>
733: *
734: * @param showThumbTitle true if the image title is shown on the thumbnail overview, otherwise false
735: */
736: protected void setShowThumbTitle(boolean showThumbTitle) {
737:
738: m_showThumbTitle = showThumbTitle;
739: }
740:
741: /**
742: * Sets the alignment of the image titles on the thumbnail overview.<p>
743: *
744: * @param thumbAlignTitle the alignment of the image titles on the thumbnail overview
745: */
746: protected void setThumbAlignTitle(String thumbAlignTitle) {
747:
748: m_thumbAlignTitle = thumbAlignTitle;
749: }
750:
751: /**
752: * Sets the number of image columns on the thumbnail overview.<p>
753: *
754: * @param thumbCols the number of image columns on the thumbnail overview
755: */
756: protected void setThumbCols(int thumbCols) {
757:
758: m_thumbCols = thumbCols;
759: }
760:
761: /**
762: * Sets the image scaler for the thumbnails.<p>
763: *
764: * @param thumbNailScaler the image scaler for the thumbnails
765: */
766: protected void setThumbNailScaler(CmsImageScaler thumbNailScaler) {
767:
768: m_thumbNailScaler = thumbNailScaler;
769: }
770:
771: /**
772: * Sets the number of image rows on the thumbnail overview.<p>
773: *
774: * @param thumbRows the number of image rows on the thumbnail overview
775: */
776: protected void setThumbRows(int thumbRows) {
777:
778: if (thumbRows < 1) {
779: m_thumbRows = -1;
780: } else {
781: m_thumbRows = thumbRows;
782: }
783: }
784:
785: /**
786: * Sets the optional bottom text on the thumbnail overview.<p>
787: *
788: * @param thumbTextBottom the optional bottom text on the thumbnail overview
789: */
790: protected void setThumbTextBottom(String thumbTextBottom) {
791:
792: m_thumbTextBottom = thumbTextBottom;
793: }
794:
795: /**
796: * Sets the optional top text on the thumbnail overview.<p>
797: *
798: * @param thumbTextTop the optional top text on the thumbnail overview
799: */
800: protected void setThumbTextTop(String thumbTextTop) {
801:
802: m_thumbTextTop = thumbTextTop;
803: }
804:
805: /**
806: * Sets the OpenCms VFS path of the image gallery to use.<p>
807: *
808: * @param vfsPathGallery the OpenCms VFS path of the image gallery to use
809: */
810: protected void setVfsPathGallery(String vfsPathGallery) {
811:
812: m_vfsPathGallery = vfsPathGallery;
813: }
814:
815: /**
816: * Checks if the given value is empty and returns in that case the default value.<p>
817: *
818: * @param value the configuration value to check
819: * @param defaultValue the default value to return in case the value is empty
820: * @return the checked value
821: */
822: private String getConfigurationValue(String value,
823: String defaultValue) {
824:
825: if (CmsStringUtil.isNotEmpty(value)) {
826: return value;
827: }
828: return defaultValue;
829: }
830:
831: /**
832: * Sets the image filter for thumbnails and the detail view.<p>
833: *
834: * @param configValue the String value of the configuration file
835: * @param isThumbNail flag indicating if the thumbnail or the detail view configuration is set
836: * @throws Exception if parsing the configuration fails
837: */
838: private void setImageFilter(String configValue, boolean isThumbNail)
839: throws Exception {
840:
841: if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configValue)
842: && !FILTER_NONE.equals(configValue)) {
843: // filter value set, determine it
844: List filter = CmsStringUtil.splitAsList(configValue,
845: FILTER_DELIMITER);
846: for (int i = 0; i < filter.size(); i++) {
847: String currentFilter = (String) filter.get(i);
848: if (isThumbNail) {
849: // set thumbnail filter
850: getThumbNailScaler().addFilter(currentFilter);
851: } else {
852: // set detail image filter
853: getDetailImageScaler().addFilter(currentFilter);
854: }
855: }
856:
857: }
858: }
859:
860: /**
861: * Sets the image size for thumbnails and the detail view.<p>
862: *
863: * @param configValue the String value of the configuration file
864: * @param isThumbNail flag indicating if the thumbnail or the detail view configuration is set
865: * @throws Exception if parsing the configuration fails
866: */
867: private void setImageSize(String configValue, boolean isThumbNail)
868: throws Exception {
869:
870: List sizes = CmsStringUtil.splitAsList(getConfigurationValue(
871: configValue, "200x150"), 'x', true);
872: int width = Integer.parseInt((String) sizes.get(0));
873: int height = Integer.parseInt((String) sizes.get(1));
874: if (isThumbNail) {
875: getThumbNailScaler().setWidth(width);
876: getThumbNailScaler().setHeight(height);
877: } else {
878: getDetailImageScaler().setWidth(width);
879: getDetailImageScaler().setHeight(height);
880: }
881: }
882:
883: }
|