📄 cmsphotoalbumbean.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/photoalbum/CmsPhotoAlbumBean.java,v $
* Date : $Date: 2006/03/27 14:52:22 $
* Version: $Revision: 1.2 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2005 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.frontend.photoalbum;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.types.CmsResourceTypeImage;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.util.CmsStringUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import org.apache.commons.logging.Log;
/**
* Provides methods to generate frontend views of a photo album using a XML Content configuration file.<p>
*
* @author Andreas Zahner
*
* @version $Revision: 1.2 $
*
* @since 6.1.3
*/
public class CmsPhotoAlbumBean extends CmsJspActionElement {
/** Request parameter value for the album action: show detail view. */
public static final int ACTION_DETAIL = 1;
/** Request parameter value for the album action: show original image. */
public static final int ACTION_ORIGINAL = 2;
/** Request parameter value for the album action: show thumbnail view. */
public static final int ACTION_THUMBNAIL = 0;
/** Request parameter name for the action parameter. */
public static final String PARAM_ACTION = "action";
/** Request parameter name for the image parameter. */
public static final String PARAM_IMAGE = "image";
/** Request parameter name for the album page parameter. */
public static final String PARAM_PAGE = "thumbpage";
/** Request parameter value for the album action: show detail view. */
public static final String VALUE_ACTION_DETAIL = "detail";
/** Request parameter value for the album action: show original image. */
public static final String VALUE_ACTION_ORIGINAL = "original";
/** Request parameter value for the album action: show thumbnail view. */
public static final String VALUE_ACTION_THUMBNAIL = "thumbnail";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsPhotoAlbumBean.class);
/** The list of all photos to display in the photo album. */
private List m_albumPhotos;
/** Holds possible configuration error messages. */
private List m_configErrors;
/** The photo album configuration. */
private CmsPhotoAlbumConfiguration m_configuration;
/** The current page to display for the thumbnail view. */
private int m_currentPage;
/** The display action to determine the view to generate. */
private int m_displayAction;
/** The messages to use. */
private CmsMessages m_messages;
/** The number of pages to display for the thumbnail view. */
private int m_pageCount;
/** The number of photos to display on a single thumbnail overview page. */
private int m_photosPerPage;
/** The CSS style object that is used to format the photo album output. */
private CmsPhotoAlbumStyle m_style;
/**
* Constructor, creates the necessary photo album configuration objects.<p>
*
* @param context the JSP page context object
* @param req the JSP request
* @param res the JSP response
*/
public CmsPhotoAlbumBean(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(context, req, res, null);
}
/**
* Constructor, creates the necessary photo album configuration objects using a given configuration file URI.<p>
*
* @param context the JSP page context object
* @param req the JSP request
* @param res the JSP response
* @param configUri URI of the photo album configuration file, if not provided, current URI is used for configuration
*/
public CmsPhotoAlbumBean(PageContext context, HttpServletRequest req, HttpServletResponse res, String configUri) {
super(context, req, res);
init(configUri);
}
/**
* Builds the HTML to display the photo album.<p>
*
* @return the HTML to display the photo album
* @throws IOException if writing the output fails
*/
public String displayAlbum() throws IOException {
// show eventual configuration errors
buildHtmlConfigurationErrors();
// show selected album view
switch (getDisplayAction()) {
case ACTION_DETAIL:
return buildHtmlViewDetail();
case ACTION_ORIGINAL:
return "";
case ACTION_THUMBNAIL:
default:
return buildHtmlViewThumbNail();
}
}
/**
* Returns the list of all photos to display in the photo album.<p>
*
* @return the list of all photos to display in the photo album
*/
public List getAlbumPhotos() {
if (m_albumPhotos == null) {
CmsResourceFilter filter = CmsResourceFilter.DEFAULT.addRequireType(CmsResourceTypeImage.getStaticTypeId());
try {
m_albumPhotos = getCmsObject().readResources(getConfiguration().getVfsPathGallery(), filter, false);
} catch (CmsException e) {
// create empty photo list
m_albumPhotos = new ArrayList(0);
// log error
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(
Messages.LOG_ERR_IMAGEFOLDER_NOT_FOUND_1,
getConfiguration().getVfsPathGallery()));
}
addConfigError(m_messages.key(
Messages.LOG_ERR_IMAGEFOLDER_NOT_FOUND_1,
getConfiguration().getVfsPathGallery()));
}
}
return m_albumPhotos;
}
/**
* Returns the photo album configuration.<p>
*
* @return the photo album configuration
*/
public CmsPhotoAlbumConfiguration getConfiguration() {
return m_configuration;
}
/**
* Returns the current page to display for the thumbnail view.<p>
*
* @return the current page to display for the thumbnail view
*/
public int getCurrentPage() {
return m_currentPage;
}
/**
* Returns the display action to determine the view to generate.<p>
*
* @return the display action to determine the view to generate
*/
public int getDisplayAction() {
return m_displayAction;
}
/**
* Returns the number of pages to display for the thumbnail view.<p>
*
* @return the number of pages to display for the thumbnail view
*/
public int getPageCount() {
return m_pageCount;
}
/**
* Returns the number of photos to display on a single thumbnail overview page.<p>
*
* @return the number of photos to display on a single thumbnail overview page
*/
public int getPhotosPerPage() {
return m_photosPerPage;
}
/**
* Returns the CSS style object that is used to format the photo album output.<p>
*
* @return the CSS style object that is used to format the photo album output
*/
public CmsPhotoAlbumStyle getStyle() {
return m_style;
}
/**
* Initializes the photo album configuration and determines the display action.<p>
*
* @param configUri URI of the photo album configuration file, if not provided, current URI is used for configuration
*/
public void init(String configUri) {
// set messages
m_messages = Messages.get().getBundle(getRequestContext().getLocale());
// initialize empty list of configuration errors
setConfigErrors(new ArrayList());
// initialize the photo album CSS styles
setStyle(new CmsPhotoAlbumStyle());
// initialize the photo album configuration
try {
setConfiguration(new CmsPhotoAlbumConfiguration(this, configUri));
} catch (Exception e) {
// set empty configuration
setConfiguration(new CmsPhotoAlbumConfiguration());
if (e instanceof CmsException) {
// for Cms exceptions, show detailed error message
addConfigError(((CmsException)e).getLocalizedMessage(getRequestContext().getLocale()));
} else {
addConfigError(e.getLocalizedMessage());
}
}
// determine the album view to display depending on request parameter
String action = getRequest().getParameter(PARAM_ACTION);
if (VALUE_ACTION_DETAIL.equals(action)) {
// show the detail view
setDisplayAction(ACTION_DETAIL);
} else if (VALUE_ACTION_ORIGINAL.equals(action)) {
// show the original image
setDisplayAction(ACTION_ORIGINAL);
} else {
// default action: show the thumbnail overview
setDisplayAction(ACTION_THUMBNAIL);
}
// determine the necessary page data to build navigation elements
calculatePageData();
}
/**
* Sets the photo album configuration.<p>
*
* @param configuration the photo album configuration
*/
public void setConfiguration(CmsPhotoAlbumConfiguration configuration) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -