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