1 /*
2 * $Id: AIMMessageBean.java,v 1.3 2003/10/02 01:25:53 smulube Exp $
3 *
4 * ***** BEGIN LICENSE BLOCK *****
5 * ===========================================================================
6 * Copyright (c) 2003 Sam Mulube
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.COPYRIGHT AND PERMISSION NOTICE
25 * ===========================================================================
26 * ***** END LICENSE BLOCK *****
27 */
28 package org.zerofun.maven.im.beans;
29
30 import org.apache.commons.lang.StringUtils;
31 import org.zerofun.maven.im.MavenIMException;
32
33 import com.levelonelabs.aim.AIMBuddy;
34 import com.levelonelabs.aim.AIMClient;
35 import com.levelonelabs.aim.AIMSender;
36
37 /***
38 * This bean provides the actual functionality for sending a message to AIM
39 * clients. It's functionality is invoked by the corresponding
40 * AIMMessageTag class.
41 *
42 * @author <a href="mailto:sam@mulube.com">Sam Mulube</a>
43 * @version $Revision: 1.3 $
44 *
45 */
46 public class AIMMessageBean {
47
48 private String from = null;
49 private String message = null;
50 private String password = null;
51 private String to = null;
52
53 /***
54 * The main method of the bean. This performs the function of creating and
55 * sending the message to all AIM recipients.
56 * @throws Exception
57 */
58 public void execute() throws Exception {
59 if (getTo() == null) {
60 throw new MavenIMException("No AIM recipients specified.");
61 }
62 String[] recipients = UtilityBean.getRecipients(getTo());
63 AIMSender sender = getSender();
64 for (int i = 0; i < recipients.length; i++) {
65 String recipient = recipients[i];
66 System.out.println("Sending message to: " + recipient);
67 AIMBuddy buddy = new AIMBuddy(recipient);
68 sender.sendMessage(buddy, getMessage());
69 Thread.sleep(1500);
70 }
71 System.out.println("Disconnecting from AIM server...");
72 sender.signOff();
73
74 }
75
76 /***
77 * Gets the username of the AIM user messages will be sent from.
78 * @return the AIM username String
79 */
80 public String getFrom() {
81 return from;
82 }
83
84 /***
85 * Gets the message which will be sent to all recipients.
86 * @return the message String
87 */
88 public String getMessage() {
89 return message;
90 }
91
92 /***
93 * Gets the password used to authenticate the specified username.
94 * @return the password String
95 */
96 public String getPassword() {
97 return password;
98 }
99
100 /***
101 * Gets an initialised AIMSender ready for use sending messages.
102 * @return the AIMSender to use.
103 * @throws InterruptedException
104 */
105 private AIMSender getSender() throws InterruptedException {
106 AIMSender sender =
107 new AIMClient(getFrom(), getPassword(), "Maven bot", true);
108 sender.signOn();
109 return sender;
110 }
111
112 /***
113 * Gets the list of recipients to which the message should be sent. This may
114 * be a single user, or a comma separated list of recipients.
115 * @return the to String
116 */
117 public String getTo() {
118 return to;
119 }
120
121 /***
122 * Sets the username from which messages will be sent.
123 * @param from the username String to set
124 */
125 public void setFrom(String from) {
126 this.from = from;
127 }
128
129 /***
130 * Sets the message which will be sent to all recipients.
131 * @param message the message string to set
132 */
133 public void setMessage(String message) {
134 this.message = message;
135 }
136
137 /***
138 * Sets the password which will authenticate the specified username to the
139 * AIM server.
140 * @param password the password String to set
141 */
142 public void setPassword(String password) {
143 this.password = password;
144 }
145
146 /***
147 * Sets the list of recipients to which will be sent messages.
148 * @param to the to String to set
149 */
150 public void setTo(String to) {
151 this.to = to;
152 }
153
154 }
155
156 /*
157 * $Log: AIMMessageBean.java,v $
158 * Revision 1.3 2003/10/02 01:25:53 smulube
159 * added better comments.
160 *
161 * Revision 1.2 2003/10/01 17:16:24 smulube
162 * beans now throw exception if no recipients specified.
163 *
164 * Revision 1.1 2003/09/26 01:18:35 smulube
165 * Using jaimbot library. Claims to send but not working as yet.
166 *
167 */
This page was automatically generated by Maven