View Javadoc

1   /*
2    * jcurl java curling software framework https://JCurl.mro.name Copyright (C)
3    * 2005-2009 M. Rohrmoser
4    * 
5    * This program is free software; you can redistribute it and/or modify it under
6    * the terms of the GNU General Public License as published by the Free Software
7    * Foundation; either version 2 of the License, or (at your option) any later
8    * version.
9    * 
10   * This program is distributed in the hope that it will be useful, but WITHOUT
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13   * details.
14   * 
15   * You should have received a copy of the GNU General Public License along with
16   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17   * Place, Suite 330, Boston, MA 02111-1307 USA
18   */
19  
20  package org.jcurl.demo.smack;
21  
22  import javax.swing.JComponent;
23  
24  import org.apache.commons.logging.Log;
25  import org.jcurl.core.log.JCLoggerFactory;
26  import org.jivesoftware.smack.Chat;
27  import org.jivesoftware.smack.ChatManagerListener;
28  import org.jivesoftware.smack.MessageListener;
29  import org.jivesoftware.smack.XMPPConnection;
30  import org.jivesoftware.smack.packet.Message;
31  
32  /**
33   * Log a conversation. Register with {@link XMPPConnection#getChatManager()} to
34   * keep track of the current chats.
35   * 
36   * @author <a href="mailto:JCurl@mro.name">M. Rohrmoser </a>
37   * @version $Id: ChatLogSimpleSwingBean.java 1031 2009-07-23 15:06:05Z mro $
38   */
39  public class ChatLogSimpleSwingBean extends JComponent implements
40  		ChatManagerListener, MessageListener {
41  
42  	private static final Log log = JCLoggerFactory
43  			.getLogger(ChatLogSimpleSwingBean.class);
44  	private static final long serialVersionUID = 7185219077872195562L;
45  
46  	public ChatLogSimpleSwingBean() {}
47  
48  	public void chatCreated(final Chat chat, final boolean flag) {
49  		chat.addMessageListener(this);
50  	}
51  
52  	public void processMessage(final Chat chat, final Message message) {
53  		if (message.getBody() == null)
54  			log.info(message.getFrom() + " -> " + message.getTo() + ": "
55  					+ message.toXML());
56  		else
57  			log.info(message.getFrom() + " -> " + message.getTo() + ": "
58  					+ message.getBody());
59  	}
60  
61  }