Changeset 538:2d20ea6087b0
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
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. |
| 4 | 4 | // Please first read the full copyright statement in file COPYRIGHT.html |
| 5 | 5 | package org.w3c.unicorn.output; |
| 6 | 6 | |
| 7 | 7 | import java.io.CharArrayWriter; |
| 8 | | import java.io.IOException; |
| 9 | 8 | import java.io.UnsupportedEncodingException; |
| 10 | 9 | import java.io.Writer; |
| | 10 | import java.util.Date; |
| 11 | 11 | import java.util.Map; |
| 12 | 12 | import java.util.ArrayList; |
| 13 | 13 | import java.util.Properties; |
| | 14 | import org.w3c.unicorn.util.Message; |
| 14 | 15 | import javax.mail.*; |
| 15 | 16 | import javax.mail.internet.*; |
| 16 | 17 | import org.w3c.unicorn.UnicornCall; |
| | 18 | import org.w3c.unicorn.exceptions.UnicornException; |
| 17 | 19 | import org.w3c.unicorn.util.Property; |
| 18 | 20 | import org.w3c.unicorn.util.UnicornAuthenticator; |
| 19 | 21 | |
| 20 | 22 | /** |
| 21 | | * This module allow to generate output in mail format. |
| | 23 | * This module allows to send the response by mail. |
| 22 | 24 | * |
| 23 | 25 | * @author Thomas GAMBET |
| … |
… |
|
| 50 | 52 | } |
| 51 | 53 | |
| 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 { |
| 53 | 56 | //mapOfStringObject.put("baseUri", "http://qa-dev.w3.org/unicorn/"); |
| 54 | 57 | |
| 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 | } |
| 56 | 66 | displayOnIndex(mapOfStringObject, aWriter); |
| | 67 | messages.remove(pendingMess); |
| 57 | 68 | } |
| 58 | 69 | |
| | 70 | @SuppressWarnings("unchecked") |
| 59 | 71 | public void produceOutput(Map<String, Object> mapOfStringObject, final Writer aWriter) { |
| 60 | 72 | |
| | 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 | |
| 61 | 79 | try { |
| 62 | | |
| 63 | 80 | mapOfStringObject.put("baseUri", "http://qa-dev.w3.org:8001/unicorn/"); |
| 64 | 81 | |
| … |
… |
|
| 72 | 89 | |
| 73 | 90 | session.setDebug(debug); |
| 74 | | Message msg = new MimeMessage(session); |
| | 91 | javax.mail.Message msg = new MimeMessage(session); |
| 75 | 92 | |
| 76 | 93 | InternetAddress addressFrom = new InternetAddress(mailProps.getProperty("unicorn.mail.from"), "Unicorn"); |
| 77 | 94 | msg.setFrom(addressFrom); |
| 78 | | msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); |
| | 95 | msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(recipient)); |
| 79 | 96 | |
| 80 | 97 | // Setting the Subject and Content Type |
| … |
… |
|
| 110 | 127 | |
| 111 | 128 | 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 | } |
| 112 | 133 | firstOutputFormater.produceError(mapOfStringObject, aWriter); |
| 113 | 134 | } |