KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > navigation > actions > HelpAction


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.navigation.actions;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28
29 import com.sslexplorer.boot.PropertyClass;
30 import com.sslexplorer.boot.PropertyClassManager;
31 import com.sslexplorer.boot.PropertyDefinition;
32 import com.sslexplorer.boot.Util;
33 import com.sslexplorer.core.CoreMenuTree;
34 import com.sslexplorer.core.actions.DefaultAction;
35 import com.sslexplorer.navigation.NavigationManager;
36 import com.sslexplorer.navigation.forms.HelpForm;
37 import com.sslexplorer.security.Constants;
38 import com.sslexplorer.security.LogonControllerFactory;
39 import com.sslexplorer.security.SessionInfo;
40
41 /**
42  * Action to switch to the user console. All users are allowed to do this.
43  *
44  * @author Brett Smith <brett@3sp.com>
45  */

46
47 public class HelpAction extends DefaultAction {
48     
49     /**
50      * Constructor
51      */

52     public HelpAction() {
53         super();
54     }
55
56     /*
57      * (non-Javadoc)
58      *
59      * @see com.sslexplorer.security.actions.AuthenticatedAction#onExecute(org.apache.struts.action.ActionMapping,
60      * org.apache.struts.action.ActionForm,
61      * javax.servlet.http.HttpServletRequest,
62      * javax.servlet.http.HttpServletResponse)
63      */

64     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
65                     HttpServletResponse JavaDoc response) throws Exception JavaDoc {
66         String JavaDoc source = request.getParameter("source");
67         HelpForm helpForm = (HelpForm)form;
68         if(source == null) {
69             throw new Exception JavaDoc("Help action requires a source parameter.");
70         }
71         if(source.equalsIgnoreCase("property")) {
72             String JavaDoc name = request.getParameter("name");
73             if(name == null) {
74                 throw new Exception JavaDoc("Help for property source requires a name parameter.");
75             }
76             String JavaDoc propertyClassName = request.getParameter("propertyClass");
77             if(propertyClassName == null) {
78                 throw new Exception JavaDoc("Help for property source requires a propertyClass parameter.");
79             }
80             PropertyClass propertyClass = PropertyClassManager.getInstance().getPropertyClass(propertyClassName);
81             if(propertyClass == null) {
82                 throw new Exception JavaDoc("Invalid property class.");
83             }
84             PropertyDefinition def = propertyClass.getDefinition(name);
85             if(def == null) {
86                 throw new Exception JavaDoc("No property definition with name of " + name);
87             }
88             request.setAttribute(Constants.REQ_ATTR_PROPERTY_DEFINITION, def);
89             return mapping.findForward("property");
90         }
91         else if(source.equalsIgnoreCase("help")) {
92             // load the documentation context menu
93
SessionInfo info = LogonControllerFactory.getInstance().getSessionInfo(request);
94             helpForm.setMenu(NavigationManager.getMenuTree(CoreMenuTree.MENU_ITEM_MENU_TREE).rebuildMenus(SessionInfo.HELP_CONTEXT,
95                 info,
96                 request,
97                 Util.getOriginalRequest(request)));
98             return mapping.findForward("help");
99         }
100         throw new Exception JavaDoc("No source of type " + source);
101
102     }
103
104     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
105         return SessionInfo.HELP_CONTEXT;
106     }
107
108 }
Popular Tags