KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Constructor JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28 import javax.servlet.http.HttpSession JavaDoc;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 import com.sslexplorer.core.CoreUtil;
34 import com.sslexplorer.policyframework.PolicyDatabaseFactory;
35 import com.sslexplorer.policyframework.Resource;
36 import com.sslexplorer.policyframework.ResourceItem;
37 import com.sslexplorer.policyframework.ResourceItemModel;
38 import com.sslexplorer.properties.Property;
39 import com.sslexplorer.properties.impl.profile.ProfilePropertyKey;
40 import com.sslexplorer.properties.impl.systemconfig.SystemConfigKey;
41 import com.sslexplorer.security.Constants;
42 import com.sslexplorer.security.LogonControllerFactory;
43 import com.sslexplorer.security.SessionInfo;
44 import com.sslexplorer.table.TableItemModel;
45 import com.sslexplorer.table.forms.AbstractPagerForm;
46
47 /**
48  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
49  *
50  */

51 public class AbstractResourcesForm extends AbstractPagerForm {
52
53     /**
54      * Constant used for the <i>Icons</i> view of resources
55      */

56     public final static String JavaDoc ICONS_VIEW = "icons";
57
58     /**
59      * Constant used for the <i>List</i> view of resources
60      */

61     public final static String JavaDoc LIST_VIEW = "list";
62
63     protected int selectedResource;
64     protected int launchedPolicy;
65     protected String JavaDoc selectedView;
66
67     static Log log = LogFactory.getLog(AbstractResourcesForm.class);
68
69     public AbstractResourcesForm(String JavaDoc id) {
70         super(new ResourceItemModel(id));
71     }
72
73     public AbstractResourcesForm(TableItemModel model) {
74         super(model);
75     }
76
77     public void setSelectedResource(int selectedResource) {
78         this.selectedResource = selectedResource;
79     }
80
81     public int getSelectedResource() {
82         return selectedResource;
83     }
84
85     public void setLaunchedPolicy(int launchedPolicy) {
86         this.launchedPolicy = launchedPolicy;
87     }
88
89     public int getLaunchedPolicy() {
90         return launchedPolicy;
91     }
92
93     public void initialize(List JavaDoc resources, Class JavaDoc resourceItemClass, HttpSession JavaDoc session, String JavaDoc defaultSortColumnId) {
94         super.initialize(session, defaultSortColumnId);
95         launchedPolicy = -1;
96         try {
97             for (Iterator JavaDoc i = resources.iterator(); i.hasNext();) {
98                 Resource dr = (Resource) i.next();
99                 Constructor JavaDoc c = resourceItemClass.getConstructor(new Class JavaDoc[] { Resource.class, List JavaDoc.class });
100                 List JavaDoc policies = PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(dr,
101                                 LogonControllerFactory.getInstance().getSessionInfo(session).getUser().getRealm());
102                 ResourceItem item = (ResourceItem) c.newInstance(new Object JavaDoc[] { dr, policies });
103                 getModel().addItem(item);
104             }
105             getPager().rebuild(getFilterText());
106         } catch (Throwable JavaDoc t) {
107             log.error("Failed to initialise resources form.", t);
108         }
109     }
110     
111     public void checkSelectedView(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
112         SessionInfo sessionInfo = (SessionInfo)request.getSession().getAttribute(Constants.SESSION_INFO);
113         int realmID = sessionInfo.getRealm().getRealmID();
114         int navigationContext = sessionInfo.getNavigationContext();
115         String JavaDoc defaultView = navigationContext ==
116             SessionInfo.MANAGEMENT_CONSOLE_CONTEXT
117                     ? Property.getProperty(new SystemConfigKey("ui.defaultManagementConsoleViewType"))
118                     : Property.getProperty(new ProfilePropertyKey("ui.defaultUserConsoleViewType", sessionInfo));
119         if(navigationContext == SessionInfo.USER_CONSOLE_CONTEXT) {
120             selectedView = CoreUtil.getCookieValue("ui_view_" + getModel().getId() + "_" + navigationContext, request, defaultView);
121             
122             if (selectedView == null){
123                 selectedView = Property.getProperty(new ProfilePropertyKey(CoreUtil.getCurrentPropertyProfileId(request.getSession()),
124                                 sessionInfo.getUser().getPrincipalName(),
125                                 "ui.defaultUserConsoleViewType", realmID));
126                 
127                 CoreUtil.storeUIState("ui_view_" + getModel().getId() + "_" + navigationContext, defaultView, request, response);
128             }
129
130         }
131         else{
132             selectedView = defaultView;
133         }
134     }
135
136     /**
137      * Get the selected view. This will be one of {@link #ICONS_VIEW} or
138      * {@link #LIST_VIEW}.
139      *
140      * @return selected view
141      */

142     public String JavaDoc getSelectedView() {
143         return selectedView;
144     }
145
146     /**
147      * Set the selected view. This will be one of {@link #ICONS_VIEW} or
148      * {@link #LIST_VIEW}.
149      *
150      * @param selectedView selected view
151      */

152     public void setSelectedView(String JavaDoc selectedView) {
153         this.selectedView = selectedView;
154     }
155
156 }
Popular Tags