1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.im;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  
20  import rath.msnm.MSNMessenger;
21  import rath.msnm.SwitchboardSession;
22  import rath.msnm.entity.MsnFriend;
23  import rath.msnm.event.MsnAdapter;
24  import rath.msnm.msg.MimeMessage;
25  
26  /**
27   * <a href="MSNMessageAdapter.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class MSNMessageAdapter extends MsnAdapter {
32  
33      public MSNMessageAdapter(MSNMessenger msn, String to, String msg) {
34          _msn = msn;
35          _to = to;
36          _msg = msg;
37      }
38  
39      public void whoJoinSession(SwitchboardSession ss, MsnFriend join) {
40          try {
41              if (_to.equals(join.getLoginName())) {
42                  ss.sendInstantMessage(new MimeMessage(_msg));
43                  ss.cleanUp();
44              }
45          }
46          catch (Exception e) {
47              _log.warn(e);
48          }
49  
50          _msn.removeMsnListener(this);
51      }
52  
53      private static Log _log = LogFactoryUtil.getLog(MSNConnector.class);
54  
55      private MSNMessenger _msn;
56      private String _to;
57      private String _msg;
58  
59  }