KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > setup > actions > MessageQueueDispatchAction


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.setup.actions;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.struts.Globals;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30 import org.apache.struts.action.ActionMessages;
31
32 import com.sslexplorer.core.CoreServlet;
33 import com.sslexplorer.core.CoreUtil;
34 import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
35 import com.sslexplorer.policyframework.Permission;
36 import com.sslexplorer.policyframework.PolicyConstants;
37 import com.sslexplorer.policyframework.PolicyUtil;
38 import com.sslexplorer.security.Constants;
39 import com.sslexplorer.security.SessionInfo;
40 import com.sslexplorer.setup.forms.MessageQueueForm;
41
42 /**
43  */

44 public class MessageQueueDispatchAction extends AuthenticatedDispatchAction {
45     /**
46      */

47     public MessageQueueDispatchAction() {
48         super(PolicyConstants.MESSAGE_QUEUE_RESOURCE_TYPE,
49             new Permission[] { PolicyConstants.PERM_VIEW,
50                         PolicyConstants.PERM_SEND,
51                         PolicyConstants.PERM_CONTROL,
52                         PolicyConstants.PERM_CLEAR });
53     }
54
55     /**
56      * @param mapping
57      * @param form
58      * @param request
59      * @param response
60      * @return ActionForward
61      * @throws Exception
62      */

63     public ActionForward confirmClearQueue(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
64         PolicyUtil.checkPermission(PolicyConstants.MESSAGE_QUEUE_RESOURCE_TYPE, PolicyConstants.PERM_CLEAR, request);
65         return mapping.findForward("confirmClearQueue");
66     }
67
68     /**
69      * @param mapping
70      * @param form
71      * @param request
72      * @param response
73      * @return ActionForward
74      * @throws Exception
75      */

76     public ActionForward clearQueue(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
77         PolicyUtil.checkPermission(PolicyConstants.MESSAGE_QUEUE_RESOURCE_TYPE, PolicyConstants.PERM_CLEAR, request);
78         CoreServlet.getServlet().getNotifier().clearAllMessages();
79         return mapping.findForward("refresh");
80     }
81
82     /**
83      * @param mapping
84      * @param form
85      * @param request
86      * @param response
87      * @return ActionForward
88      * @throws Exception
89      */

90     public ActionForward sendMessage(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
91         PolicyUtil.checkPermission(PolicyConstants.MESSAGE_QUEUE_RESOURCE_TYPE, PolicyConstants.PERM_SEND, request);
92         return mapping.findForward("sendMessage");
93     }
94
95     /**
96      * @param mapping
97      * @param form
98      * @param request
99      * @param response
100      * @return ActionForward
101      * @throws Exception
102      */

103     public ActionForward enable(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
104         PolicyUtil.checkPermission(PolicyConstants.MESSAGE_QUEUE_RESOURCE_TYPE, PolicyConstants.PERM_CONTROL, request);
105         String JavaDoc sel = ((MessageQueueForm)form).getSelectedSink();
106         CoreServlet.getServlet().getNotifier().setEnabled(sel, true);
107         ActionMessages msgs = new ActionMessages();
108         msgs.add(Globals.MESSAGE_KEY, new ActionMessage("messageQueue.info.sinkEnabled", sel));
109         saveMessages(request, msgs);
110         return list(mapping, form, request, response);
111     }
112
113     /**
114      * @param mapping
115      * @param form
116      * @param request
117      * @param response
118      * @return ActionForward
119      * @throws Exception
120      */

121     public ActionForward disable(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
122         PolicyUtil.checkPermission(PolicyConstants.MESSAGE_QUEUE_RESOURCE_TYPE, PolicyConstants.PERM_CONTROL, request);
123         String JavaDoc sel = ((MessageQueueForm)form).getSelectedSink();
124         CoreServlet.getServlet().getNotifier().setEnabled(sel, false);
125         ActionMessages msgs = new ActionMessages();
126         msgs.add(Globals.MESSAGE_KEY, new ActionMessage("messageQueue.info.sinkDisabled", sel));
127         saveMessages(request, msgs);
128         return list(mapping, form, request, response);
129     }
130
131     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
132         return list(mapping, form, request, response);
133     }
134     
135     /**
136      * @param mapping
137      * @param form
138      * @param request
139      * @param response
140      * @return ActionForward
141      * @throws Exception
142      */

143     public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
144                     throws Exception JavaDoc {
145         CoreUtil.clearFlow(request);
146         
147         MessageQueueForm messageQueueForm = (MessageQueueForm) form;
148         messageQueueForm.initialize(request.getSession());
149         return mapping.findForward("display");
150     }
151
152     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
153         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
154     }
155 }
Popular Tags