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

📄 panelmanager.java

📁 这是linux下ssl vpn的实现程序
💻 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.Collections;
import java.util.Comparator;
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;

/**
 * Allows <i>Panels</i> to be register.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.1 $
 * @see com.sslexplorer.core.Panel
 */
public class PanelManager {

    // Private instance variables
    private Map panels;

    // Private statics
    private static PanelManager instance;

    /*
     * Private constructor to prevent instantiation
     */
    private PanelManager() {
        super();
        panels = new HashMap();
    }

    /**
     * Add a panel
     * 
     * @param panel panel to add
     */
    public void addPanel(Panel panel) {
        panels.put(panel.getId(), panel);
    }

    /**
     * Remove a panel
     * 
     * @param id id of panel to remove
     */
    public void removePanel(String id) {
        panels.remove(id);
    }

    /**
     * Get an instance of the key store import type manager.
     * 
     * @return key store import type manager
     */
    public static PanelManager getInstance() {
        if (instance == null) {
            instance = new PanelManager();
        }
        return instance;
    }
    
    /**
     * Get a panel give its id. No check if the panel is available is made.
     * If no such panel exists <code>null</code> will be returned.
     * 
     *  @param id panel id
     *  @return panel
     */
    public Panel getPanel(String id) {
        return (Panel)panels.get(id);
    }

    /**
     * Get a sort list of registered {@link Panel} objects to display for the
     * given placement based on the current state. The {@link Panel#isAvailable(HttpServletRequest, HttpServletResponse)}
     * method will be called and only if this returns <i>true</i> will the
     * panel be in the list. 
     * 
     * @param placement placement
     * @param request request
     * @param response response
     * @return list of appropriate panels
     */
    public List getPanels(int placement, HttpServletRequest request, HttpServletResponse response) {
        List a = new ArrayList();
        for (Iterator i = panels.values().iterator(); i.hasNext();) {
            Panel p = (Panel) i.next();
            if (p.getPlacement() == placement && p.isAvailable(request, response)) {
                a.add(p);
            }
        }
        Collections.sort(a, new Comparator() {
            public int compare(Object arg0, Object arg1) {
                Panel p1 = (Panel) arg0;
                Panel p2 = (Panel) arg1;
                return new Integer(p1.getWeight()).compareTo(new Integer(p2.getWeight()));
            }

        });
        return a;
    }

}

⌨️ 快捷键说明

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