📄 menuitem.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.core;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.sslexplorer.boot.ContextHolder;
import com.sslexplorer.policyframework.Permission;
import com.sslexplorer.policyframework.ResourceType;
import com.sslexplorer.security.SessionInfo;
/**
* Represents a single item in the tree of available menu actions. A menu item
* may either be a submenu or a leaf menu item. Whenever a user navigates to a
* page, the entire tree of <code>MenuItem</code>s is travered looking for
* menu items that are valid for the current state. This is then used to build
* up a tree of {@link com.sslexplorer.core.AvailableMenuItem} objects that is
* passed to the view for rendering.
* <p>
* A <code>MenuItem</code> is deemed valid for the current state if
* <code>true</code> is returned from {@link #isAvailable(HttpServletRequest)}
* method. By default this checks the parmeters parameters passed to this object
* when constructing <code>administratorOnly</code>,
* <code>availableInSetup</code> and <code>permissionId</code>. If any
* actions have any special requirements as to when they are visible,
* <code>MenuItem</code> should be sub-classed and
* {@link #isAvailable(HttpServletRequest)} should be overidden.
* <p>
* Every menu item must have two message resources added to a bundle. The keys
* must be in the format <strong>menuItem.[id].name</strong> and
* <strong>menuItem.[id].description</strong>. The bundle name must be passed
* as the contructor parameter <code>messageResourcesKey</code>.
*
* @author Brett Smith <brett@3sp.com>
* @see com.sslexplorer.core.AvailableMenuItem
*/
public class MenuItem implements Comparable {
final static Log log = LogFactory.getLog(MenuItem.class);
// Protected instance variables
protected String messageResourcesKey;
protected String path;
protected List children;
protected MenuItem parent;
protected boolean leaf;
protected int weight;
protected int navigationContext;
protected ResourceType resourceTypeOfPermissionsRequired;
protected ResourceType resourcesOfTypeRequired;
protected Permission[] permissionsRequired;
// Private instance variables
private String id;
private String target = "_self";
/**
* Construct a new <code>MenuItem</code>.
*
* @param id menu item item
* @param messageResourcesKey the name of the resource bundle to retrieve
* menu name displayed to user
* @param part the URL or relative path that will be navigated to upon
* selecting this menu item
* @param weight weight of item in its parent menu used to order the items.
* @param leaf <code>true</code> if this item is not a sub-menu.
* @param navigationContext the navigation context this menu item should
* appear in. This should be a bitmask of the constants
* {@link com.sslexplorer.security.SessionInfo#USER_CONSOLE_CONTEXT}
* and
* {@link com.sslexplorer.security.SessionInfo#MANAGEMENT_CONSOLE_CONTEXT}.
*/
public MenuItem(String id, String messageResourcesKey, String path, int weight, boolean leaf, int navigationContext) {
this(id, messageResourcesKey, path, weight, leaf, null, navigationContext, null, null, null);
}
/**
* Construct a new <code>MenuItem</code>.
*
* @param id menu item item
* @param messageResourcesKey the name of the resource bundle to retrieve
* menu name displayed to user
* @param part the URL or relative path that will be navigated to upon
* selecting this menu item
* @param weight weight of item in its parent menu used to order the items.
* @param availableInSetup the action is only valid when in setup mode
* @param leaf <code>true</code> if this item is not a sub-menu.
* @param target the browser target (i.e. _self, _blank etc). A value of
* null means _self.
* @param navigationContext the navigation context this menu item should
* appear in. This should be a bitmask of the constants
* {@link com.sslexplorer.security.SessionInfo#USER_CONSOLE_CONTEXT}
* and
* {@link com.sslexplorer.security.SessionInfo#MANAGEMENT_CONSOLE_CONTEXT}.
*/
public MenuItem(String id, String messageResourcesKey, String path, int weight, boolean leaf, String target,
int navigationContext) {
this(id, messageResourcesKey, path, weight, leaf, target, navigationContext, null, null, null);
}
/**
* Construct a new <code>MenuItem</code>. Because resource type can be
* supplied, this implies that the menu item is for the management console
*
* @param id menu item item
* @param messageResourcesKey the name of the resource bundle to retrieve
* menu name displayed to user
* @param part the URL or relative path that will be navigated to upon
* selecting this menu item
* @param weight weight of item in its parent menu used to order the items
* @param leaf <code>true</code> if this item is not a sub-menu.
* @param navigationContext the navigation context this menu item should
* appear in. This should be a bitmask of the constants
* {@link com.sslexplorer.security.SessionInfo#USER_CONSOLE_CONTEXT}
* and
* {@link com.sslexplorer.security.SessionInfo#MANAGEMENT_CONSOLE_CONTEXT}.
* @param resourceTypeOfPermissionsRequired resource type of any resource
* permissions required. May be <code>null</code> if you do not
* wish to check for permissions
* @param permissionsRequired array of required permission. Must be supplied
* if you have specified a
* <code>resourceTypeOfPermissionsRequired</code> otherwise may be
* null.
*/
public MenuItem(String id, String messageResourcesKey, String path, int weight, boolean leaf, ResourceType resourceTypeOfPermissionsRequired,
Permission[] permissionsRequired) {
this(id, messageResourcesKey, path, weight, leaf, null, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, resourceTypeOfPermissionsRequired, permissionsRequired,
null);
}
/**
* Construct a new <code>MenuItem</code>.
*
* @param id menu item item
* @param messageResourcesKey the name of the resource bundle to retrieve
* menu name displayed to user
* @param part the URL or relative path that will be navigated to upon
* selecting this menu item
* @param weight weight of item in its parent menu used to order the items.
* @param leaf <code>true</code> if this item is not a sub-menu.
* @param target the browser target (i.e. _self, _blank etc). A value of
* null means _self.
* @param navigationContext the navigation context this menu item should
* appear in. This should be a bitmask of the constants
* {@link com.sslexplorer.security.SessionInfo#USER_CONSOLE_CONTEXT}
* and
* {@link com.sslexplorer.security.SessionInfo#MANAGEMENT_CONSOLE_CONTEXT}.
* @param resourceTypeOfPermissionsRequired resource type of any resource
* permissions required. May be <code>null</code> if you do not
* wish to check for permissions
* @param permissionsRequired array of required permission. Must be supplied
* if you have specified a
* <code>resourceTypeOfPermissionsRequired</code> otherwise may be
* null.
*/
public MenuItem(String id, String messageResourcesKey, String path, int weight, boolean leaf, String target,
int navigationContext, ResourceType resourceTypeOfPermissionsRequired, Permission[] permissionsRequired) {
this(id, messageResourcesKey, path, weight, leaf, target, navigationContext, resourceTypeOfPermissionsRequired, permissionsRequired, null);
}
/**
* Construct a new <code>MenuItem</code>.
*
* @param id menu item item
* @param messageResourcesKey the name of the resource bundle to retrieve
* menu name displayed to user
* @param part the URL or relative path that will be navigated to upon
* selecting this menu item
* @param weight weight of item in its parent menu used to order the items.
* @param leaf <code>true</code> if this item is not a sub-menu.
* @param target the browser target (i.e. _self, _blank etc). A value of
* null means _self.
* @param navigationContext the navigation context this menu item should
* appear in. This should be a bitmask of the constants
* {@link com.sslexplorer.security.SessionInfo#USER_CONSOLE_CONTEXT}
* and
* {@link com.sslexplorer.security.SessionInfo#MANAGEMENT_CONSOLE_CONTEXT}.
* @param resourceTypeOfPermissionsRequired resource type of any resource
* permissions required. May be <code>null</code> if you do not
* wish to check for permissions
* @param permissionsRequired array of required permission. Must be supplied
* if you have specified a
* <code>resourceTypeOfPermissionsRequired</code> otherwise may be
* null.
* @param resourcesOfTypeRequired if specified the user must have access to
* at least one resource of the type.
*/
public MenuItem(String id, String messageResourcesKey, String path, int weight, boolean leaf, String target,
int navigationContext, ResourceType resourceTypeOfPermissionsRequired, Permission[] permissionsRequired,
ResourceType resourcesOfTypeRequired) {
super();
this.navigationContext = navigationContext;
this.target = target == null ? "_self" : target;
this.id = id;
this.leaf = leaf;
this.weight = weight;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -