1
22
23 package com.liferay.portal.im;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.util.PropsKeys;
28 import com.liferay.portal.util.PropsUtil;
29
30 import org.walluck.oscar.AIMConnection;
31 import org.walluck.oscar.AIMSession;
32 import org.walluck.oscar.client.Oscar;
33
34
41 public class AIMConnector {
42
43 public static void disconnect() {
44 if (_instance != null) {
45 _instance._disconnect();
46 }
47 }
48
49 public static void send(String to, String msg) {
50 _instance._send(to, msg);
51 }
52
53 private AIMConnector() {
54 }
55
56 private void _connect() {
57 String login = PropsUtil.get(PropsKeys.AIM_LOGIN);
58 String password = PropsUtil.get(PropsKeys.AIM_PASSWORD);
59
60 AIMSession ses = new AIMSession();
61
62 ses.setSN(login);
63
64 Oscar oscar = new Oscar();
65
66 oscar.setSN(login);
67 oscar.setPassword(password);
68
69 ses.init();
70 }
71
72 private void _disconnect() {
73 if (_aim != null) {
74 AIMConnection.killAllInSess(_aim);
75 }
76 }
77
78 private void _send(String to, String msg) {
79 try {
80 if (_aim == null) {
81 _connect();
82
83
86 Thread.sleep(1000);
87 }
88
89 _oscar.sendIM(_aim, to, msg, Oscar.getICQCaps());
90 }
91 catch (Exception e) {
92 if (_log.isWarnEnabled()) {
93 _log.warn("Could not send AIM message");
94 }
95 }
96 }
97
98 private static Log _log = LogFactoryUtil.getLog(AIMConnector.class);
99
100 private static AIMConnector _instance = new AIMConnector();
101
102 private AIMSession _aim;
103 private Oscar _oscar;
104
105 }