[vlma-devel] commit: A MSN notifier. (Adrien Grand )

git version control git at videolan.org
Wed Jun 18 20:09:36 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Wed Jun 18 20:11:18 2008 +0200| [6aaee0cb72bec899b7a367fbf8e4661f61e255dd]

A MSN notifier.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=6aaee0cb72bec899b7a367fbf8e4661f61e255dd
---

 vlma-core/pom.xml                                  |    5 +
 .../org/videolan/vlma/notifier/MSNNotifier.java    |   99 ++++++++++++++++++++
 vlma-daemon/src/main/resources/config.properties   |    3 +
 vlma-daemon/src/main/resources/daemon.xml          |    3 +
 4 files changed, 110 insertions(+), 0 deletions(-)

diff --git a/vlma-core/pom.xml b/vlma-core/pom.xml
index b59fed1..b306eef 100644
--- a/vlma-core/pom.xml
+++ b/vlma-core/pom.xml
@@ -69,6 +69,11 @@
            <version>1.10</version>
         </dependency>
         <dependency>
+            <groupId>jmsn</groupId>
+            <artifactId>msnmlib</artifactId>
+            <version>1.4-20050613</version>
+        </dependency>
+        <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring</artifactId>
             <version>${spring.version}</version>
diff --git a/vlma-core/src/main/java/org/videolan/vlma/notifier/MSNNotifier.java b/vlma-core/src/main/java/org/videolan/vlma/notifier/MSNNotifier.java
new file mode 100644
index 0000000..10ec37b
--- /dev/null
+++ b/vlma-core/src/main/java/org/videolan/vlma/notifier/MSNNotifier.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2006-2008 the VideoLAN team
+ *
+ * This file is part of VLMa.
+ *
+ * VLMa is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * VLMa is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with VLMa. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package org.videolan.vlma.notifier;
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.videolan.vlma.VLMa;
+
+import rath.msnm.MSNMessenger;
+import rath.msnm.SwitchboardSession;
+import rath.msnm.UserStatus;
+import rath.msnm.msg.MimeMessage;
+
+/**
+ * A MSN notifier.
+ *
+ * @author jpountz
+ */
+public class MSNNotifier extends Notifier {
+
+    public static final Logger logger = Logger.getLogger(IRCNotifier.class);
+
+    private MSNMessenger msnm;
+    private String login;
+    private String pass;
+    private String[] recipients;
+
+    public MSNNotifier() {
+        connect();
+    }
+
+    /**
+     * Log into MSN.
+     */
+    private void connect() {
+        login = VLMa.getInstance().getString("vlma.notification.msn.login");
+        pass = VLMa.getInstance().getString("vlma.notification.msn.pass");
+        recipients = VLMa.getInstance().getString("vlma.notification.msn.recipients").split(",");
+        msnm = new MSNMessenger(login, pass);
+        msnm.setInitialStatus(UserStatus.ONLINE);
+        msnm.login();
+    }
+
+    /**
+     * Does the user want to be notified by MSN?
+     *
+     * @return true if there is one recipient or more
+     */
+    private boolean isMSNEnabled() {
+        String tmp = VLMa.getInstance().getString("vlma.notification.msn.recipients");
+        return (tmp != null && tmp.length() > 0);
+    }
+
+    @Override
+    public void sendNotification(String message) {
+        if (isMSNEnabled()) {
+            if (msnm == null || !msnm.isLoggedIn()) {
+                connect();
+            }
+            MimeMessage msg = new MimeMessage();
+            msg.setKind(MimeMessage.KIND_MESSAGE);
+            msg.setMessage(message);
+            SwitchboardSession ss = null;
+            for(String recipient : recipients) {
+                ss = null;
+                try {
+                    while (ss == null) {
+                       ss = msnm.doCallWait(recipient);
+                    }
+                    ss.sendInstantMessage(msg);
+                } catch (IOException e) {
+                    logger.error("Could not send message", e);
+                } catch (InterruptedException e) {
+                    logger.error("Could not send message", e);
+                }
+            }
+        }
+    }
+
+}
diff --git a/vlma-daemon/src/main/resources/config.properties b/vlma-daemon/src/main/resources/config.properties
index cc51414..60712e2 100644
--- a/vlma-daemon/src/main/resources/config.properties
+++ b/vlma-daemon/src/main/resources/config.properties
@@ -22,6 +22,9 @@ vlma.notification.irc.port = 6667
 vlma.notification.mail.host = localhost
 vlma.notification.mail.recipients =
 vlma.notification.mail.sender = VideoLAN Manager <noreply at videolan.org>
+vlma.notification.msn.login =
+vlma.notification.msn.pass =
+vlma.notification.msn.recipients =
 vlma.sap.files.group = Files
 vlma.sap.radio.group = Radio
 vlma.sap.stream.group = Stream
diff --git a/vlma-daemon/src/main/resources/daemon.xml b/vlma-daemon/src/main/resources/daemon.xml
index 83426ca..19b2886 100644
--- a/vlma-daemon/src/main/resources/daemon.xml
+++ b/vlma-daemon/src/main/resources/daemon.xml
@@ -50,6 +50,7 @@
             <list>
                 <ref bean="mailNotifier" />
                 <ref bean="ircNotifier" />
+                <ref bean="msnNotifier" />
             </list>
         </property>
     </bean>
@@ -64,6 +65,8 @@
         <property name="mailSender" ref="mailSender" />
     </bean>
 
+    <bean id="msnNotifier" class="org.videolan.vlma.notifier.MSNNotifier" />
+
     <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl" />
 
 	<bean id="orderGiver" class="org.videolan.vlma.OrderGiverImpl">



More information about the vlma-devel mailing list