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
42 public class AIMConnector {
43
44 public static void disconnect() {
45 if (_instance != null) {
46 _instance._disconnect();
47 }
48 }
49
50 public static void send(String to, String msg) {
51 _instance._send(to, msg);
52 }
53
54 private AIMConnector() {
55 }
56
57 private void _connect() {
58 String login = PropsUtil.get(PropsKeys.AIM_LOGIN);
59 String password = PropsUtil.get(PropsKeys.AIM_PASSWORD);
60
61 AIMSession ses = new AIMSession();
62
63 ses.setSN(login);
64
65 Oscar oscar = new Oscar();
66
67 oscar.setSN(login);
68 oscar.setPassword(password);
69
70 ses.init();
71 }
72
73 private void _disconnect() {
74 if (_aim != null) {
75 AIMConnection.killAllInSess(_aim);
76 }
77 }
78
79 private void _send(String to, String msg) {
80 try {
81 if (_aim == null) {
82 _connect();
83
84
87 Thread.sleep(1000);
88 }
89
90 _oscar.sendIM(_aim, to, msg, Oscar.getICQCaps());
91 }
92 catch (Exception e) {
93 if (_log.isWarnEnabled()) {
94 _log.warn("Could not send AIM message");
95 }
96 }
97 }
98
99 private static Log _log = LogFactoryUtil.getLog(AIMConnector.class);
100
101 private static AIMConnector _instance = new AIMConnector();
102
103 private AIMSession _aim;
104 private Oscar _oscar;
105
106 }