📄 cmstemplatenavigation.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/CmsTemplateNavigation.java,v $
* Date : $Date: 2006/03/27 14:52:51 $
* Version: $Revision: 1.31 $
*
* 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.templateone;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspNavElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsStringUtil;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.types.I_CmsXmlContentValue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import org.apache.commons.logging.Log;
/**
* Provides methods to build the different navigations for the OpenCms template one.<p>
*
* The navigation methods are used by the included JSP elements of template one.
* The inclusion has to be done by passing the Map of request parameters to the included
* element. The following request parameters have to be added before inclusion:
* <ul>
* <li>the current locale</li>
* <li>the resource path to the used navigation icons</li>
* <li>the start folder to build the navigation from</li>
* <li>the head navigation start folder to build the navigation from</li>
* <li>the flag to determine if the head navigation menus are enabled</li>
* <li>the flag to determine if the left navigation follows the head navigation selection</li>
* </ul>
*
* Remember to set the Flex cache settings of the navigation elements to consider these
* request parameters.<p>
*
* @author Andreas Zahner
*
* @version $Revision: 1.31 $
*
* @since 6.0.0
*/
public class CmsTemplateNavigation extends CmsTemplateBase {
/** Configuration file name for the optional manual head navigation configuration. */
public static final String FILE_CONFIG_HEADNAV = "headnav";
/** Request parameter name for the head navigation start folder. */
public static final String PARAM_HEADNAV_FOLDER = "headnavfolder";
/** Request parameter name for the head navigation flag to use images on 1st level. */
public static final String PARAM_HEADNAV_IMAGES = "headnavimages";
/** Request parameter name for the head navigation flag to mark the current top level folder. */
public static final String PARAM_HEADNAV_MARKCURRENT = "headnavmarkcurrent";
/** Request parameter name for the head navigation flag to manually configure the head navigation. */
public static final String PARAM_HEADNAV_MANUAL = "headnavmanual";
/** Request parameter name for the head navigation flag to expand the submenus on click (true) or mouseover (false). */
public static final String PARAM_HEADNAV_MENUCLICK = "headnavmenuclick";
/** Request parameter name for the head navigation sub menu depth. */
public static final String PARAM_HEADNAV_MENUDEPTH = "headnavmenudepth";
/** Request parameter name for the current locale. */
public static final String PARAM_LOCALE = "locale";
/** Request parameter name for the left navigation editable include element uri. */
public static final String PARAM_NAVLEFT_ELEMENTURI = "navleftelementuri";
/** Request parameter name for the flag if the left navigation should display only the selected resources. */
public static final String PARAM_NAVLEFT_SHOWSELECTED = "navleftselected";
/** Request parameter name for the flag if the left navigation tree should be displayed. */
public static final String PARAM_NAVLEFT_SHOWTREE = "navleftshowtree";
/** Request parameter name for the current resource path. */
public static final String PARAM_RESPATH = "respath";
/** Request parameter name for the flag if the head navigation menus should be shown. */
public static final String PARAM_SHOWMENUS = "showmenus";
/** Request parameter name for the current start folder. */
public static final String PARAM_STARTFOLDER = "startfolder";
/** Name of the property key to determine if the current element is shown in headnav. */
public static final String PROPERTY_HEADNAV_USE = "style_head_nav_showitem";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsTemplateBean.class);
/** Stores the global website area configuration. */
private CmsXmlContent m_globalConfiguration;
/** Stores the optional head navigation configuration. */
private CmsXmlContent m_headNavConfiguration;
/** Stores the path to the head navigation start folder. */
private String m_headNavFolder;
/** The default behaviour to include items in head navigation menu if property <code>style_head_nav_showitem</code> is not set. */
private boolean m_headNavItemDefaultValue;
/** Determines if the head navigation menu should be created from a manual configuration file. */
private boolean m_headNavManual;
/** Determines if the currently active top folder should be marked in the head navigation. */
private boolean m_headNavMarkCurrent;
/** Determines if the submenus are expanded on click (true) or mouseover (false). */
private boolean m_headNavMenuClick;
/** Stores the current locale value. */
private String m_locale;
/** The maximum depth of the sub menus in the head navigation. */
private int m_menuDepth;
/** Stores the localized resource Strings. */
private CmsMessages m_messages;
/** Stores the left navigation include element uri. */
private String m_navLeftElementUri;
/** Flag if the left navigation should display only the selected resources. */
private boolean m_navLeftShowSelected;
/** Flag if the left navigation tree should be displayed. */
private boolean m_navLeftShowTree;
/** Stores the substituted path to the modules resources. */
private String m_resPath;
/** Indicates if accessible version is shown. */
private boolean m_showAccessibleVersion;
/** Flag that determines if the head navigation 1st row should use images instead of text links. */
private boolean m_showHeadNavImages;
/** Flag to determine if the DHTML menus (2nd level) of the head navigation should be shown. */
private boolean m_showMenus;
/** Stores the path to the start folder for navigation and search. */
private String m_startFolder;
/**
* Empty constructor, required for every JavaBean.<p>
*/
public CmsTemplateNavigation() {
super();
}
/**
* Constructor, with parameters.<p>
*
* Use this constructor for the template.<p>
*
* @param context the JSP page context object
* @param req the JSP request
* @param res the JSP response
*/
public CmsTemplateNavigation(PageContext context, HttpServletRequest req, HttpServletResponse res) {
super();
init(context, req, res);
}
/**
* Returns the html for the bread crumb navigation above the page content.<p>
*
* The bread crumb navigation is only displayed if the folder depth of the current
* URI is deeper than 3 levels relative to the defined start level.<p>
*
* @param styleClass the CSS class name to use in the <div> and <a> elements
* @return the html for the bread crumb navigation above the page content
*/
public String buildNavigationBreadCrumb(String styleClass) {
StringBuffer result = new StringBuffer(512);
// get start level of the displayed tree
int startLevel = 1;
if (showNavLeftSelected()) {
// follow selection in head navigation
startLevel = CmsResource.getPathLevel(getHeadNavFolder());
} else {
// create default navigation
startLevel = CmsResource.getPathLevel(getStartFolder());
}
// get navigation for requested uri
CmsJspNavElement currentPage = getNavigation().getNavigationForResource(getRequestContext().getUri());
// get the level of the requested uri
int currentLevel = currentPage.getNavTreeLevel();
// determine level delta
int deltaLevel = currentLevel - startLevel;
// check if navigation is shown
boolean showNavigation = deltaLevel > 3 || (deltaLevel == 3 && currentPage.isInNavigation());
if (showNavigation) {
// create the navigation row
String separator = ">";
result.append("<div class=\"");
result.append(styleClass);
result.append("\">");
List navElements = getNavigation().getNavigationBreadCrumb(startLevel + 3, true);
for (int i = 0; i < navElements.size(); i++) {
CmsJspNavElement nav = (CmsJspNavElement)navElements.get(i);
result.append("<a href=\"");
result.append(link(nav.getResourceName()));
result.append("\" class=\"");
result.append(styleClass);
result.append("\" title=\"");
result.append(nav.getNavText());
result.append("\">");
result.append(separator);
result.append(" ");
result.append(nav.getNavText());
result.append("</a>\n");
}
if (currentPage.isInNavigation()) {
// show current page in navigation list
result.append("<a href=\"");
result.append(link(currentPage.getResourceName()));
result.append("\" class=\"");
result.append(styleClass);
result.append("\" title=\"");
result.append(currentPage.getNavText());
result.append("\">");
result.append(separator);
result.append(" ");
result.append(currentPage.getNavText());
result.append("</a>\n");
}
result.append("</div>");
}
return result.toString();
}
/**
* Returns the html for the head navigation row.<p>
*
* This method only creates the head row part, be sure to add the
* dhtml menu entries by calling the method buildNavigationHeadMenus(java.lang.String).<p>
*
* @param homeLabel the label of the "home" link
* @param styleLink the CSS class name of the link node
* @param styleSeparator the CSS class name of the spearator node
* @return the html for the head navigation row
*/
public String buildNavigationHead(String homeLabel, String styleLink, String styleSeparator) {
boolean firstItem = true;
StringBuffer result = new StringBuffer(1024);
result.append("<div class=\"");
result.append(styleLink);
result.append("\">\n");
result.append("\t<!-- Start Topnavigation -->\n");
boolean showHomeLink = Boolean.valueOf(getConfigurationValue("headnav.homelink/link.show", CmsStringUtil.TRUE)).booleanValue();
if (showHomeLink && !showHeadNavImages()) {
// create the "home" link at first position
boolean onlyIndex = Boolean.valueOf(
getConfigurationValue("headnav.homelink/link.onlyindex", CmsStringUtil.FALSE)).booleanValue();
String url = getStartFolder();
String target = "_self";
if ((onlyIndex && isDefaultFile(getStartFolder(), getRequestContext().getUri())) || (!onlyIndex)) {
// settings only valid for start page of microsite or for all subpages
url = getConfigurationValue("headnav.homelink/link.url", getStartFolder());
homeLabel = getConfigurationValue("headnav.homelink/link.text", homeLabel);
target = getConfigurationValue("headnav.homelink/link.target", "_self");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -