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

📄 abstractwizardpolicyselectionform.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.policyframework.forms;

import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.sslexplorer.boot.PropertyList;
import com.sslexplorer.core.BundleActionMessage;
import com.sslexplorer.input.MultiSelectDataSource;
import com.sslexplorer.input.MultiSelectSelectionModel;
import com.sslexplorer.wizard.AbstractWizardSequence;
import com.sslexplorer.wizard.forms.DefaultWizardForm;

public abstract class AbstractWizardPolicySelectionForm extends DefaultWizardForm {
    

    private MultiSelectSelectionModel policyModel;
    private PropertyList selectedPolicies;
    
    // Statics for sequence attributes
    public final static String ATTR_SELECTED_POLICIES = "selectedPolicies";

    public AbstractWizardPolicySelectionForm(boolean nextAvailable, boolean previousAvailable, String page, String focussedField, boolean autoComplete, boolean finishAvailable, String pageName, String resourceBundle, String resourcePrefix, int stepIndex) {
        super(nextAvailable, previousAvailable, page, focussedField, autoComplete, finishAvailable, pageName, resourceBundle,
            resourcePrefix, stepIndex);
    }   

    /* (non-Javadoc)
     * @see com.sslexplorer.wizard.forms.DefaultWizardForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        if(isCommiting()) {
            if(selectedPolicies.size() == 0) {
                ActionErrors errs = new ActionErrors();
                errs.add(Globals.ERROR_KEY, new BundleActionMessage(getResourceBundle(), getResourcePrefix() + ".error.noPoliciesSelected"));
                return errs;
            }
            else {
                /* Make sure the selected policies are all currently available, this prevents
                 * anyone fiddling the polices they are allowed to configure
                 */
                for(Iterator i = selectedPolicies.iterator(); i.hasNext(); ) {
                    String pol = (String)i.next();
                    if(!policyModel.contains(pol)) {
                        throw new Error("User doesn't have permission to select the policy '" + pol + "', this shouldn't happen.");
                    }
                }
            }
        }
        return super.validate(mapping, request);
    }


    /**
     * @return Returns the selectedPolicies.
     */
    public String getSelectedPolicies() {
        return selectedPolicies.getAsTextFieldText();
    }

    /**
     * @param selectedPolicies The selectedPolicies to set.
     */
    public void setSelectedPolicies(String selectedPolicies) {
        this.selectedPolicies.setAsTextFieldText(selectedPolicies);
    }

    /**
     * @return Returns the policyModel.
     */
    public MultiSelectSelectionModel getPolicyModel() {
        return policyModel;
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.wizard.forms.DefaultWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
     */
    public void apply(AbstractWizardSequence sequence) throws Exception {
        super.apply(sequence);
        sequence.putAttribute(getAttributeKey(), selectedPolicies);
    }

    /**
     * @param policyModel The policyModel to set.
     */
    public void setPolicyModel(MultiSelectSelectionModel policyModel) {
        this.policyModel = policyModel;
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.wizard.forms.AbstractWizardForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset(mapping, request);
        AbstractWizardSequence seq = getWizardSequence(request);
        selectedPolicies = (PropertyList)seq.getAttribute(getAttributeKey(), new PropertyList());        
        MultiSelectDataSource policies = createDatasource(mapping, request);
        policyModel = new MultiSelectSelectionModel(policies, selectedPolicies);
    }

    public abstract MultiSelectDataSource createDatasource(ActionMapping mapping, HttpServletRequest request);
    
    protected String getAttributeKey() {
        return ATTR_SELECTED_POLICIES;
    }
}

⌨️ 快捷键说明

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