W3C home > Mailing lists > Public > www-validator-cvs@w3.org > September 2009

2006/unicorn/src/org/w3c/unicorn/output MailOutputModule.java,1.1,1.2

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 23 Sep 2009 09:28:07 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MqO8t-0004IK-7u@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/output
In directory hutz:/tmp/cvs-serv16480/src/org/w3c/unicorn/output

Modified Files:
	MailOutputModule.java 
Log Message:
first draft of the MailOutputModule

Index: MailOutputModule.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/output/MailOutputModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- MailOutputModule.java	22 Sep 2009 12:39:29 -0000	1.1
+++ MailOutputModule.java	23 Sep 2009 09:28:05 -0000	1.2
@@ -4,8 +4,14 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.unicorn.output;
 
+import java.io.CharArrayWriter;
+import java.io.IOException;
 import java.io.Writer;
 import java.util.Map;
+import javax.mail.*;
+import javax.mail.internet.*;
+
+import java.util.*; 
 
 /**
  * This module allow to generate output in mail format.
@@ -13,32 +19,102 @@
  * @author Thomas GAMBET
  */
 public class MailOutputModule implements OutputModule {
-
-	public void produceFirstOutput(OutputFormater aOutputFormater,
-			Map<String, Object> mapOfStringObject,
-			Map<String, String> mapOfParameter, Writer aWriter) {
+	
+	private OutputFormater aOutputFormater;
+	
+	private OutputFormater mailOutputFormater;
+	
+	private Map<String, String> mapOfOutputParameters;
+	
+	private Map<String, String> mapOfSpecificParameters;
+	
+	private String recipient;
+	
+	public MailOutputModule(Map<String, String> mapOfOutputParameters, Map<String, String> mapOfSpecificParameters) {
+		this.mapOfOutputParameters = mapOfOutputParameters;
+		this.mapOfSpecificParameters = mapOfSpecificParameters;
+		this.recipient = mapOfSpecificParameters.get("email");
+			
 		
+		aOutputFormater = OutputFactory.createOutputFormater(mapOfOutputParameters.get("format"),
+				mapOfOutputParameters.get("lang"), mapOfOutputParameters.get("mimetype"));
 		
-		aOutputFormater.produceOutput(mapOfStringObject, aWriter);
+		mailOutputFormater = OutputFactory.createOutputFormater(mapOfSpecificParameters.get("format"),
+				mapOfOutputParameters.get("lang"), mapOfOutputParameters.get("mimetype"));
 		
 	}
 	
-	public void produceOutput(final OutputFormater aOutputFormater, Map<String, Object> mapOfStringObject,
-			final Map<String, String> mapOfParameter, final Writer aWriter) {
+	public void produceFirstOutput(Map<String, Object> mapOfStringObject, Writer aWriter) {
 		
+		try {
+			aWriter.append("mail en cours d'envoi.");
+			aWriter.close();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			System.out.println("TOOOOOO");
+			e.printStackTrace();
+		}
+	}
+	
+	public void produceOutput(Map<String, Object> mapOfStringObject, final Writer aWriter) {
 		
+		/*try {
+			aWriter.close();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			System.out.println("TOOOOOO");
+			e.printStackTrace();
+		}*/
 		
-		aOutputFormater.produceOutput(mapOfStringObject, aWriter);
+	    Properties props = new Properties();
+	    props.put("mail.smtp.starttls.enable","true");
+	    //props.put("mail.smtp.user", "thomas.gambet@gmail.com");
+	    
+		try {
+			Session session = Session.getDefaultInstance(props, null);
+		    session.setDebug(true);
+		    Message msg = new MimeMessage(session);
+			
+		    InternetAddress addressFrom = new InternetAddress("thomas.gambet@gmail.com");
+			msg.setFrom(addressFrom);
+			
+			InternetAddress[] adresses = {new InternetAddress(recipient)};
+			msg.setRecipients(Message.RecipientType.TO, adresses);
+			
+			// Setting the Subject and Content Type
+			msg.setSubject("test subject");
+			
+			CharArrayWriter writer = new CharArrayWriter();
+			mailOutputFormater.produceOutput(mapOfStringObject, writer);
+			writer.close();
+			
+			msg.setContent(writer.toString(), mapOfOutputParameters.get("mimetype"));
+			
+			Transport transport = session.getTransport("smtp");
+			transport.connect("smtp.gmail.com", "eric.gambet@gmail.com", "36153615");
+			transport.sendMessage(msg, msg.getAllRecipients());
+			//aOutputFormater.produceOutput(mapOfStringObject, aWriter);
+			//aWriter.close();
+		} catch (AddressException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (MessagingException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} 
 	}
 
-	public void produceError(final OutputFormater aOutputFormater, Map<String, Object> mapOfStringObject,
-			final Map<String, String> mapOfParameter, final Writer aWriter) {
+	public void produceError(Map<String, Object> mapOfStringObject, final Writer aWriter) {
 		
 		
 		
 		aOutputFormater.produceError(mapOfStringObject, aWriter);
 	}
 
+	public String getOutputParameter(String string) {
+		return mapOfOutputParameters.get(string);
+	}
+
 
 
 }
Received on Wednesday, 23 September 2009 09:28:15 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:14 GMT