[vlma-devel] commit: Use getList() to retrieve several values at the same time. ( Adrien Grand )

git version control git at videolan.org
Mon Jun 30 23:10:56 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Mon Jun 30 23:02:11 2008 +0200| [c68bef3b9b869c7bce825d33651cb0895c685fc5]

Use getList() to retrieve several values at the same time.

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

 .../org/videolan/vlma/notifier/IRCNotifier.java    |   22 ++++++++++++-------
 .../org/videolan/vlma/notifier/MSNNotifier.java    |   11 ++++++---
 .../org/videolan/vlma/notifier/MailNotifier.java   |   12 +++++++++-
 3 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/notifier/IRCNotifier.java b/vlma-core/src/main/java/org/videolan/vlma/notifier/IRCNotifier.java
index 7166a99..d45de9d 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/notifier/IRCNotifier.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/notifier/IRCNotifier.java
@@ -21,6 +21,7 @@
 package org.videolan.vlma.notifier;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.log4j.Logger;
 import org.schwering.irc.lib.IRCConnection;
@@ -42,7 +43,7 @@ public class IRCNotifier extends Notifier {
     private IRCConnection conn;
     private String nick;
     private String pass;
-    private String chan;
+    private List<String> chans;
     private String host;
     private int port;
 
@@ -61,12 +62,13 @@ public class IRCNotifier extends Notifier {
      *
      * @throws IOException
      */
+    @SuppressWarnings("unchecked")
     private void connect() throws IOException {
         nick = VLMa.getInstance().getString("vlma.notification.irc.nick");
         pass = VLMa.getInstance().getString("vlma.notification.irc.pass");
         host = VLMa.getInstance().getString("vlma.notification.irc.host");
         port = VLMa.getInstance().getInt("vlma.notification.irc.port");
-        chan = VLMa.getInstance().getString("vlma.notification.irc.chan");
+        chans = VLMa.getInstance().getList("vlma.notification.irc.chan");
         conn = new IRCConnection(host, new int[] { port }, pass, nick, "vlma", "VLMa");
         conn.setEncoding("UTF-8");
         conn.addIRCEventListener(new Listener());
@@ -79,7 +81,9 @@ public class IRCNotifier extends Notifier {
         try {
             Thread.sleep(5000);
         } catch (InterruptedException e) { }
-        conn.doJoin(chan);
+        for (String chan : chans) {
+            conn.doJoin(chan);
+        }
     }
 
     /**
@@ -106,11 +110,13 @@ public class IRCNotifier extends Notifier {
     @Override
     public void sendNotification(String message) {
         if (isIRCEnabled()) {
-            try {
-                checkConnection();
-                conn.doPrivmsg(chan, message);
-            } catch (IOException e) {
-                logger.error("IRC notifier cannot connect", e);
+            for (String chan : chans) {
+                try {
+                    checkConnection();
+                    conn.doPrivmsg(chan, message);
+                } catch (IOException e) {
+                    logger.error("IRC notifier cannot connect", e);
+                }
             }
         }
     }
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
index 81616bc..8261232 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/notifier/MSNNotifier.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/notifier/MSNNotifier.java
@@ -21,6 +21,7 @@
 package org.videolan.vlma.notifier;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.log4j.Logger;
 import org.videolan.vlma.VLMa;
@@ -42,7 +43,7 @@ public class MSNNotifier extends Notifier {
     private MSNMessenger msnm;
     private String login;
     private String pass;
-    private String[] recipients;
+    private List<String> recipients;
 
     public MSNNotifier() {
         if (isMSNEnabled()) {
@@ -53,10 +54,11 @@ public class MSNNotifier extends Notifier {
     /**
      * Log into MSN.
      */
+    @SuppressWarnings("unchecked")
     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(",");
+        recipients = VLMa.getInstance().getList("vlma.notification.msn.recipients");
         msnm = new MSNMessenger(login, pass);
         msnm.setInitialStatus(UserStatus.ONLINE);
         msnm.login();
@@ -67,9 +69,10 @@ public class MSNNotifier extends Notifier {
      *
      * @return true if there is one recipient or more
      */
+    @SuppressWarnings("unchecked")
     private boolean isMSNEnabled() {
-        String tmp = VLMa.getInstance().getString("vlma.notification.msn.recipients");
-        return (tmp != null && tmp.length() > 0);
+        List<String> tmp = VLMa.getInstance().getList("vlma.notification.msn.recipients");
+        return (tmp != null && tmp.size() > 0);
     }
 
     @Override
diff --git a/vlma-core/src/main/java/org/videolan/vlma/notifier/MailNotifier.java b/vlma-core/src/main/java/org/videolan/vlma/notifier/MailNotifier.java
index 9654a77..da38caa 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/notifier/MailNotifier.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/notifier/MailNotifier.java
@@ -20,6 +20,8 @@
 
 package org.videolan.vlma.notifier;
 
+import java.util.List;
+
 import org.apache.log4j.Logger;
 import org.springframework.mail.MailException;
 import org.springframework.mail.javamail.JavaMailSenderImpl;
@@ -46,15 +48,21 @@ public class MailNotifier extends Notifier {
         return (tmp != null && tmp.length() > 0);
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public void sendNotification(String message) {
         if (isMailEnabled()) {
             SimpleMailMessage msg = new SimpleMailMessage();
             String from = VLMa.getInstance().getString("vlma.notification.mail.sender");
-            String[] recipients = VLMa.getInstance().getString("vlma.notification.mail.recipients").split(",");
+            List<String> recipients = VLMa.getInstance().getList("vlma.notification.mail.recipients");
             mailSender.setHost(VLMa.getInstance().getString("vlma.notification.mail.host"));
             msg.setFrom(from);
-            msg.setTo(recipients);
+            String[] recipientsArray = new String[recipients.size()];
+            int i = 0;
+            for (String recipient : recipients) {
+                recipientsArray[i++] = recipient;
+            }
+            msg.setTo(recipientsArray);
             msg.setSubject(message);
             msg.setText(message);
             try{



More information about the vlma-devel mailing list