KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > applications > forms > ApplicationShortcutsForm


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.applications.forms;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 import com.sslexplorer.applications.ApplicationShortcut;
31 import com.sslexplorer.applications.ApplicationShortcutItem;
32 import com.sslexplorer.extensions.ExtensionDescriptor;
33 import com.sslexplorer.extensions.ExtensionBundle.ExtensionBundleStatus;
34 import com.sslexplorer.extensions.store.ExtensionStore;
35 import com.sslexplorer.policyframework.PolicyDatabaseFactory;
36 import com.sslexplorer.policyframework.ResourceItemModel;
37 import com.sslexplorer.policyframework.forms.AbstractResourcesForm;
38 import com.sslexplorer.security.SessionInfo;
39
40 /**
41  * Extension of
42  * {@link com.sslexplorer.policyframework.forms.AbstractResourcesForm} that
43  * provides the model for lists of <i>Application Shortcuts</i>.
44  *
45  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
46  */

47 public class ApplicationShortcutsForm extends AbstractResourcesForm {
48
49     static Log log = LogFactory.getLog(ApplicationShortcutsForm.class);
50
51     // Private instance variables
52

53     /**
54      * Constructor
55      */

56     public ApplicationShortcutsForm() {
57         super(new ResourceItemModel("applicationShortcuts"));
58     }
59
60     /**
61      * Initialise the pager and the items and the ability to sort.
62      *
63      * @param applicationShortcuts List of Samples to be added.
64      * @param session The session information.
65      * @param defaultSortColumnId default sort column
66      * @param request request from action that initialises this form
67      */

68     public void initialise(List JavaDoc applicationShortcuts, SessionInfo session, String JavaDoc defaultSortColumnId, HttpServletRequest JavaDoc request) {
69         super.initialize(session.getHttpSession(), defaultSortColumnId);
70         if (selectedView == null) {
71             selectedView = session.getNavigationContext() == SessionInfo.USER_CONSOLE_CONTEXT ? ICONS_VIEW : LIST_VIEW;
72         } else if (session.getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
73             selectedView = LIST_VIEW;
74         }
75         try {
76             for (Iterator JavaDoc i = applicationShortcuts.iterator(); i.hasNext();) {
77                 ApplicationShortcut applicationShortcut = (ApplicationShortcut) i.next();
78                 List JavaDoc policies = PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(applicationShortcut,
79                                 session.getUser().getRealm());
80                 ExtensionDescriptor ed = ExtensionStore.getInstance().getExtensionDescriptor(applicationShortcut.getApplication());
81                 if (ed == null) {
82                     log.warn("Found shortcut with an application ID '" + applicationShortcut.getApplication()
83                                     + "' that does not exist. An extension may have been removed.");
84                 } else {
85                     if(ed.getApplicationBundle().getStatus() != ExtensionBundleStatus.ACTIVATED) {
86                         log.warn("Found shortcut with an application ID '" + applicationShortcut.getApplication()
87                             + "' that uses an application contained in an extension bundle that is not activated (its status is '" + ed.getApplicationBundle().getStatus().getName() + "'). Ignoring.");
88                     }
89                     else {
90                         ApplicationShortcutItem item = new ApplicationShortcutItem(ed, applicationShortcut, policies, session
91                                         .getNavigationContext(), applicationShortcut.sessionPasswordRequired(session));
92                         item.setFavoriteType(getFavoriteType(applicationShortcut.getResourceId()));
93                         getModel().addItem(item);
94                     }
95                 }
96             }
97             checkSort();
98             getPager().rebuild(getFilterText());
99         } catch (Throwable JavaDoc t) {
100             log.error("Failed to initialise resources form.", t);
101         }
102     }
103 }
104
Popular Tags