KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > forms > PropertyProfileForm


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.properties.forms;
21
22 import java.util.List JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.struts.Globals;
29 import org.apache.struts.action.ActionErrors;
30 import org.apache.struts.action.ActionMapping;
31 import org.apache.struts.action.ActionMessage;
32
33 import com.sslexplorer.boot.PropertyList;
34 import com.sslexplorer.input.MultiSelectSelectionModel;
35 import com.sslexplorer.policyframework.Resource;
36 import com.sslexplorer.policyframework.ResourceUtil;
37 import com.sslexplorer.policyframework.forms.AbstractResourceForm;
38 import com.sslexplorer.properties.ProfilesFactory;
39 import com.sslexplorer.properties.PropertyProfile;
40 import com.sslexplorer.security.Constants;
41 import com.sslexplorer.security.SessionInfo;
42 import com.sslexplorer.security.User;
43
44 /**
45  * Form for editing property profiles.
46  *
47  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
48  *
49  */

50 public class PropertyProfileForm extends AbstractResourceForm {
51     static Log log = LogFactory.getLog(PropertyProfileForm.class);
52     private List JavaDoc propertyProfiles;
53     private int selectedPropertyProfile;
54     private String JavaDoc scope;
55     private String JavaDoc selectedTab = "details";
56
57     /**
58      * Get the action needed to perform the update.
59      *
60      * @return String
61      */

62     public String JavaDoc getUpdateAction() {
63         return getEditing() ? (Constants.SCOPE_GLOBAL.equals(getPropertyScope()) ? "/editGlobalPropertyProfile.do"
64                         : "/editPropertyProfile.do")
65                         : (Constants.SCOPE_GLOBAL.equals(getPropertyScope()) ? "/createGlobalPropertyProfile.do"
66                                         : "/createPropertyProfile.do");
67     }
68
69     /*
70      * (non-Javadoc)
71      *
72      * @see com.sslexplorer.policyframework.forms.AbstractResourceForm#validate(org.apache.struts.action.ActionMapping,
73      * javax.servlet.http.HttpServletRequest)
74      */

75     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
76         ActionErrors errs = super.validate(mapping, request);
77         if (isCommiting()) {
78             if (getResourceName().equalsIgnoreCase("default")
79                             && (!getEditing() || (getEditing() && !getResource().getResourceName().equalsIgnoreCase("default")))) {
80                 errs.add(Globals.ERROR_KEY, new ActionMessage("error.createProfile.cantUseNameDefault"));
81                 setResourceName("");
82             }
83         }
84         return errs;
85     }
86
87     /**
88      * @return List of property profiles
89      */

90     public List JavaDoc getPropertyProfiles() {
91         return propertyProfiles;
92     }
93
94     /**
95      * @param selectedPropertyProfile
96      */

97     public void setSelectedPropertyProfile(int selectedPropertyProfile) {
98         this.selectedPropertyProfile = selectedPropertyProfile;
99     }
100
101     /**
102      * @return int property profile id
103      */

104     public int getSelectedPropertyProfile() {
105         return selectedPropertyProfile;
106     }
107
108     /**
109      * @return the property scope
110      */

111     public String JavaDoc getPropertyScope() {
112         return scope;
113     }
114
115     /**
116      * @param scope
117      */

118     public void setPropertyScope(String JavaDoc scope) {
119         this.scope = scope;
120     }
121
122     /**
123      * @param propertyProfiles
124      */

125     public void setPropertyProfiles(List JavaDoc propertyProfiles) {
126         this.propertyProfiles = propertyProfiles;
127     }
128
129     /*
130      * (non-Javadoc)
131      *
132      * @see com.sslexplorer.policyframework.forms.AbstractResourceForm#getResourceByName(java.lang.String,
133      * com.sslexplorer.security.SessionInfo)
134      */

135     public Resource getResourceByName(String JavaDoc name, SessionInfo session) throws Exception JavaDoc {
136         String JavaDoc username = Constants.SCOPE_GLOBAL.equals(getPropertyScope()) ? null : getUser().getPrincipalName();
137         return ProfilesFactory.getInstance().getPropertyProfile(username, name, getUser().getRealm().getResourceId());
138     }
139
140     /*
141      * (non-Javadoc)
142      *
143      * @see com.sslexplorer.tabs.TabModel#getTabCount()
144      */

145     public int getTabCount() {
146         return getPropertyScope().equals(Constants.SCOPE_PERSONAL) ? 1 : 2;
147     }
148
149     /*
150      * (non-Javadoc)
151      *
152      * @see com.sslexplorer.tabs.TabModel#getTabName(int)
153      */

154     public String JavaDoc getTabName(int idx) {
155         switch (idx) {
156             case 0:
157                 return "details";
158             default:
159                 return "policies";
160         }
161     }
162
163     /*
164      * (non-Javadoc)
165      *
166      * @see com.sslexplorer.tabs.TabModel#getTabTitle(int)
167      */

168     public String JavaDoc getTabTitle(int idx) {
169         // Get from resources
170
return null;
171     }
172
173     /**
174      * @param user
175      * @param resource
176      * @param editing
177      * @param policyModel
178      * @param selectedPolicies
179      * @param owner
180      * @param assignOnly
181      * @throws Exception
182      */

183     public void initialise(User user, Resource resource, boolean editing, MultiSelectSelectionModel policyModel,
184                            PropertyList selectedPolicies, User owner, boolean assignOnly) throws Exception JavaDoc {
185         super.initialise(user, resource, editing, policyModel, selectedPolicies, owner, assignOnly);
186         propertyProfiles = ProfilesFactory.getInstance().getPropertyProfiles(owner == null ? null : owner.getPrincipalName(), true,
187                         ((PropertyProfile)resource).getRealmID());
188         if (owner != null) {
189             propertyProfiles = ResourceUtil.filterResources(owner, propertyProfiles, owner == null ? true : false);
190         }
191         if (resource != null) {
192             selectedPropertyProfile = ((PropertyProfile) resource).getResourceId();
193         } else {
194             selectedPropertyProfile = 0;
195         }
196     }
197
198     /*
199      * (non-Javadoc)
200      *
201      * @see com.sslexplorer.tabs.TabModel#getSelectedTab()
202      */

203     public String JavaDoc getSelectedTab() {
204         return selectedTab;
205     }
206
207     /*
208      * (non-Javadoc)
209      *
210      * @see com.sslexplorer.tabs.TabModel#setSelectedTab(java.lang.String)
211      */

212     public void setSelectedTab(String JavaDoc selectedTab) {
213         this.selectedTab = selectedTab;
214     }
215
216     /*
217      * (non-Javadoc)
218      *
219      * @see com.sslexplorer.policyframework.forms.AbstractResourceForm#applyToResource()
220      */

221     public void applyToResource() throws Exception JavaDoc {
222     }
223
224     /*
225      * (non-Javadoc)
226      *
227      * @see com.sslexplorer.tabs.TabModel#getTabBundle(int)
228      */

229     public String JavaDoc getTabBundle(int idx) {
230         return null;
231     }
232 }
Popular Tags