KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > forms > AbstractWizardPolicySelectionForm


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.policyframework.forms;
21
22 import java.util.Iterator JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.struts.Globals;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionMapping;
29
30 import com.sslexplorer.boot.PropertyList;
31 import com.sslexplorer.core.BundleActionMessage;
32 import com.sslexplorer.input.MultiSelectDataSource;
33 import com.sslexplorer.input.MultiSelectSelectionModel;
34 import com.sslexplorer.security.LogonControllerFactory;
35 import com.sslexplorer.security.SessionInfo;
36 import com.sslexplorer.wizard.AbstractWizardSequence;
37 import com.sslexplorer.wizard.forms.DefaultWizardForm;
38
39 public abstract class AbstractWizardPolicySelectionForm extends DefaultWizardForm {
40     
41
42     private MultiSelectSelectionModel policyModel;
43     private PropertyList selectedPolicies;
44     
45     // Statics for sequence attributes
46
public final static String JavaDoc ATTR_SELECTED_POLICIES = "selectedPolicies";
47
48     public AbstractWizardPolicySelectionForm(boolean nextAvailable, boolean previousAvailable, String JavaDoc page, String JavaDoc focussedField, boolean autoComplete, boolean finishAvailable, String JavaDoc pageName, String JavaDoc resourceBundle, String JavaDoc resourcePrefix, int stepIndex) {
49         super(nextAvailable, previousAvailable, page, focussedField, autoComplete, finishAvailable, pageName, resourceBundle,
50             resourcePrefix, stepIndex);
51     }
52
53     /* (non-Javadoc)
54      * @see com.sslexplorer.wizard.forms.DefaultWizardForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
55      */

56     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
57         if(isCommiting()) {
58             if(selectedPolicies.size() == 0) {
59                 ActionErrors errs = new ActionErrors();
60                 errs.add(Globals.ERROR_KEY, new BundleActionMessage(getResourceBundle(), getResourcePrefix() + ".error.noPoliciesSelected"));
61                 return errs;
62             }
63             else {
64                 /* Make sure the selected policies are all currently available, this prevents
65                  * anyone fiddling the polices they are allowed to configure
66                  */

67                 for(Iterator JavaDoc i = selectedPolicies.iterator(); i.hasNext(); ) {
68                     String JavaDoc pol = (String JavaDoc)i.next();
69                     if(!policyModel.contains(pol)) {
70                         throw new Error JavaDoc("User doesn't have permission to select the policy '" + pol + "', this shouldn't happen.");
71                     }
72                 }
73             }
74         }
75         return super.validate(mapping, request);
76     }
77
78
79     /**
80      * @return Returns the selectedPolicies.
81      */

82     public String JavaDoc getSelectedPolicies() {
83         return selectedPolicies.getAsTextFieldText();
84     }
85
86     /**
87      * @param selectedPolicies The selectedPolicies to set.
88      */

89     public void setSelectedPolicies(String JavaDoc selectedPolicies) {
90         this.selectedPolicies.setAsTextFieldText(selectedPolicies);
91     }
92
93     /**
94      * @return Returns the policyModel.
95      */

96     public MultiSelectSelectionModel getPolicyModel() {
97         return policyModel;
98     }
99
100     /* (non-Javadoc)
101      * @see com.sslexplorer.wizard.forms.DefaultWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
102      */

103     public void apply(AbstractWizardSequence sequence) throws Exception JavaDoc {
104         super.apply(sequence);
105         sequence.putAttribute(getAttributeKey(), selectedPolicies);
106     }
107
108     /**
109      * @param policyModel The policyModel to set.
110      */

111     public void setPolicyModel(MultiSelectSelectionModel policyModel) {
112         this.policyModel = policyModel;
113     }
114
115     /* (non-Javadoc)
116      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
117      */

118     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
119         super.reset(mapping, request);
120         AbstractWizardSequence seq = getWizardSequence(request);
121         selectedPolicies = (PropertyList)seq.getAttribute(getAttributeKey(), new PropertyList());
122         MultiSelectDataSource policies = createDatasource(mapping, request);
123         SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
124         policyModel = new MultiSelectSelectionModel(session, policies, selectedPolicies);
125     }
126
127     public abstract MultiSelectDataSource createDatasource(ActionMapping mapping, HttpServletRequest JavaDoc request);
128     
129     protected String JavaDoc getAttributeKey() {
130         return ATTR_SELECTED_POLICIES;
131     }
132 }
133
Popular Tags