📄 cmsphotoalbumconfiguration.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/photoalbum/CmsPhotoAlbumConfiguration.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 com.alkacon.simapi.Simapi;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.loader.CmsImageScaler;
import org.opencms.main.CmsException;
import org.opencms.util.CmsStringUtil;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlContentFactory;
import org.opencms.xml.types.CmsXmlHtmlValue;
import java.awt.Color;
import java.util.List;
import java.util.Locale;
/**
* Represents the frontend configuration of a photo album.<p>
*
* @author Andreas Zahner
*
* @version $Revision: 1.2 $
*
* @since 6.1.3
*/
public class CmsPhotoAlbumConfiguration {
/** Image filter: delimiter character. */
public static final String FILTER_DELIMITER = ".";
/** Image filter: no filter selected. */
public static final String FILTER_NONE = "none";
/** Navigation element position: on the bottom, above the editable text element. */
public static final String NAVPOS_BOTTOM_ABOVE = "b_a";
/** Navigation element position: on the bottom, below the editable text element. */
public static final String NAVPOS_BOTTOM_BELOW = "b_b";
/** Navigation element position: on top, above the editable text element. */
public static final String NAVPOS_TOP_ABOVE = "t_a";
/** Navigation element position: on top, below the editable text element. */
public static final String NAVPOS_TOP_BELOW = "t_b";
/** Configuration node name for the align navigation node. */
public static final String NODE_ALIGN_NAVIGATION = "AlignNavigation";
/** Configuration node name for the align navigation node. */
public static final String NODE_ALIGN_TITLE = "AlignTitle";
/** Configuration node name for the background node. */
public static final String NODE_BACKGROUND = "Background";
/** Configuration node name for the columns node. */
public static final String NODE_COLS = "Cols";
/** Configuration node name for the detail node. */
public static final String NODE_DETAIL = "Details";
/** Configuration node name for the filter node. */
public static final String NODE_FILTER = "Filter";
/** Configuration node name for the high quality node. */
public static final String NODE_HIGHQUALITY = "HighQuality";
/** Configuration node name for the navigation position node. */
public static final String NODE_NAVIGATION_POSITION = "NavigationPosition";
/** Configuration node name for the rows node. */
public static final String NODE_ROWS = "Rows";
/** Configuration node name for the show description node. */
public static final String NODE_SHOWDESCRIPTION = "ShowDescription";
/** Configuration node name for the show original link node. */
public static final String NODE_SHOWLINKORIGINAL = "ShowLinkOriginal";
/** Configuration node name for the show resource name as title node. */
public static final String NODE_SHOWRESOURCENAMEASTITLE = "ShowResourceNameAsTitle";
/** Configuration node name for the show title node. */
public static final String NODE_SHOWTITLE = "ShowTitle";
/** Configuration node name for the size node. */
public static final String NODE_SIZE = "Size";
/** Configuration node name for the bottom text node. */
public static final String NODE_TEXTBOTTOM = "TextBottom";
/** Configuration node name for the top text node. */
public static final String NODE_TEXTTOP = "TextTop";
/** Configuration node name for the thumbs node. */
public static final String NODE_THUMBS = "Thumbs";
/** Configuration node name for the title node. */
public static final String NODE_TITLE = "Title";
/** Configuration node name for the vfs folder node. */
public static final String NODE_VFSFOLDER = "VfsFolder";
/** The image album title. */
private String m_albumTitle;
/** The alignment of the album navigation elements. */
private String m_alignNavigation;
/** The alignment of the image titles on the detail view. */
private String m_detailAlignTitle;
/** The image scaler for the detail image. */
private CmsImageScaler m_detailImageScaler;
/** The navigation element position on the pages. */
private String m_navigationPosition;
/** The flag if the image description is shown on the detail view. */
private boolean m_showDetailDescription;
/** The flag if the image original link is shown on the detail view. */
private boolean m_showDetailOriginalLink;
/** The flag if the image title is shown on the detail view. */
private boolean m_showDetailTitle;
/** The flag if the image resource name is shown as title if no title is found. */
private boolean m_showResourceNameAsTitle;
/** The flag if the image title is shown on the thumbnail overview. */
private boolean m_showThumbTitle;
/** The alignment of the image titles on the thumbnail overview. */
private String m_thumbAlignTitle;
/** The number of image columns on the thumbnail overview. */
private int m_thumbCols;
/** The image scaler for the thumbnails. */
private CmsImageScaler m_thumbNailScaler;
/** The number of image rows on the thumbnail overview. */
private int m_thumbRows;
/** The optional bottom text on the thumbnail overview. */
private String m_thumbTextBottom;
/** The optional top text on the thumbnail overview. */
private String m_thumbTextTop;
/** The OpenCms VFS path of the image gallery to use. */
private String m_vfsPathGallery;
/**
* Empty constructor that does no initialization.<p>
*/
public CmsPhotoAlbumConfiguration() {
// initialize member objects
initMembers();
}
/**
* Constructor that initializes the configuration using the currently requested URI.<p>
*
* @param jsp the initialized CmsJspActionElement to access the OpenCms API
* @throws Exception if parsing the configuration fails
*/
public CmsPhotoAlbumConfiguration(CmsJspActionElement jsp)
throws Exception {
init(jsp, null);
}
/**
* Constructor that initializes the configuration from the given configuration URI.<p>
*
* @param jsp the initialized CmsJspActionElement to access the OpenCms API
* @param configUri URI of the configuration file, if not provided, current URI is used for configuration
* @throws Exception if parsing the configuration fails
*/
public CmsPhotoAlbumConfiguration(CmsJspActionElement jsp, String configUri)
throws Exception {
init(jsp, configUri);
}
/**
* Returns the image album title.<p>
*
* @return the image album title
*/
public String getAlbumTitle() {
return m_albumTitle;
}
/**
* Returns the alignment of the album navigation elements.<p>
*
* @return the alignment of the album navigation elements
*/
public String getAlignNavigation() {
return m_alignNavigation;
}
/**
* Returns the alignment of the image titles on the detail view.<p>
*
* @return the alignment of the image titles on the detail view
*/
public String getDetailAlignTitle() {
return m_detailAlignTitle;
}
/**
* Returns the image scaler for the detail image.<p>
*
* @return the image scaler for the detail image
*/
public CmsImageScaler getDetailImageScaler() {
return m_detailImageScaler;
}
/**
* Returns the navigation element position on the pages.<p>
*
* @return the navigation element position on the pages
*/
public String getNavigationPosition() {
return m_navigationPosition;
}
/**
* Returns the alignment of the image titles on the thumbnail overview.<p>
*
* @return the alignment of the image titles on the thumbnail overview
*/
public String getThumbAlignTitle() {
return m_thumbAlignTitle;
}
/**
* Returns the number of image columns on the thumbnail overview.<p>
*
* @return the number of image columns on the thumbnail overview
*/
public int getThumbCols() {
return m_thumbCols;
}
/**
* Returns the image scaler for the thumbnails.<p>
*
* @return the image scaler for the thumbnails
*/
public CmsImageScaler getThumbNailScaler() {
return m_thumbNailScaler;
}
/**
* Returns the number of image rows on the thumbnail overview.<p>
*
* @return the number of image rows on the thumbnail overview
*/
public int getThumbRows() {
return m_thumbRows;
}
/**
* Returns the optional bottom text on the thumbnail overview.<p>
*
* @return the optional bottom text on the thumbnail overview
*/
public String getThumbTextBottom() {
return m_thumbTextBottom;
}
/**
* Returns the optional top text on the thumbnail overview.<p>
*
* @return the optional top text on the thumbnail overview
*/
public String getThumbTextTop() {
return m_thumbTextTop;
}
/**
* Returns the OpenCms VFS path of the image gallery to use.<p>
*
* @return the OpenCms VFS path of the image gallery to use
*/
public String getVfsPathGallery() {
return m_vfsPathGallery;
}
/**
* Initializes the album configuration.<p>
*
* @param jsp the initialized CmsJspActionElement to access the OpenCms API
* @param configUri URI of the form configuration file, if not provided, current URI is used for configuration
*
* @throws Exception if parsing the configuration fails
*/
public void init(CmsJspActionElement jsp, String configUri) throws Exception {
// initialize member objects
initMembers();
// read the album configuration file from VFS
if (CmsStringUtil.isEmpty(configUri)) {
configUri = jsp.getRequestContext().getUri();
}
CmsFile file = jsp.getCmsObject().readFile(configUri);
CmsXmlContent content = CmsXmlContentFactory.unmarshal(jsp.getCmsObject(), file);
// get locale from request context
Locale locale = jsp.getRequestContext().getLocale();
// get the cms object
CmsObject cms = jsp.getCmsObject();
// get the album title
String stringValue = content.getStringValue(cms, NODE_TITLE, locale);
setAlbumTitle(getConfigurationValue(stringValue, ""));
// get the gallery vfs folder
stringValue = content.getStringValue(cms, NODE_VFSFOLDER, locale);
setVfsPathGallery(getConfigurationValue(stringValue, ""));
// get the alignment of navigation elements
stringValue = content.getStringValue(cms, NODE_ALIGN_NAVIGATION, locale);
setAlignNavigation(getConfigurationValue(stringValue, "left"));
// get the position of navigation elements
stringValue = content.getStringValue(cms, NODE_NAVIGATION_POSITION, locale);
setNavigationPosition(getConfigurationValue(stringValue, NAVPOS_BOTTOM_BELOW));
// get the show resource name as title flag
stringValue = content.getStringValue(cms, NODE_SHOWRESOURCENAMEASTITLE, locale);
setShowResourceNameAsTitle(Boolean.valueOf(stringValue).booleanValue());
// get the thumbnail configuration parameters
String nodePrefix = NODE_THUMBS + "/";
// get the show thumbs title flag
stringValue = content.getStringValue(cms, nodePrefix + NODE_SHOWTITLE, locale);
setShowThumbTitle(Boolean.valueOf(stringValue).booleanValue());
// get the alignment of thumbs title
stringValue = content.getStringValue(cms, nodePrefix + NODE_ALIGN_TITLE, locale);
setThumbAlignTitle(getConfigurationValue(stringValue, "left"));
// get the number of displayed columns
stringValue = content.getStringValue(cms, nodePrefix + NODE_COLS, locale);
setThumbCols(Integer.parseInt(getConfigurationValue(stringValue, "1")));
// get the number of rows per page
stringValue = content.getStringValue(cms, nodePrefix + NODE_ROWS, locale);
setThumbRows(Integer.parseInt(getConfigurationValue(stringValue, "-1")));
// get the thumbnail background color
stringValue = content.getStringValue(cms, nodePrefix + NODE_BACKGROUND, locale);
stringValue = getConfigurationValue(stringValue, "#FFFFFF");
Color color = Color.WHITE;
try {
color = Color.decode(stringValue);
} catch (NumberFormatException e) {
throw new CmsException(Messages.get().container(Messages.LOG_ERR_WRONG_THUMB_BGCOLOR_1, stringValue));
}
getThumbNailScaler().setColor(color);
// get the thumbs high quality flag
stringValue = content.getStringValue(cms, nodePrefix + NODE_HIGHQUALITY, locale);
if (Boolean.valueOf(stringValue).booleanValue()) {
// use high quality for thumbnails
getThumbNailScaler().setQuality(85);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -