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