cmsexplorercontextmenubuilder.java
来自「找了很久才找到到源代码」· Java 代码 · 共 519 行 · 第 1/2 页
JAVA
519 行
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsExplorerContextMenuBuilder.java,v $
* Date : $Date: 2007-09-10 08:46:15 $
* Version: $Revision: 1.6 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 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.workplace.explorer;
import org.opencms.file.CmsResourceFilter;
import org.opencms.i18n.CmsEncoder;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.workplace.explorer.menu.CmsMenuItemVisibilityMode;
import org.opencms.workplace.explorer.menu.CmsMenuRule;
import org.opencms.workplace.explorer.menu.CmsMenuRuleTranslator;
import org.opencms.workplace.explorer.menu.CmsMirMultiStandard;
import org.opencms.workplace.explorer.menu.I_CmsMenuItemRule;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
/**
* Context menu builder class.<p>
*
* @author Michael Moossen
* @author Andreas Zahner
*
* @version $Revision: 1.6 $
*
* @since 6.5.6
*/
public class CmsExplorerContextMenuBuilder extends CmsWorkplace {
/** The HTML code for a separator context menu entry. */
private static final String HTML_SEPARATOR = "<li class=\"cmsep\"><span></span></li>";
/** The link target parameter value. */
private String m_paramActtarget;
/** The resource list parameter value. */
private String m_paramResourcelist;
/**
* Public constructor.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsExplorerContextMenuBuilder(CmsJspActionElement jsp) {
super(jsp);
}
/**
* Public constructor with JSP variables.<p>
*
* @param context the JSP page context
* @param req the JSP request
* @param res the JSP response
*/
public CmsExplorerContextMenuBuilder(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Generates the context menu for the given resources.<p>
*
* @return html code
*/
public String contextMenu() {
// get the resource path list
List resourceList = CmsStringUtil.splitAsList(getParamResourcelist(), "|");
// create a resource util object for the first resource in the list
CmsResourceUtil[] resUtil = new CmsResourceUtil[resourceList.size()];
for (int i = 0; i < resourceList.size(); i++) {
try {
resUtil[i] = new CmsResourceUtil(getCms(), getCms().readResource(
(String)resourceList.get(0),
CmsResourceFilter.ALL));
} catch (CmsException e) {
// fatal error
return "";
}
}
// the explorer type settings
CmsExplorerTypeSettings settings = null;
// get the context menu configuration for the given selection mode
CmsExplorerContextMenu contextMenu;
// single or multi selection?
boolean isSingleSelection = (resourceList.size() == 1);
if (isSingleSelection) {
// get the explorer type setting for the first resource
try {
settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(resUtil[0].getResourceTypeName());
} catch (Throwable e) {
return "";
}
if (settings == null || !settings.isEditable(getCms(), resUtil[0].getResource())) {
// the user has no access to this resource type
return "";
}
// get the context menu configuration
contextMenu = settings.getContextMenu();
} else {
// get the multi context menu configuration
if (OpenCms.getWorkplaceManager().getMultiContextMenu() == null) {
// no multi context menu defined, do not show menu
return "";
} else {
contextMenu = OpenCms.getWorkplaceManager().getMultiContextMenu();
}
}
// get an instance of the menu rule translator
CmsMenuRuleTranslator menuRuleTranslator = new CmsMenuRuleTranslator();
// store the mode results in a Map to optimize performance
Map storedModes = new HashMap();
StringBuffer menu = new StringBuffer(4096);
menu.append("<div id=\"menu\">");
buildHtmlContextMenu(
contextMenu.getAllEntries(),
null,
menu,
resUtil,
menuRuleTranslator,
isSingleSelection,
storedModes);
menu.append("</div>");
return menu.toString();
}
/**
* Returns the link target parameter value.<p>
*
* @return the link target parameter value
*/
public String getParamActtarget() {
return m_paramActtarget;
}
/**
* Returns the resourcelist parameter value.<p>
*
* @return the resourcelist parameter value
*/
public String getParamResourcelist() {
return m_paramResourcelist;
}
/**
* Sets the link target parameter value.<p>
*
* @param paramActtarget the link target parameter value to set
*/
public void setParamActtarget(String paramActtarget) {
m_paramActtarget = paramActtarget;
}
/**
* Sets the resourcelist parameter value.<p>
*
* @param paramResourcelist the resourcelist parameter value to set
*/
public void setParamResourcelist(String paramResourcelist) {
m_paramResourcelist = paramResourcelist;
}
/**
* Returns the HTML for the list of given context menu entry items.<p>
*
* @param contextMenuEntries the context menu entry items to loop
* @param parent the parent context menu entry item or null if none is defined
* @param menu the Buffer to add the HTML to
* @param resUtil the initialized resource utility to create the context menu for
* @param menuRuleTranslator the menu rule translator
* @param isSingleSelection flag indicating if more than one resource is selected
* @param storedModes caches the mode for the item rules
*/
protected void buildHtmlContextMenu(
List contextMenuEntries,
CmsExplorerContextMenuItem parent,
StringBuffer menu,
CmsResourceUtil[] resUtil,
CmsMenuRuleTranslator menuRuleTranslator,
boolean isSingleSelection,
Map storedModes) {
boolean insertSeparator = false;
boolean firstEntryWritten = false;
// open the menu list
menu.append("\n<ul");
if (parent != null) {
// we are in a sub menu, set the id
menu.append(" id=\"");
menu.append(parent.getKey().hashCode());
menu.append("\"");
}
menu.append(">");
// loop the menu items
Iterator it = contextMenuEntries.iterator();
while (it.hasNext()) {
CmsExplorerContextMenuItem item = (CmsExplorerContextMenuItem)it.next();
// check if the current item is a sub item and collect the parent IDs
StringBuffer parentIdsBuffer = new StringBuffer(64);
CmsExplorerContextMenuItem pItem = item;
boolean isFirst = true;
while (pItem.isSubItem()) {
// this is a sub item, collect parent IDs (used to determine which menus should be kept open)
if (isFirst) {
parentIdsBuffer.append("'");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?