001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.im;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    
020    import rath.msnm.MSNMessenger;
021    import rath.msnm.SwitchboardSession;
022    import rath.msnm.entity.MsnFriend;
023    import rath.msnm.event.MsnAdapter;
024    import rath.msnm.msg.MimeMessage;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class MSNMessageAdapter extends MsnAdapter {
030    
031            public MSNMessageAdapter(MSNMessenger msn, String to, String msg) {
032                    _msn = msn;
033                    _to = to;
034                    _msg = msg;
035            }
036    
037            @Override
038            public void whoJoinSession(SwitchboardSession ss, MsnFriend join) {
039                    try {
040                            if (_to.equals(join.getLoginName())) {
041                                    ss.sendInstantMessage(new MimeMessage(_msg));
042                                    ss.cleanUp();
043                            }
044                    }
045                    catch (Exception e) {
046                            _log.warn(e);
047                    }
048    
049                    _msn.removeMsnListener(this);
050            }
051    
052            private static Log _log = LogFactoryUtil.getLog(MSNConnector.class);
053    
054            private MSNMessenger _msn;
055            private String _to;
056            private String _msg;
057    
058    }