KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > admin > SendAdminMailAction


1 /*
2  * $Id: SendAdminMailAction.java,v 1.3 2005/06/07 12:32:27 bel70 Exp $
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the
6  * Mozilla Public License Version 1.1 (the "License"); you may not use this file
7  * except in compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
12  * the specific language governing rights and limitations under the License.
13  *
14  * The Original Code is JGossip forum code.
15  *
16  * The Initial Developer of the Original Code is the JResearch, Org. Portions
17  * created by the Initial Developer are Copyright (C) 2004 the Initial
18  * Developer. All Rights Reserved.
19  *
20  * Contributor(s): Dmitriy Belov <bel@jresearch.org> . *
21  * ***** END LICENSE BLOCK*****
22  *
23  */

24 /*
25  * Created on 29.04.2004
26  *
27  */

28 package org.jresearch.gossip.actions.admin;
29
30 import java.sql.SQLException JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36 import javax.servlet.http.HttpSession JavaDoc;
37
38 import org.apache.struts.action.ActionForm;
39 import org.apache.struts.action.ActionForward;
40 import org.apache.struts.action.ActionMapping;
41 import org.apache.struts.util.MessageResources;
42 import org.jresearch.gossip.IConst;
43 import org.jresearch.gossip.actions.BaseAction;
44 import org.jresearch.gossip.am.ban.BanGuard;
45 import org.jresearch.gossip.beans.NamedValue;
46 import org.jresearch.gossip.beans.user.User;
47 import org.jresearch.gossip.configuration.Configurator;
48 import org.jresearch.gossip.constants.BanType;
49 import org.jresearch.gossip.dao.UserDAO;
50 import org.jresearch.gossip.exception.SystemException;
51 import org.jresearch.gossip.forms.SendAdminMailForm;
52 import org.jresearch.gossip.mail.MailMessage;
53 import org.jresearch.gossip.mail.MailQueue;
54 import org.jresearch.gossip.util.HtmlCodec;
55 import org.jresearch.gossip.util.MessageProcessor;
56
57 /**
58  * DOCUMENT ME!
59  *
60  * @author Dmitry Belov
61  */

62 public class SendAdminMailAction extends BaseAction {
63
64     /*
65      * (non-Javadoc)
66      *
67      * @see org.jresearch.gossip.actions.BaseAction#process(org.apache.struts.action.ActionMapping,
68      * org.apache.struts.action.ActionForm,
69      * javax.servlet.http.HttpServletRequest,
70      * javax.servlet.http.HttpServletResponse)
71      */

72     public ActionForward process(ActionMapping mapping, ActionForm form,
73             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
74             throws SystemException {
75         MessageResources messages = getResources(request);
76         HttpSession JavaDoc session = request.getSession();
77         SendAdminMailForm samForm = (SendAdminMailForm) form;
78         User user = (User) session.getAttribute(IConst.SESSION.USER_KEY);
79         UserDAO dao = UserDAO.getInstance();
80         MessageProcessor mp = MessageProcessor.getInstance();
81         String JavaDoc mess = mp.prepareMessage(HtmlCodec.encode(samForm.getText()), 0,
82                 messages);
83         StringBuffer JavaDoc siteUrl = new StringBuffer JavaDoc();
84         siteUrl.append(request.getServerName());
85         siteUrl.append(":");
86         siteUrl.append(request.getServerPort());
87         siteUrl.append(request.getContextPath());
88         siteUrl.append(Configurator.getInstance().get(
89                 IConst.CONFIG.MODULE_PREFIX));
90         siteUrl.append("/");
91         /*
92          * {0} - login {1} - message text {2} - site url {3} - site name
93          */

94         Object JavaDoc[] messArgs = new Object JavaDoc[] { "", mp.nl2br(mess),
95                 siteUrl.toString(),
96                 Configurator.getInstance().get(IConst.CONFIG.SITE_NAME) };
97         MailQueue queue = (MailQueue) session.getServletContext().getAttribute(
98                 IConst.CONTEXT.MAIL_QUEUE);
99         try {
100
101             ArrayList JavaDoc userMails = dao.getUserEmails();
102             Iterator JavaDoc it = userMails.iterator();
103             BanGuard guard = BanGuard.getInstance();
104             while (it.hasNext()) {
105                 NamedValue nv = (NamedValue) it.next();
106
107                 if (!guard.checkBan(nv.getValue(), BanType.EMAIL)
108                         && !user.getName().equals(nv.getName())) {
109                     messArgs[0] = nv.getName();
110                     queue.push(new MailMessage(messages.getMessage(
111                             "mails.ADMIN_MAIL", messArgs),
112                             samForm.getSubject(), Configurator.getInstance()
113                                     .get(IConst.CONFIG.ADMINMAIL), user
114                                     .getName(), nv.getValue(), nv.getName()));
115                 }
116             }
117             request.removeAttribute("sendAdminMailForm");
118             log(request, "status.ADMIN_MAIL_SENT");
119             setStatusMessage(request, "status.ADMIN_MAIL_SENT");
120         } catch (SQLException JavaDoc sqle) {
121             getServlet().log("Connection.process", sqle);
122         }
123         return (mapping.getInputForward());
124     }
125 }
Popular Tags