KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator 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.boot.PropertyList;
34 import com.sslexplorer.core.CoreServlet;
35 import com.sslexplorer.core.CoreUtil;
36 import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
37 import com.sslexplorer.input.MultiSelectDataSource;
38 import com.sslexplorer.input.MultiSelectSelectionModel;
39 import com.sslexplorer.notification.Message;
40 import com.sslexplorer.notification.Recipient;
41 import com.sslexplorer.policyframework.Permission;
42 import com.sslexplorer.policyframework.PolicyConstants;
43 import com.sslexplorer.policyframework.PolicyDataSource;
44 import com.sslexplorer.policyframework.PolicyDatabaseFactory;
45 import com.sslexplorer.realms.Realm;
46 import com.sslexplorer.security.LogonControllerFactory;
47 import com.sslexplorer.security.SessionInfo;
48 import com.sslexplorer.setup.forms.MessageForm;
49
50 public class SendMessageDispatchAction extends AuthenticatedDispatchAction {
51     public SendMessageDispatchAction() {
52         super(PolicyConstants.MESSAGE_QUEUE_RESOURCE_TYPE,
53             new Permission[] { PolicyConstants.PERM_SEND });
54     }
55
56     final static Log log = LogFactory.getLog(SendMessageDispatchAction.class);
57
58     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
59                     throws Exception JavaDoc {
60         MessageForm mf = (MessageForm)form;
61         mf.setReferer(CoreUtil.getReferer(request));
62         PropertyList selectedPolicies = new PropertyList();
63         MultiSelectDataSource policies = new PolicyDataSource();
64         SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
65         MultiSelectSelectionModel policyModel = new MultiSelectSelectionModel(session, policies, selectedPolicies);
66         mf.initialise(policyModel, selectedPolicies, getSessionInfo(request));
67         String JavaDoc users = request.getParameter("users");
68         if(users != null) {
69             if(users.equals("*")) {
70                 mf.setSelectedPolicies(String.valueOf(PolicyDatabaseFactory.getInstance().getEveryonePolicyIDForRealm(
71                                 getSessionInfo(request).getUser().getRealm())));
72                 policyModel.rebuild(session);
73             }
74             else {
75                 mf.setSelectedAccounts(users);
76             }
77         }
78         return mapping.findForward("display");
79     }
80
81     public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
82                     throws Exception JavaDoc {
83         MessageForm mf = (MessageForm)form;
84         Realm realm = getSessionInfo(request).getUser().getRealm();
85         Message msg = new Message(mf.getSubject(), mf.getContent(), mf.getUrgent());
86         for(Iterator JavaDoc i = mf.getSelectedAccountsList().iterator(); i.hasNext(); ) {
87             msg.getRecipients().add(new Recipient(Recipient.USER, (String JavaDoc)i.next(), realm.getResourceName()));
88         }
89         for(Iterator JavaDoc i = mf.getSelectedRolesList().iterator(); i.hasNext(); ) {
90             msg.getRecipients().add(new Recipient(Recipient.ROLE, (String JavaDoc)i.next(), realm.getResourceName()));
91         }
92         for(Iterator JavaDoc i = mf.getSelectedPoliciesList().iterator(); i.hasNext(); ) {
93             msg.getRecipients().add(new Recipient(Recipient.POLICY, (String JavaDoc)i.next(), realm.getResourceName()));
94         }
95         if(msg.getRecipients().size() == 0) {
96             throw new Exception JavaDoc("No recipients in any of the accounts, roles or policies selected.");
97         }
98         if(mf.getSelectedSink().equals("*")) {
99             CoreServlet.getServlet().getNotifier().sendToAll(msg);
100         }
101         else if(mf.getSelectedSink().equals("^")) {
102             CoreServlet.getServlet().getNotifier().sendToFirst(msg);
103         }
104         else {
105             CoreServlet.getServlet().getNotifier().sendToSink(mf.getSelectedSink(), msg);
106         }
107         return cancel(mapping, form, request, response);
108     }
109
110     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
111         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
112     }
113 }
Popular Tags