1 19 20 package com.sslexplorer.policyframework.forms; 21 22 import java.lang.reflect.Constructor ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 import javax.servlet.http.HttpSession ; 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 51 public class AbstractResourcesForm extends AbstractPagerForm { 52 53 56 public final static String ICONS_VIEW = "icons"; 57 58 61 public final static String LIST_VIEW = "list"; 62 63 protected int selectedResource; 64 protected int launchedPolicy; 65 protected String selectedView; 66 67 static Log log = LogFactory.getLog(AbstractResourcesForm.class); 68 69 public AbstractResourcesForm(String 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 resources, Class resourceItemClass, HttpSession session, String defaultSortColumnId) { 94 super.initialize(session, defaultSortColumnId); 95 launchedPolicy = -1; 96 try { 97 for (Iterator i = resources.iterator(); i.hasNext();) { 98 Resource dr = (Resource) i.next(); 99 Constructor c = resourceItemClass.getConstructor(new Class [] { Resource.class, List .class }); 100 List policies = PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(dr, 101 LogonControllerFactory.getInstance().getSessionInfo(session).getUser().getRealm()); 102 ResourceItem item = (ResourceItem) c.newInstance(new Object [] { dr, policies }); 103 getModel().addItem(item); 104 } 105 getPager().rebuild(getFilterText()); 106 } catch (Throwable t) { 107 log.error("Failed to initialise resources form.", t); 108 } 109 } 110 111 public void checkSelectedView(HttpServletRequest request, HttpServletResponse response) { 112 SessionInfo sessionInfo = (SessionInfo)request.getSession().getAttribute(Constants.SESSION_INFO); 113 int realmID = sessionInfo.getRealm().getRealmID(); 114 int navigationContext = sessionInfo.getNavigationContext(); 115 String 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 142 public String getSelectedView() { 143 return selectedView; 144 } 145 146 152 public void setSelectedView(String selectedView) { 153 this.selectedView = selectedView; 154 } 155 156 } | Popular Tags |