KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > applications > actions > EditApplicationShortcutDispatchAction


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.actions;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Locale JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.struts.Globals;
33 import org.apache.struts.action.ActionForm;
34 import org.apache.struts.action.ActionForward;
35 import org.apache.struts.action.ActionMapping;
36 import org.apache.struts.action.ActionMessage;
37 import org.apache.struts.action.ActionMessages;
38
39 import com.sslexplorer.applications.ApplicationShortcut;
40 import com.sslexplorer.applications.ApplicationShortcutDatabaseFactory;
41 import com.sslexplorer.applications.ApplicationsPlugin;
42 import com.sslexplorer.applications.forms.ApplicationShortcutForm;
43 import com.sslexplorer.extensions.ShortcutParameterItem;
44 import com.sslexplorer.policyframework.Resource;
45 import com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction;
46 import com.sslexplorer.policyframework.forms.AbstractResourceForm;
47 import com.sslexplorer.security.SessionInfo;
48
49 /**
50  * Extension of
51  * {@link com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction}
52  * that allows an administrator to edit the details of an application shortcut.
53  * <p>
54  * The type of application cannot be changed, only the usual resources details
55  * and the short specific values of the application extensions parameters.
56  *
57  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
58  */

59 public class EditApplicationShortcutDispatchAction extends AbstractResourceDispatchAction {
60
61     static Log log = LogFactory.getLog(EditApplicationShortcutDispatchAction.class);
62
63     /**
64      * Constructor.
65      */

66     public EditApplicationShortcutDispatchAction() {
67         super(ApplicationsPlugin.APPLICATION_SHORTCUT_RESOURCE_TYPE);
68     }
69
70
71     /*
72      * (non-Javadoc)
73      *
74      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
75      * org.apache.struts.action.ActionForm,
76      * javax.servlet.http.HttpServletRequest,
77      * javax.servlet.http.HttpServletResponse)
78      */

79     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
80         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
81     }
82
83
84     /* (non-Javadoc)
85      * @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#edit(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
86      */

87     public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
88         ((ApplicationShortcutForm) form).setLocale((Locale JavaDoc)request.getSession().getAttribute(Globals.LOCALE_KEY));
89         return super.edit(mapping, form, request, response);
90     }
91
92
93     /*
94      * (non-Javadoc)
95      *
96      * @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#createResource(org.apache.struts.action.ActionMapping,
97      * org.apache.struts.action.ActionForm,
98      * javax.servlet.http.HttpServletRequest,
99      * javax.servlet.http.HttpServletResponse)
100      */

101     public Resource createResource(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
102                     throws Exception JavaDoc {
103         // TODO only needed if your wanting to create the resouce without the
104
// wizard.
105
return null;
106     }
107
108     /* (non-Javadoc)
109      * @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#commit(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
110      */

111     public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
112                     throws Exception JavaDoc {
113         ActionMessages msgs = new ActionMessages();
114         msgs.add(Globals.MESSAGE_KEY, new ActionMessage("editTunnel.message.saved"));
115         this.addMessages(request, msgs);
116         return super.commit(mapping, form, request, response);
117     }
118
119     /* (non-Javadoc)
120      * @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#commitCreatedResource(org.apache.struts.action.ActionMapping, com.sslexplorer.policyframework.forms.AbstractResourceForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
121      */

122     protected Resource commitCreatedResource(ActionMapping mapping, AbstractResourceForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
123         ApplicationShortcutForm asf = (ApplicationShortcutForm)form;
124         ApplicationShortcut as = (ApplicationShortcut)asf.getResource();
125         Map JavaDoc<String JavaDoc, String JavaDoc> parameterMap = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
126         for (Iterator JavaDoc i = asf.getParameterItems().iterator(); i.hasNext();) {
127             ShortcutParameterItem pi = (ShortcutParameterItem) i.next();
128             parameterMap.put(pi.getName(), pi.getPropertyValue().toString());
129         }
130         int resourceId = ApplicationShortcutDatabaseFactory.getInstance().createApplicationShortcut(
131             as.getApplication(), asf.getResourceName(), asf.getResourceDescription(),
132             parameterMap, getSessionInfo(request).getRealmId());
133         return as.getResourceType().getResourceById(resourceId);
134         
135     }
136
137 }
Popular Tags