KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > attributes > actions > AttributeDefinitionInformationAction


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.properties.attributes.actions;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30 import org.apache.struts.util.MessageResources;
31
32 import com.sslexplorer.boot.PropertyClassManager;
33 import com.sslexplorer.core.CoreUtil;
34 import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
35 import com.sslexplorer.properties.attributes.AttributeDefinition;
36 import com.sslexplorer.properties.attributes.forms.AttributeDefinitionInformationForm;
37 import com.sslexplorer.security.Constants;
38 import com.sslexplorer.security.SessionInfo;
39
40 /**
41  * Action that display details about an {@link AttributeDefinition}.
42  *
43  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
44  */

45 public class AttributeDefinitionInformationAction extends AuthenticatedDispatchAction {
46
47     final static Log log = LogFactory.getLog(AttributeDefinitionInformationAction.class);
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping,
53      * org.apache.struts.action.ActionForm,
54      * javax.servlet.http.HttpServletRequest,
55      * javax.servlet.http.HttpServletResponse)
56      */

57     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
58                                      HttpServletResponse JavaDoc response) throws Exception JavaDoc {
59         try {
60             String JavaDoc name = request.getParameter("name");
61             String JavaDoc propertyClass = request.getParameter("propertyClass");
62             AttributeDefinition def = (AttributeDefinition)PropertyClassManager.getInstance().getPropertyClass(propertyClass).getDefinition(name);
63             request.setAttribute(Constants.REQ_ATTR_INFO_RESOURCE, def);
64             return attributeInformation(mapping, form, request, response);
65         } catch (Exception JavaDoc e) {
66             log.error("Failed to get attribute information. ", e);
67             response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
68             return null;
69         }
70     }
71
72     /**
73      * Display information about an attribute definition
74      *
75      * @param mapping mapping
76      * @param form form
77      * @param request request
78      * @param response response
79      * @return forward
80      * @throws Exception on any error
81      */

82     public ActionForward attributeInformation(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
83                                                     HttpServletResponse JavaDoc response) throws Exception JavaDoc {
84         AttributeDefinition def = (AttributeDefinition) request.getAttribute(Constants.REQ_ATTR_INFO_RESOURCE);
85         MessageResources mr = null;
86         if(def.getMessageResourcesKey() != null) {
87             mr = CoreUtil.getMessageResources(request.getSession(), def.getMessageResourcesKey());
88         }
89         ((AttributeDefinitionInformationForm) form).initialise(mr, def);
90         return mapping.findForward("display");
91     }
92
93     /*
94      * (non-Javadoc)
95      *
96      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
97      * org.apache.struts.action.ActionForm,
98      * javax.servlet.http.HttpServletRequest,
99      * javax.servlet.http.HttpServletResponse)
100      */

101     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
102         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
103     }
104 }
Popular Tags