001
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 import com.liferay.portal.kernel.util.PropsKeys;
020 import com.liferay.portal.util.PropsUtil;
021
022 import org.walluck.oscar.AIMConnection;
023 import org.walluck.oscar.AIMSession;
024 import org.walluck.oscar.client.Oscar;
025
026
031 public class AIMConnector {
032
033 public static void disconnect() {
034 if (_instance != null) {
035 _instance._disconnect();
036 }
037 }
038
039 public static void send(String to, String msg) {
040 _instance._send(to, msg);
041 }
042
043 private AIMConnector() {
044 }
045
046 private void _connect() {
047 String login = PropsUtil.get(PropsKeys.AIM_LOGIN);
048 String password = PropsUtil.get(PropsKeys.AIM_PASSWORD);
049
050 AIMSession ses = new AIMSession();
051
052 ses.setSN(login);
053
054 Oscar oscar = new Oscar();
055
056 oscar.setSN(login);
057 oscar.setPassword(password);
058
059 ses.init();
060 }
061
062 private void _disconnect() {
063 if (_aim != null) {
064 AIMConnection.killAllInSess(_aim);
065 }
066 }
067
068 private void _send(String to, String msg) {
069 try {
070 if (_aim == null) {
071 _connect();
072
073
074
075
076 Thread.sleep(1000);
077 }
078
079 _oscar.sendIM(_aim, to, msg, Oscar.getICQCaps());
080 }
081 catch (Exception e) {
082 if (_log.isWarnEnabled()) {
083 _log.warn("Could not send AIM message");
084 }
085 }
086 }
087
088 private static Log _log = LogFactoryUtil.getLog(AIMConnector.class);
089
090 private static AIMConnector _instance = new AIMConnector();
091
092 private AIMSession _aim;
093 private Oscar _oscar;
094
095 }