0001: /*
0002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/photoalbum/CmsPhotoAlbumBean.java,v $
0003: * Date : $Date: 2008-02-27 12:05:55 $
0004: * Version: $Revision: 1.5 $
0005: *
0006: * This library is part of OpenCms -
0007: * the Open Source Content Management System
0008: *
0009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
0010: *
0011: * This library is free software; you can redistribute it and/or
0012: * modify it under the terms of the GNU Lesser General Public
0013: * License as published by the Free Software Foundation; either
0014: * version 2.1 of the License, or (at your option) any later version.
0015: *
0016: * This library is distributed in the hope that it will be useful,
0017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0019: * Lesser General Public License for more details.
0020: *
0021: * For further information about Alkacon Software GmbH, please see the
0022: * company website: http://www.alkacon.com
0023: *
0024: * For further information about OpenCms, please see the
0025: * project website: http://www.opencms.org
0026: *
0027: * You should have received a copy of the GNU Lesser General Public
0028: * License along with this library; if not, write to the Free Software
0029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0030: */
0031:
0032: package org.opencms.frontend.photoalbum;
0033:
0034: import org.opencms.file.CmsPropertyDefinition;
0035: import org.opencms.file.CmsResource;
0036: import org.opencms.file.CmsResourceFilter;
0037: import org.opencms.file.types.CmsResourceTypeImage;
0038: import org.opencms.i18n.CmsEncoder;
0039: import org.opencms.i18n.CmsMessages;
0040: import org.opencms.jsp.CmsJspActionElement;
0041: import org.opencms.main.CmsException;
0042: import org.opencms.main.CmsLog;
0043: import org.opencms.util.CmsStringUtil;
0044:
0045: import java.io.IOException;
0046: import java.util.ArrayList;
0047: import java.util.List;
0048:
0049: import javax.servlet.http.HttpServletRequest;
0050: import javax.servlet.http.HttpServletResponse;
0051: import javax.servlet.jsp.PageContext;
0052:
0053: import org.apache.commons.logging.Log;
0054:
0055: /**
0056: * Provides methods to generate frontend views of a photo album using a XML Content configuration file.<p>
0057: *
0058: * @author Andreas Zahner
0059: *
0060: * @version $Revision: 1.5 $
0061: *
0062: * @since 6.1.3
0063: */
0064: public class CmsPhotoAlbumBean extends CmsJspActionElement {
0065:
0066: /** Request parameter value for the album action: show detail view. */
0067: public static final int ACTION_DETAIL = 1;
0068:
0069: /** Request parameter value for the album action: show original image. */
0070: public static final int ACTION_ORIGINAL = 2;
0071:
0072: /** Request parameter value for the album action: show thumbnail view. */
0073: public static final int ACTION_THUMBNAIL = 0;
0074:
0075: /** Request parameter name for the action parameter. */
0076: public static final String PARAM_ACTION = "action";
0077:
0078: /** Request parameter name for the image parameter. */
0079: public static final String PARAM_IMAGE = "image";
0080:
0081: /** Request parameter name for the album page parameter. */
0082: public static final String PARAM_PAGE = "thumbpage";
0083:
0084: /** Request parameter value for the album action: show detail view. */
0085: public static final String VALUE_ACTION_DETAIL = "detail";
0086:
0087: /** Request parameter value for the album action: show original image. */
0088: public static final String VALUE_ACTION_ORIGINAL = "original";
0089:
0090: /** Request parameter value for the album action: show thumbnail view. */
0091: public static final String VALUE_ACTION_THUMBNAIL = "thumbnail";
0092:
0093: /** The log object for this class. */
0094: private static final Log LOG = CmsLog
0095: .getLog(CmsPhotoAlbumBean.class);
0096:
0097: /** The list of all photos to display in the photo album. */
0098: private List m_albumPhotos;
0099:
0100: /** Holds possible configuration error messages. */
0101: private List m_configErrors;
0102:
0103: /** The photo album configuration. */
0104: private CmsPhotoAlbumConfiguration m_configuration;
0105:
0106: /** The current page to display for the thumbnail view. */
0107: private int m_currentPage;
0108:
0109: /** The display action to determine the view to generate. */
0110: private int m_displayAction;
0111:
0112: /** The messages to use. */
0113: private CmsMessages m_messages;
0114:
0115: /** The number of pages to display for the thumbnail view. */
0116: private int m_pageCount;
0117:
0118: /** The number of photos to display on a single thumbnail overview page. */
0119: private int m_photosPerPage;
0120:
0121: /** The CSS style object that is used to format the photo album output. */
0122: private CmsPhotoAlbumStyle m_style;
0123:
0124: /**
0125: * Constructor, creates the necessary photo album configuration objects.<p>
0126: *
0127: * @param context the JSP page context object
0128: * @param req the JSP request
0129: * @param res the JSP response
0130: */
0131: public CmsPhotoAlbumBean(PageContext context,
0132: HttpServletRequest req, HttpServletResponse res) {
0133:
0134: this (context, req, res, null);
0135: }
0136:
0137: /**
0138: * Constructor, creates the necessary photo album configuration objects using a given configuration file URI.<p>
0139: *
0140: * @param context the JSP page context object
0141: * @param req the JSP request
0142: * @param res the JSP response
0143: * @param configUri URI of the photo album configuration file, if not provided, current URI is used for configuration
0144: */
0145: public CmsPhotoAlbumBean(PageContext context,
0146: HttpServletRequest req, HttpServletResponse res,
0147: String configUri) {
0148:
0149: super (context, req, res);
0150: init(configUri);
0151: }
0152:
0153: /**
0154: * Builds the HTML to display the photo album.<p>
0155: *
0156: * @return the HTML to display the photo album
0157: * @throws IOException if writing the output fails
0158: */
0159: public String displayAlbum() throws IOException {
0160:
0161: // show eventual configuration errors
0162: buildHtmlConfigurationErrors();
0163: // show selected album view
0164: switch (getDisplayAction()) {
0165: case ACTION_DETAIL:
0166: return buildHtmlViewDetail();
0167: case ACTION_ORIGINAL:
0168: return "";
0169: case ACTION_THUMBNAIL:
0170: default:
0171: return buildHtmlViewThumbNail();
0172: }
0173: }
0174:
0175: /**
0176: * Returns the list of all photos to display in the photo album.<p>
0177: *
0178: * @return the list of all photos to display in the photo album
0179: */
0180: public List getAlbumPhotos() {
0181:
0182: if (m_albumPhotos == null) {
0183: CmsResourceFilter filter = CmsResourceFilter.DEFAULT
0184: .addRequireType(CmsResourceTypeImage
0185: .getStaticTypeId());
0186: try {
0187: m_albumPhotos = getCmsObject().readResources(
0188: getConfiguration().getVfsPathGallery(), filter,
0189: false);
0190: } catch (CmsException e) {
0191: // create empty photo list
0192: m_albumPhotos = new ArrayList(0);
0193: // log error
0194: if (LOG.isErrorEnabled()) {
0195: LOG.error(Messages.get().getBundle().key(
0196: Messages.LOG_ERR_IMAGEFOLDER_NOT_FOUND_1,
0197: getConfiguration().getVfsPathGallery()));
0198: }
0199: addConfigError(m_messages.key(
0200: Messages.LOG_ERR_IMAGEFOLDER_NOT_FOUND_1,
0201: getConfiguration().getVfsPathGallery()));
0202: }
0203: }
0204: return m_albumPhotos;
0205: }
0206:
0207: /**
0208: * Returns the photo album configuration.<p>
0209: *
0210: * @return the photo album configuration
0211: */
0212: public CmsPhotoAlbumConfiguration getConfiguration() {
0213:
0214: return m_configuration;
0215: }
0216:
0217: /**
0218: * Returns the current page to display for the thumbnail view.<p>
0219: *
0220: * @return the current page to display for the thumbnail view
0221: */
0222: public int getCurrentPage() {
0223:
0224: return m_currentPage;
0225: }
0226:
0227: /**
0228: * Returns the display action to determine the view to generate.<p>
0229: *
0230: * @return the display action to determine the view to generate
0231: */
0232: public int getDisplayAction() {
0233:
0234: return m_displayAction;
0235: }
0236:
0237: /**
0238: * Returns the number of pages to display for the thumbnail view.<p>
0239: *
0240: * @return the number of pages to display for the thumbnail view
0241: */
0242: public int getPageCount() {
0243:
0244: return m_pageCount;
0245: }
0246:
0247: /**
0248: * Returns the number of photos to display on a single thumbnail overview page.<p>
0249: *
0250: * @return the number of photos to display on a single thumbnail overview page
0251: */
0252: public int getPhotosPerPage() {
0253:
0254: return m_photosPerPage;
0255: }
0256:
0257: /**
0258: * Returns the CSS style object that is used to format the photo album output.<p>
0259: *
0260: * @return the CSS style object that is used to format the photo album output
0261: */
0262: public CmsPhotoAlbumStyle getStyle() {
0263:
0264: return m_style;
0265: }
0266:
0267: /**
0268: * Initializes the photo album configuration and determines the display action.<p>
0269: *
0270: * @param configUri URI of the photo album configuration file, if not provided, current URI is used for configuration
0271: */
0272: public void init(String configUri) {
0273:
0274: // set messages
0275: m_messages = Messages.get().getBundle(
0276: getRequestContext().getLocale());
0277: // initialize empty list of configuration errors
0278: setConfigErrors(new ArrayList());
0279: // initialize the photo album CSS styles
0280: setStyle(new CmsPhotoAlbumStyle());
0281: // initialize the photo album configuration
0282: try {
0283: setConfiguration(new CmsPhotoAlbumConfiguration(this ,
0284: configUri));
0285: } catch (Exception e) {
0286: // set empty configuration
0287: setConfiguration(new CmsPhotoAlbumConfiguration());
0288: if (e instanceof CmsException) {
0289: // for Cms exceptions, show detailed error message
0290: addConfigError(((CmsException) e)
0291: .getLocalizedMessage(getRequestContext()
0292: .getLocale()));
0293: } else {
0294: addConfigError(e.getLocalizedMessage());
0295: }
0296: }
0297: // determine the album view to display depending on request parameter
0298: String action = getRequest().getParameter(PARAM_ACTION);
0299: if (VALUE_ACTION_DETAIL.equals(action)) {
0300: // show the detail view
0301: setDisplayAction(ACTION_DETAIL);
0302: } else if (VALUE_ACTION_ORIGINAL.equals(action)) {
0303: // show the original image
0304: setDisplayAction(ACTION_ORIGINAL);
0305: } else {
0306: // default action: show the thumbnail overview
0307: setDisplayAction(ACTION_THUMBNAIL);
0308: }
0309: // determine the necessary page data to build navigation elements
0310: calculatePageData();
0311: }
0312:
0313: /**
0314: * Sets the photo album configuration.<p>
0315: *
0316: * @param configuration the photo album configuration
0317: */
0318: public void setConfiguration(
0319: CmsPhotoAlbumConfiguration configuration) {
0320:
0321: m_configuration = configuration;
0322: }
0323:
0324: /**
0325: * Sets the CSS style object that is used to format the photo album output.<p>
0326: *
0327: * @param style the CSS style object that is used to format the photo album output
0328: */
0329: public void setStyle(CmsPhotoAlbumStyle style) {
0330:
0331: m_style = style;
0332: }
0333:
0334: /**
0335: * Adds an error to the list of configuration errors.<p>
0336: *
0337: * @param configError error to add to the list of configuration errors
0338: */
0339: protected void addConfigError(String configError) {
0340:
0341: m_configErrors.add(configError);
0342: }
0343:
0344: /**
0345: * Returns the HTML for the photo album title.<p>
0346: *
0347: * @return the HTML for the photo album title
0348: */
0349: protected String buildHtmlAlbumTitle() {
0350:
0351: if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getConfiguration()
0352: .getAlbumTitle())) {
0353: // show the title
0354: StringBuffer result = new StringBuffer(128);
0355: result.append("<h1");
0356: result.append(getStyle().getClassPageTitle());
0357: result.append(">");
0358: result.append(getConfiguration().getAlbumTitle());
0359: result.append("</h1>\n");
0360: return result.toString();
0361: }
0362: return "";
0363: }
0364:
0365: /**
0366: * Writes the HTML for the configuration error output.<p>
0367: *
0368: * Writes the found configuration errors directly to the JSP writer.<p>
0369: *
0370: * @throws IOException if writing the output fails
0371: */
0372: protected void buildHtmlConfigurationErrors() throws IOException {
0373:
0374: if (!getRequestContext().currentProject().isOnlineProject()
0375: && getConfigErrors().size() > 0) {
0376: // configuration error(s) found, show them in offline projects
0377: getJspContext().getOut().print("<h1>");
0378: getJspContext()
0379: .getOut()
0380: .print(
0381: m_messages
0382: .key(Messages.GUI_CONFIG_ERRORS_HEADLINE_0));
0383: getJspContext().getOut().print("</h1>");
0384: getJspContext().getOut().print("<p>");
0385: // loop error messages
0386: for (int i = 0; i < getConfigErrors().size(); i++) {
0387: if (i > 0) {
0388: getJspContext().getOut().println("<br />");
0389: }
0390: getJspContext().getOut()
0391: .print(getConfigErrors().get(i));
0392: }
0393: getJspContext().getOut().print("</p>");
0394: }
0395: }
0396:
0397: /**
0398: * Returns the HTML for the image navigation on the photo album detail page.<p>
0399: *
0400: * @param currentNavigationPosition the current navigation position to display the navigation
0401: * @param photoIndex the index of the photo to display
0402: * @param photo the photo to display as CmsResource object
0403: * @return the HTML for the image navigation on the photo album detail page
0404: */
0405: protected String buildHtmlImageNavigation(
0406: String currentNavigationPosition, int photoIndex,
0407: CmsResource photo) {
0408:
0409: if (!checkNavigationPosition(currentNavigationPosition)) {
0410: // wrong position to insert the navigation elements, do not show navigation at this position
0411: return "";
0412: }
0413:
0414: StringBuffer result = new StringBuffer(1024);
0415: StringBuffer link = new StringBuffer(256);
0416: result.append("<tr>\n\t<td");
0417: result.append(getStyle().getClassNavigation());
0418: result.append(getConfiguration().getStyleAlignAttribute(
0419: getConfiguration().getAlignNavigation()));
0420: result.append(">");
0421: if (photoIndex > 0) {
0422: // build the "Back" link
0423: result.append("<a");
0424: result.append(getStyle().getClassLink());
0425: result.append(" href=\"");
0426: link.append(getRequestContext().getUri());
0427: link.append("?");
0428: link.append(PARAM_ACTION).append("=").append(
0429: VALUE_ACTION_DETAIL);
0430: link.append("&");
0431: link.append(PARAM_IMAGE).append("=").append(photoIndex - 1);
0432: result.append(link(link.toString()));
0433: result.append("\">");
0434: result.append(m_messages
0435: .key(Messages.GUI_NAVIGATION_BACK_0));
0436: result.append("</a>");
0437: result.append(" - ");
0438: } else {
0439: result.append(fillNavSpaces(m_messages
0440: .key(Messages.GUI_NAVIGATION_BACK_0)
0441: + " - "));
0442: }
0443: // build the image index information
0444: Object[] args = new Object[] { new Integer(photoIndex + 1),
0445: new Integer(getAlbumPhotos().size()) };
0446: result.append(m_messages.key(Messages.GUI_DETAIL_IMAGEINFO_2,
0447: args));
0448: if (photoIndex < (getAlbumPhotos().size() - 1)) {
0449: // build the "Next" link
0450: result.append(" - ");
0451: result.append("<a");
0452: result.append(getStyle().getClassLink());
0453: result.append(" href=\"");
0454: link = new StringBuffer(256);
0455: link.append(getRequestContext().getUri());
0456: link.append("?");
0457: link.append(PARAM_ACTION).append("=").append(
0458: VALUE_ACTION_DETAIL);
0459: link.append("&");
0460: link.append(PARAM_IMAGE).append("=").append(photoIndex + 1);
0461: result.append(link(link.toString()));
0462: result.append("\">");
0463: result.append(m_messages
0464: .key(Messages.GUI_NAVIGATION_NEXT_0));
0465: result.append("</a>");
0466: } else {
0467: result.append(fillNavSpaces(" - "
0468: + m_messages.key(Messages.GUI_NAVIGATION_NEXT_0)));
0469: }
0470: result.append("<br />");
0471:
0472: // build the link to the thumbnail overview
0473: int thumbPage = 1;
0474: if (getConfiguration().showPageNavigation()) {
0475: // calculate the page to show
0476: thumbPage = (photoIndex / getPhotosPerPage()) + 1;
0477: }
0478: result.append("<a");
0479: result.append(getStyle().getClassLink());
0480: result.append(" href=\"");
0481: link = new StringBuffer(256);
0482: link.append(getRequestContext().getUri());
0483: link.append("?");
0484: link.append(PARAM_ACTION).append("=").append(
0485: VALUE_ACTION_THUMBNAIL);
0486: link.append("&");
0487: link.append(PARAM_PAGE).append("=").append(thumbPage);
0488: result.append(link(link.toString()));
0489: result.append("\">");
0490: result.append(m_messages
0491: .key(Messages.GUI_NAVIGATION_OVERVIEW_0));
0492: result.append("</a>");
0493:
0494: // build the link to the original image if configured
0495: if (getConfiguration().showDetailOriginalLink()) {
0496: result.append(" - <a");
0497: result.append(getStyle().getClassLink());
0498: result.append(" href=\"");
0499: result.append(link(getCmsObject().getSitePath(photo)));
0500: result.append("\" target=\"originalphoto\">");
0501: result.append(m_messages
0502: .key(Messages.GUI_NAVIGATION_ORIGINAL_0));
0503: result.append("</a>");
0504: }
0505: result.append("</td>\n</tr>\n");
0506:
0507: return result.toString();
0508: }
0509:
0510: /**
0511: * Returns the HTML for the page navigation on the thumbnail overview pages.<p>
0512: *
0513: * @param currentNavigationPosition the current navigation position to display the navigation
0514: * @return the HTML for the page navigation on the thumbnail overview pages
0515: */
0516: protected String buildHtmlPageNavigation(
0517: String currentNavigationPosition) {
0518:
0519: if (!checkNavigationPosition(currentNavigationPosition)) {
0520: // wrong position to insert the navigation elements, do not show navigation at this position
0521: return "";
0522: }
0523:
0524: StringBuffer result = new StringBuffer(1024);
0525:
0526: if (getConfiguration().showPageNavigation()
0527: && getPageCount() > 1) {
0528: // show navigation and number of pages greater than 1
0529: result.append("<tr>\n\t<td colspan=\"");
0530: result.append(getConfiguration().getThumbCols());
0531: result.append("\"");
0532: result.append(getStyle().getClassNavigation());
0533: result.append(getConfiguration().getStyleAlignAttribute(
0534: getConfiguration().getAlignNavigation()));
0535: result.append(">");
0536: StringBuffer link = new StringBuffer(256);
0537: if (getCurrentPage() > 1) {
0538: // build the "Back" link
0539: result.append("<a");
0540: result.append(getStyle().getClassLink());
0541: result.append(" href=\"");
0542: link.append(getRequestContext().getUri());
0543: link.append("?");
0544: link.append(PARAM_ACTION).append("=").append(
0545: VALUE_ACTION_THUMBNAIL);
0546: link.append("&");
0547: link.append(PARAM_PAGE).append("=").append(
0548: getCurrentPage() - 1);
0549: result.append(link(link.toString()));
0550: result.append("\">");
0551: result.append(m_messages
0552: .key(Messages.GUI_NAVIGATION_BACK_0));
0553: result.append("</a>");
0554: result.append(" - ");
0555: } else {
0556: result.append(fillNavSpaces(m_messages
0557: .key(Messages.GUI_NAVIGATION_BACK_0)
0558: + " - "));
0559: }
0560: // build the page index information
0561: result.append(m_messages.key(Messages.GUI_THUMB_PAGEINFO_2,
0562: new Integer(getCurrentPage()), new Integer(
0563: getPageCount())));
0564: if (getCurrentPage() < getPageCount()) {
0565: // build the "Next" link
0566: result.append(" - ");
0567: result.append("<a class=\"");
0568: result.append(getStyle().getClassLink());
0569: result.append("\" href=\"");
0570: link = new StringBuffer(256);
0571: link.append(getRequestContext().getUri());
0572: link.append("?");
0573: link.append(PARAM_ACTION).append("=").append(
0574: VALUE_ACTION_THUMBNAIL);
0575: link.append("&");
0576: link.append(PARAM_PAGE).append("=").append(
0577: getCurrentPage() + 1);
0578: result.append(link(link.toString()));
0579: result.append("\">");
0580: result.append(m_messages
0581: .key(Messages.GUI_NAVIGATION_NEXT_0));
0582: result.append("</a>");
0583: } else {
0584: result.append(fillNavSpaces(" - "
0585: + m_messages
0586: .key(Messages.GUI_NAVIGATION_NEXT_0)));
0587: }
0588: result.append("</td>\n</tr>\n");
0589: }
0590: return result.toString();
0591: }
0592:
0593: /**
0594: * Returns the HTML for a text row on the thumbnail overview page of the photo album.<p>
0595: *
0596: * @param text the text to display in the row
0597: * @return the HTML for a text row on the thumbnail overview page of the photo album
0598: */
0599: protected String buildHtmlThumbTextRow(String text) {
0600:
0601: if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(text)) {
0602: StringBuffer result = new StringBuffer(2048);
0603: result.append("<tr>\n\t<td colspan=\"");
0604: result.append(getConfiguration().getThumbCols());
0605: result.append("\"");
0606: result.append(getStyle().getClassThumbText());
0607: result.append(">");
0608: result.append(text);
0609: result.append("</td>\n</tr>\n");
0610: return result.toString();
0611: }
0612: return "";
0613: }
0614:
0615: /**
0616: * Returns the HTML to build the detail view of a selected photo album image.<p>
0617: *
0618: * @return the HTML to build the detail view of a selected photo album image
0619: */
0620: protected String buildHtmlViewDetail() {
0621:
0622: StringBuffer result = new StringBuffer(4096);
0623:
0624: //show the photo gallery title
0625: result.append(buildHtmlAlbumTitle());
0626:
0627: // get the photo index number to show
0628: String indexParam = getRequest().getParameter(PARAM_IMAGE);
0629: int photoIndex = 0;
0630: if (CmsStringUtil.isNotEmpty(indexParam)) {
0631: // check the index parameter and set it to valid value if necessary
0632: photoIndex = Integer.parseInt(indexParam);
0633: if (photoIndex > (getAlbumPhotos().size() - 1)) {
0634: photoIndex = getAlbumPhotos().size() - 1;
0635: }
0636: }
0637:
0638: // get the photo to show
0639: CmsResource photo = (CmsResource) getAlbumPhotos().get(
0640: photoIndex);
0641: String resourceName = getCmsObject().getSitePath(photo);
0642:
0643: // determine the photo title
0644: String title = "";
0645: if (getConfiguration().showResourceNameAsTitle()) {
0646: title = CmsResource.getName(resourceName);
0647: }
0648: title = property(CmsPropertyDefinition.PROPERTY_TITLE,
0649: resourceName, title);
0650: title = CmsEncoder.escapeXml(title);
0651:
0652: result.append("<table border=\"0\"");
0653: result.append(getStyle().getClassThumbTable());
0654: result.append(" width=\"");
0655: result.append(getConfiguration().getDetailImageScaler()
0656: .getWidth());
0657: result.append("\">\n");
0658:
0659: // show the navigation if configured position is top above text
0660: result.append(buildHtmlImageNavigation(
0661: CmsPhotoAlbumConfiguration.NAVPOS_TOP_ABOVE,
0662: photoIndex, photo));
0663:
0664: // show the image title if configured
0665: if (getConfiguration().showDetailTitle()
0666: && CmsStringUtil.isNotEmptyOrWhitespaceOnly(title)) {
0667: result.append("<tr>\n\t<td");
0668: result.append(getStyle().getClassDetailImageTitle());
0669: result.append(getConfiguration().getStyleAlignAttribute(
0670: getConfiguration().getDetailAlignTitle()));
0671: result.append(">");
0672: result.append(title);
0673: result.append("</td>\n</tr>\n");
0674:
0675: }
0676:
0677: // show the navigation if configured position is top below text
0678: result.append(buildHtmlImageNavigation(
0679: CmsPhotoAlbumConfiguration.NAVPOS_TOP_BELOW,
0680: photoIndex, photo));
0681:
0682: // show image row
0683: result.append("<tr>\n\t<td>");
0684: // create the image
0685: result.append("<img src=\"");
0686: StringBuffer link = new StringBuffer(256);
0687: link.append(resourceName);
0688: link.append(getConfiguration().getDetailImageScaler()
0689: .toRequestParam());
0690: result.append(link(link.toString()));
0691: result.append("\" border=\"0\" width=\"");
0692: result.append(getConfiguration().getDetailImageScaler()
0693: .getWidth());
0694: result.append("\" height=\"");
0695: result.append(getConfiguration().getDetailImageScaler()
0696: .getHeight());
0697: result.append("\" alt=\"");
0698: result.append(title);
0699: result.append("\" title=\"");
0700: result.append(title);
0701: result.append("\" />");
0702: result.append("</td>\n</tr>\n");
0703:
0704: // show the navigation if configured position is bottom above text
0705: result.append(buildHtmlImageNavigation(
0706: CmsPhotoAlbumConfiguration.NAVPOS_BOTTOM_ABOVE,
0707: photoIndex, photo));
0708:
0709: // show the image description if configured and present
0710: if (getConfiguration().showDetailDescription()) {
0711: String description = property(
0712: CmsPropertyDefinition.PROPERTY_DESCRIPTION,
0713: resourceName, "");
0714: if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(description)) {
0715: result.append("<tr>\n\t<td");
0716: result.append(getStyle()
0717: .getClassDetailImageDescription());
0718: result.append(getConfiguration()
0719: .getStyleAlignAttribute(
0720: getConfiguration()
0721: .getDetailAlignTitle()));
0722: result.append(">");
0723: result.append(description);
0724: result.append("</td>\n</tr>\n");
0725: }
0726: }
0727:
0728: // show the navigation if configured position is bottom below text
0729: result.append(buildHtmlImageNavigation(
0730: CmsPhotoAlbumConfiguration.NAVPOS_BOTTOM_BELOW,
0731: photoIndex, photo));
0732:
0733: result.append("</table>");
0734: return result.toString();
0735: }
0736:
0737: /**
0738: * Returns the HTML to build a thumbnail overview page of the photo album.<p>
0739: *
0740: * @return the HTML to build a thumbnail overview page of the photo album
0741: */
0742: protected String buildHtmlViewThumbNail() {
0743:
0744: StringBuffer result = new StringBuffer(4096);
0745:
0746: // determine photo indizes to display and the number of thumb rows
0747: int startIndex = (getCurrentPage() - 1) * getPhotosPerPage();
0748: int endIndex = 0;
0749: int rowCount = getConfiguration().getThumbRows();
0750: if (getConfiguration().showPageNavigation()) {
0751: // navigation is shown, calculate end index
0752: endIndex = (getCurrentPage() * getPhotosPerPage()) - 1;
0753: if (endIndex > (getAlbumPhotos().size() - 1)) {
0754: endIndex = getAlbumPhotos().size() - 1;
0755: }
0756: } else {
0757: // all photos on one page
0758: endIndex = getAlbumPhotos().size() - 1;
0759: }
0760: int photoCount = endIndex - startIndex + 1;
0761: rowCount = photoCount / getConfiguration().getThumbCols();
0762: if ((photoCount % getConfiguration().getThumbCols()) > 0) {
0763: rowCount += 1;
0764: }
0765:
0766: // show the photo album title
0767: result.append(buildHtmlAlbumTitle());
0768:
0769: result.append("<table border=\"0\"");
0770: result.append(getStyle().getClassThumbTable());
0771: result.append(" width=\"");
0772: result.append(getConfiguration().getThumbCols()
0773: * getConfiguration().getThumbNailScaler().getWidth());
0774: result.append("\">\n");
0775:
0776: // show the navigation if configured position is top above text
0777: result
0778: .append(buildHtmlPageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_TOP_ABOVE));
0779:
0780: // show the top text if present
0781: result.append(buildHtmlThumbTextRow(getConfiguration()
0782: .getThumbTextTop()));
0783:
0784: // show the navigation if configured position is top below text
0785: result
0786: .append(buildHtmlPageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_TOP_BELOW));
0787:
0788: String styleAttr = getConfiguration().getStyleAlignAttribute(
0789: getConfiguration().getThumbAlignTitle());
0790:
0791: int photoIndex = startIndex;
0792: for (int i = 1; i <= rowCount; i++) {
0793: // build the table thumbnail rows
0794: result.append("<tr>\n");
0795: for (int k = 1; k <= getConfiguration().getThumbCols(); k++) {
0796: // build the tumbnail table data cell
0797: result.append("\t<td width=\"");
0798: result.append(getConfiguration().getThumbNailScaler()
0799: .getWidth());
0800: result.append("\"");
0801: result.append(getStyle().getClassThumbImageTitle());
0802: result.append(styleAttr);
0803: result.append(">");
0804: if (photoIndex <= endIndex) {
0805: // current photo is in list range, show it
0806: CmsResource photo = (CmsResource) getAlbumPhotos()
0807: .get(photoIndex);
0808: String resourceName = getCmsObject().getSitePath(
0809: photo);
0810: String title = "";
0811: if (getConfiguration().showResourceNameAsTitle()) {
0812: title = CmsResource.getName(resourceName);
0813: }
0814: title = property(
0815: CmsPropertyDefinition.PROPERTY_TITLE,
0816: resourceName, title);
0817: title = CmsEncoder.escapeXml(title);
0818: // create the link to the detail view
0819: result.append("<a href=\"");
0820: StringBuffer link = new StringBuffer(256);
0821: link.append(getRequestContext().getUri());
0822: link.append("?");
0823: link.append(PARAM_ACTION).append("=").append(
0824: VALUE_ACTION_DETAIL);
0825: link.append("&").append(PARAM_IMAGE)
0826: .append("=").append(photoIndex);
0827: result.append(link(link.toString()));
0828: result.append("\">");
0829: // create the scaled thumbnail
0830: result.append("<img src=\"");
0831: link = new StringBuffer(256);
0832: link.append(resourceName);
0833: link.append(getConfiguration().getThumbNailScaler()
0834: .toRequestParam());
0835: result.append(link(link.toString()));
0836: result.append("\" border=\"0\" width=\"");
0837: result.append(getConfiguration()
0838: .getThumbNailScaler().getWidth());
0839: result.append("\" height=\"");
0840: result.append(getConfiguration()
0841: .getThumbNailScaler().getHeight());
0842: result.append("\" alt=\"");
0843: result.append(title);
0844: result.append("\" title=\"");
0845: result.append(title);
0846: result.append("\" />");
0847: result.append("</a>");
0848: if (getConfiguration().showThumbTitle()
0849: && CmsStringUtil
0850: .isNotEmptyOrWhitespaceOnly(title)) {
0851: // show title below the thumbnail
0852: result.append("<br clear=\"all\" /><span");
0853: result.append(getStyle()
0854: .getClassThumbImageTitle());
0855: result.append(">");
0856: result.append(title);
0857: result.append("</span>");
0858: }
0859: photoIndex++;
0860: }
0861: result.append("</td>\n");
0862: }
0863: result.append("</tr>\n");
0864: }
0865:
0866: // show the navigation if configured position is bottom above text
0867: result
0868: .append(buildHtmlPageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_BOTTOM_ABOVE));
0869:
0870: // show the bottom text if present
0871: result.append(buildHtmlThumbTextRow(getConfiguration()
0872: .getThumbTextBottom()));
0873:
0874: // show the navigation if configured position is bottom below text
0875: result
0876: .append(buildHtmlPageNavigation(CmsPhotoAlbumConfiguration.NAVPOS_BOTTOM_BELOW));
0877:
0878: result.append("</table>");
0879: return result.toString();
0880: }
0881:
0882: /**
0883: * Determines the necessary page information to build the navigation elements for the album pages.<p>
0884: *
0885: * Calculates the following values and stores them in members:
0886: * <ul>
0887: * <li>the number of photos to display on one overview page</li>
0888: * <li>the current thumbnail page to show</li>
0889: * <li>the number of pages to create to show all images of the selected gallery</li>
0890: * </ul>
0891: */
0892: protected void calculatePageData() {
0893:
0894: if (getConfiguration().showPageNavigation()) {
0895: // show page navigation, do calculations
0896: setPhotosPerPage(getConfiguration().getThumbCols()
0897: * getConfiguration().getThumbRows());
0898: int pageCount = getAlbumPhotos().size()
0899: / getPhotosPerPage();
0900: if ((getAlbumPhotos().size() % getPhotosPerPage()) != 0) {
0901: pageCount++;
0902: }
0903: setPageCount(pageCount);
0904: // determine page to show
0905: String page = getRequest().getParameter(PARAM_PAGE);
0906: if (CmsStringUtil.isNotEmpty(page) && getPageCount() > 1) {
0907: int currentPage = Integer.parseInt(page);
0908: if (currentPage > getPageCount()) {
0909: currentPage = getPageCount();
0910: }
0911: setCurrentPage(currentPage);
0912: } else {
0913: setCurrentPage(1);
0914: }
0915: } else {
0916: // no navigation shown, set to default values
0917: setPhotosPerPage(0);
0918: setPageCount(1);
0919: setCurrentPage(1);
0920: }
0921: }
0922:
0923: /**
0924: * Returns if the current navigation position to check is the configured position.<p>
0925: *
0926: * @param currentPosition the current navigation position to check
0927: * @return true if the current navigation position to check is the configured position, otherwise false
0928: */
0929: protected boolean checkNavigationPosition(String currentPosition) {
0930:
0931: return getConfiguration().getNavigationPosition().indexOf(
0932: currentPosition) > -1;
0933: }
0934:
0935: /**
0936: * Returns non breakable spaces (<code>&nbsp;</code>) as replacement for the given replace value.<p>
0937: *
0938: * @param replaceValue the value to replace with spaces
0939: * @return non breakable spaces as replacement
0940: */
0941: protected String fillNavSpaces(String replaceValue) {
0942:
0943: int centerIndex = getConfiguration().getAlignNavigation()
0944: .indexOf("center");
0945: if (centerIndex > -1 && CmsStringUtil.isNotEmpty(replaceValue)) {
0946: int length = replaceValue.length();
0947: StringBuffer result = new StringBuffer(6 * length);
0948: for (int i = 0; i < length; i++) {
0949: result.append(" ");
0950: }
0951: return result.toString();
0952: }
0953: return "";
0954: }
0955:
0956: /**
0957: * Returns the configuration errors that occured.<p>
0958: *
0959: * @return the configuration errors that occured
0960: */
0961: protected List getConfigErrors() {
0962:
0963: return m_configErrors;
0964: }
0965:
0966: /**
0967: * Sets the configuration errors that occured.<p>
0968: *
0969: * @param configErrors the configuration errors that occured
0970: */
0971: protected void setConfigErrors(List configErrors) {
0972:
0973: m_configErrors = configErrors;
0974: }
0975:
0976: /**
0977: * Sets the current page to display for the thumbnail view.<p>
0978: *
0979: * @param currentPage the current page to display for the thumbnail view
0980: */
0981: protected void setCurrentPage(int currentPage) {
0982:
0983: m_currentPage = currentPage;
0984: }
0985:
0986: /**
0987: * Sets the display action to determine the view to generate.<p>
0988: *
0989: * @param displayAction the display action to determine the view to generate
0990: */
0991: protected void setDisplayAction(int displayAction) {
0992:
0993: m_displayAction = displayAction;
0994: }
0995:
0996: /**
0997: * Sets the number of pages to display for the thumbnail view.<p>
0998: *
0999: * @param pageCount the number of pages to display for the thumbnail view
1000: */
1001: protected void setPageCount(int pageCount) {
1002:
1003: m_pageCount = pageCount;
1004: }
1005:
1006: /**
1007: * Sets the number of photos to display on a single thumbnail overview page.<p>
1008: *
1009: * @param photosPerPage the number of photos to display on a single thumbnail overview page
1010: */
1011: protected void setPhotosPerPage(int photosPerPage) {
1012:
1013: m_photosPerPage = photosPerPage;
1014: }
1015:
1016: }
|