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