Changeset 538:2d20ea6087b0

Show
Ignore:
Timestamp:
09/24/09 17:42:22 (4 years ago)
Author:
tgambet
Branch:
default
convert_revision:
svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@539
Message:

an error is thrown if the recipient is not specified
+ adds a temporary message containing the date of the observation to the mail output

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/org/w3c/unicorn/output/MailOutputModule.java

    r526 r538  
    1 // $Id: MailOutputModule.java,v 1.8 2009-09-24 15:33:03 tgambet Exp $ 
    2 // Author: Damien LEROY. 
    3 // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. 
     1// $Id: MailOutputModule.java,v 1.9 2009-09-24 17:42:22 tgambet Exp $ 
     2// Author: Thomas Gambet 
     3// (c) COPYRIGHT MIT, ERCIM and Keio, 2009. 
    44// Please first read the full copyright statement in file COPYRIGHT.html 
    55package org.w3c.unicorn.output; 
    66 
    77import java.io.CharArrayWriter; 
    8 import java.io.IOException; 
    98import java.io.UnsupportedEncodingException; 
    109import java.io.Writer; 
     10import java.util.Date; 
    1111import java.util.Map; 
    1212import java.util.ArrayList; 
    1313import java.util.Properties; 
     14import org.w3c.unicorn.util.Message; 
    1415import javax.mail.*; 
    1516import javax.mail.internet.*; 
    1617import org.w3c.unicorn.UnicornCall; 
     18import org.w3c.unicorn.exceptions.UnicornException; 
    1719import org.w3c.unicorn.util.Property; 
    1820import org.w3c.unicorn.util.UnicornAuthenticator; 
    1921 
    2022/** 
    21  * This module allow to generate output in mail format. 
     23 * This module allows to send the response by mail. 
    2224 *  
    2325 * @author Thomas GAMBET 
     
    5052        } 
    5153         
    52         public void produceFirstOutput(Map<String, Object> mapOfStringObject, Writer aWriter) { 
     54        @SuppressWarnings("unchecked") 
     55        public void produceFirstOutput(Map<String, Object> mapOfStringObject, Writer aWriter) throws UnicornException { 
    5356                //mapOfStringObject.put("baseUri", "http://qa-dev.w3.org/unicorn/"); 
    5457                 
    55                 ((ArrayList<org.w3c.unicorn.util.Message>) mapOfStringObject.get("messages")). add(new org.w3c.unicorn.util.Message(org.w3c.unicorn.util.Message.Level.INFO, "Le rapport est en cours d'envoi à l'adresse: " + recipient)); 
     58                ArrayList<Message> messages = ((ArrayList<Message>) mapOfStringObject.get("messages")); 
     59                Message pendingMess = new Message(Message.Level.INFO, "Le rapport est en cours d'envoi à l'adresse: " + recipient); 
     60                 
     61                if (recipient == null) { 
     62                        throw new UnicornException(new Message(Message.Level.ERROR, "Aucune adresse email spécifiée. Rajoutez &opt_email=votre.adresse@mail.com à la requête.")); 
     63                } else { 
     64                        messages.add(pendingMess); 
     65                } 
    5666                displayOnIndex(mapOfStringObject, aWriter); 
     67                messages.remove(pendingMess); 
    5768        } 
    5869         
     70        @SuppressWarnings("unchecked") 
    5971        public void produceOutput(Map<String, Object> mapOfStringObject, final Writer aWriter) { 
    6072                 
     73                if (recipient == null) 
     74                        return; 
     75                 
     76                ArrayList<Message> messages = ((ArrayList<Message>) mapOfStringObject.get("messages")); 
     77                messages.add(new Message(Message.Level.INFO, "Observation effectuée le " + new Date())); 
     78                 
    6179                try { 
    62                          
    6380                        mapOfStringObject.put("baseUri", "http://qa-dev.w3.org:8001/unicorn/"); 
    6481                         
     
    7289                         
    7390                        session.setDebug(debug); 
    74                     Message msg = new MimeMessage(session); 
     91                        javax.mail.Message msg = new MimeMessage(session); 
    7592                     
    7693                    InternetAddress addressFrom = new InternetAddress(mailProps.getProperty("unicorn.mail.from"), "Unicorn"); 
    7794                        msg.setFrom(addressFrom); 
    78                         msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); 
     95                        msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(recipient)); 
    7996                         
    8097                        // Setting the Subject and Content Type 
     
    110127 
    111128        public void produceError(Map<String, Object> mapOfStringObject, final Writer aWriter) { 
     129                if (outputParameters.get("mimetype").equals("text/html")) { 
     130                        displayOnIndex(mapOfStringObject, aWriter); 
     131                        return; 
     132                } 
    112133                firstOutputFormater.produceError(mapOfStringObject, aWriter); 
    113134        }