KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > actions > ResourceInformationAction


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

47 public class ResourceInformationAction extends AuthenticatedDispatchAction {
48
49     final static Log log = LogFactory.getLog(ResourceInformationAction.class);
50
51     /**
52      * Constructor
53      */

54     public ResourceInformationAction() {
55         super();
56     }
57
58     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
59                     throws Exception JavaDoc {
60         int resourceId = Integer.parseInt(request.getParameter("resourceId"));
61         int resourceTypeId = Integer.parseInt(request.getParameter("resourceType"));
62         ResourceType resourceType = PolicyDatabaseFactory.getInstance().getResourceType(resourceTypeId);
63         request.setAttribute(Constants.REQ_ATTR_INFO_RESOURCE, resourceType.getResourceById(resourceId));
64         return information(mapping, form, request, response);
65     }
66
67     public ActionForward information(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
68                     throws Exception JavaDoc {
69         Resource r = (Resource)request.getAttribute(Constants.REQ_ATTR_INFO_RESOURCE);
70         Collection JavaDoc<Policy> policies = null;
71         if(r.getResourceType().isPolicyRequired()) {
72             policies = PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(r, getSessionInfo(request).getRealm());
73         }
74         ((ResourceInformationForm)form).initialise(r, policies);
75         return mapping.findForward("display");
76     }
77
78     public ActionForward close(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
79                     throws Exception JavaDoc {
80         return new ActionForward(((ResourceInformationForm)form).getReferer(), true);
81     }
82
83     /*
84      * (non-Javadoc)
85      *
86      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
87      * org.apache.struts.action.ActionForm,
88      * javax.servlet.http.HttpServletRequest,
89      * javax.servlet.http.HttpServletResponse)
90      */

91     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
92         return SessionInfo.ALL_CONTEXTS;
93     }
94 }
Popular Tags