⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menuitem.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        this.messageResourcesKey = messageResourcesKey;
        this.path = path;
        this.permissionsRequired = permissionsRequired;
        this.resourceTypeOfPermissionsRequired = resourceTypeOfPermissionsRequired;
        this.resourcesOfTypeRequired = resourcesOfTypeRequired;
    }

    /**
     * Add a child to this submenu.
     * 
     * @param menuItem menu item to add
     * @throws IllegalArgumentException if this menu item is a leaf
     */
    public void addChild(MenuItem menuItem) throws IllegalArgumentException {
        if (isLeaf()) {
            throw new IllegalArgumentException("Cannot add child menu items to leaf menu items.");
        }
        if (children == null) {
            children = new ArrayList();
        }
        children.add(menuItem);
    }

    /**
     * Remove a child from this menu
     * 
     * @param menuItem menu item to remove
     * @throws IllegalArgumentException if this menu item is a leaf
     */
    public void removeChild(MenuItem menuItem) throws IllegalArgumentException {
        if (isLeaf()) {
            throw new IllegalArgumentException("Cannot remove child menu items from leaf menu items.");
        }
        if (children != null) {
            children.remove(menuItem);
        }
    }

    /**
     * Get a child menu item given its name
     * 
     * @param id id
     * @return menu item
     */
    public MenuItem getChild(String id) {
        if (children != null) {
            for (Iterator i = children.iterator(); i.hasNext();) {
                MenuItem it = (MenuItem) i.next();
                if (it.getId().equals(id)) {
                    return it;
                }
            }
        }
        return null;
    }

    /**
     * Get if this menu item is a leaf. <code>false</code> means it is a
     * sub-menu
     * 
     * @return menu item is a leaf
     */
    public boolean isLeaf() {
        return leaf;
    }

    /**
     * Set the parent of menu item
     * 
     * @param parent
     */
    public void setParent(MenuItem parent) {
        this.parent = parent;
    }

    /**
     * Return the id of this menu item
     * 
     * @return
     */
    public String getId() {
        return id;
    }

    /**
     * Get the name of the bundle to use for the message resources required for
     * this menu item.
     * 
     * @return bunlde name
     */
    public String getMessageResourcesKey() {
        return messageResourcesKey;
    }

    /**
     * Get the browser target (e.g. _self, _blank etc). If a value of
     * <code>null</code> is returned, the default <strong>_self</strong>
     * should be used.
     * 
     * @return browser targe
     */
    public String getTarget() {
        return target;
    }

    /**
     * Return the URL or relative path that should be navigated to if this menu
     * item is actioned.
     * 
     * @return path
     */
    public String getPath() {
        return path;
    }

    /**
     * Determine if this menu item should be available based on the current
     * state. By default, this will check the current navigation context and
     * {@link #getPermissionId()}.
     * <p>
     * If the menu item has any other checks it should perform (checking if a
     * property is enabled for example), it should override this method
     * (probably calling the super implementation as well).
     * 
     * 
     * @param checkNavigationContext navigation context to check against
     * @param info user to check against permissions
     * @param request request
     * @return item is available
     */
    public boolean isAvailable(int checkNavigationContext, SessionInfo info, HttpServletRequest request) {
        if ((ContextHolder.getContext().isSetupMode() && ((navigationContext & SessionInfo.SETUP_CONSOLE_CONTEXT) != 0))
                        || (navigationContext & checkNavigationContext) != 0) {
            if (resourceTypeOfPermissionsRequired != null) {
                if (info == null) {
                    return false;
                }
                try {
                    boolean allowed = CoreServlet.getServlet().getPolicyDatabase().isResourcePermissionAllowed(
                                    resourceTypeOfPermissionsRequired, permissionsRequired, info.getUser(), false);
                    if (!allowed) {
                        if (resourcesOfTypeRequired != null) {
                            return CoreServlet.getServlet().getPolicyDatabase().isPrincipalGrantedResourcesOfType(info.getUser(),
                                            resourcesOfTypeRequired, null);
                        }
                        return false;
                    }
                    return true;
                } catch (Exception e) {
                    log.error("Failed to check delegation rights.", e);
                    return false;
                }
            } else {
                try {
                    if (resourcesOfTypeRequired != null) {               
                        return CoreServlet.getServlet().getPolicyDatabase().isPrincipalGrantedResourcesOfType(info.getUser(),
                                        resourcesOfTypeRequired, null);
                    }
                } catch (Exception e) {
                    log.error("Failed to check delegation rights.", e);
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    /**
     * Return an {@link List} of all child menu items that are valid for the
     * current state (as determined by {@link #isAvailable(HttpServletRequest)}.
     * 
     * @param checkNavigationContext navigation context to check against
     * @param info session info
     * @param request request
     * 
     * @return list of available children
     */
    public List availableChildren(int checkNavigationContext, SessionInfo info, HttpServletRequest request) {
        List l = new ArrayList();
        if (children != null) {
            for (Iterator i = children.iterator(); i.hasNext();) {
                MenuItem it = (MenuItem) i.next();
                if (it.isAvailable(navigationContext, info, request)) {
                    l.add(it);
                }
            }
        }
        return l;
    }

    /**
     * Get if the menu is empty (i.e. contains no child items).
     * 
     * @return menu is empty
     */
    public boolean isEmpty() {
        return children == null || children.size() == 0;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(Object arg0) {
        return new Integer(weight).compareTo(new Integer(((MenuItem) arg0).weight));
    }

    /**
     * Get the navigation context the menu item should appear in. This should be
     * a bitmask of the contstants
     * {@link com.sslexplorer.security.SessionInfo#USER_CONSOLE_CONTEXT} and
     * {@link com.sslexplorer.security.SessionInfo#MANAGEMENT_CONSOLE_CONTEXT}.
     * 
     * @return navigation context mask
     */
    public int getNavigationContext() {
        return navigationContext;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -