Changeset 723:7dfb0815f55a
- Timestamp:
- 10/09/09 11:13:10 (4 years ago)
- Author:
- tgambet
- Branch:
- default
- convert_revision:
- svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@724
- Message:
-
changed named from AttachmentOutputFormater? to FileOutputFormater?
+ cleaned up
+ utf-8 support
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r714
|
r723
|
|
| | 1 | // $Id: Mail.java,v 1.3 2009-10-09 11:13:10 tgambet Exp $ |
| | 2 | // Author: Thomas Gambet |
| | 3 | // (c) COPYRIGHT MIT, ERCIM and Keio, 2009. |
| | 4 | // Please first read the full copyright statement in file COPYRIGHT.html |
| 1 | 5 | package org.w3c.unicorn.util; |
| 2 | 6 | |
| 3 | 7 | import java.io.ByteArrayOutputStream; |
| 4 | | import java.io.CharArrayWriter; |
| 5 | | import java.io.File; |
| 6 | | import java.io.FileOutputStream; |
| 7 | 8 | import java.io.IOException; |
| 8 | 9 | import java.io.OutputStreamWriter; |
| 9 | | import java.io.PrintWriter; |
| 10 | | import java.io.StringWriter; |
| 11 | 10 | import java.io.UnsupportedEncodingException; |
| 12 | 11 | import java.util.ArrayList; |
| … |
… |
|
| 18 | 17 | import javax.mail.Authenticator; |
| 19 | 18 | import javax.mail.MessagingException; |
| 20 | | import javax.mail.Multipart; |
| 21 | 19 | import javax.mail.Session; |
| 22 | 20 | import javax.mail.Transport; |
| … |
… |
|
| 26 | 24 | import javax.mail.internet.MimeMultipart; |
| 27 | 25 | |
| 28 | | import org.apache.commons.lang.StringEscapeUtils; |
| 29 | 26 | import org.w3c.unicorn.exceptions.UnicornException; |
| 30 | | import org.w3c.unicorn.output.AttachmentOutputFormater; |
| | 27 | import org.w3c.unicorn.output.FileOutputFormater; |
| 31 | 28 | import org.w3c.unicorn.output.OutputFormater; |
| 32 | 29 | |
| … |
… |
|
| 64 | 61 | for (OutputFormater outputFormater : outputFormaters) { |
| 65 | 62 | MimeBodyPart bodyPart = new MimeBodyPart(); |
| 66 | | if (outputFormater instanceof AttachmentOutputFormater) |
| 67 | | bodyPart.setFileName(((AttachmentOutputFormater) outputFormater).getFileName()); |
| | 63 | if (outputFormater instanceof FileOutputFormater) |
| | 64 | bodyPart.setFileName(((FileOutputFormater) outputFormater).getFileName()); |
| 68 | 65 | |
| 69 | 66 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 70 | 67 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(byteArrayOutputStream, "UTF-8"); |
| 71 | | |
| 72 | 68 | outputFormater.produceOutput(contextObjects, outputStreamWriter); |
| 73 | | |
| 74 | | |
| 75 | | |
| 76 | 69 | try { |
| 77 | 70 | outputStreamWriter.close(); |
| … |
… |
|
| 82 | 75 | } |
| 83 | 76 | |
| 84 | | |
| 85 | | |
| 86 | | bodyPart.setContent(byteArrayOutputStream.toString("UTF-8"), outputFormater.getMimeType()); |
| 87 | | |
| 88 | | bodyPart.setHeader("Content-Type", outputFormater.getMimeType() + "; charset=UTF-8"); |
| 89 | | bodyPart.setHeader("Content-Transfer-Encoding", "8bit"); |
| | 77 | bodyPart.setContent(byteArrayOutputStream.toString("UTF-8"), outputFormater.getMimeType() + "; charset=UTF-8"); |
| | 78 | bodyPart.setHeader("Content-Transfer-Encoding", "7bit"); |
| 90 | 79 | mp.addBodyPart(bodyPart); |
| 91 | 80 | } |
| … |
… |
|
| 94 | 83 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 95 | 84 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(byteArrayOutputStream, "UTF-8"); |
| 96 | | //CharArrayWriter wr = new CharArrayWriter(); |
| 97 | | |
| 98 | 85 | outputFormaters.get(0).produceOutput(contextObjects, outputStreamWriter); |
| 99 | | |
| 100 | | //outputStreamWriter.write("んのこと仲介手数料もなし"); |
| 101 | | |
| 102 | 86 | try { |
| 103 | 87 | outputStreamWriter.close(); |
| … |
… |
|
| 106 | 90 | // TODO Auto-generated catch block |
| 107 | 91 | e.printStackTrace(); |
| 108 | | } |
| 109 | | System.out.println(byteArrayOutputStream.toString("UTF-8")); |
| 110 | | |
| 111 | | |
| | 92 | } |
| 112 | 93 | msg.setContent(byteArrayOutputStream.toString("UTF-8"), outputFormaters.get(0).getMimeType() + "; charset=UTF-8"); |
| 113 | | msg.writeTo(new FileOutputStream(new File(Property.get("UPLOADED_FILES_REPOSITORY") + "/test1.txt"))); |
| 114 | | msg.setHeader("Content-Type", outputFormaters.get(0).getMimeType() + "; charset=UTF-8"); |
| 115 | 94 | msg.setHeader("Content-Transfer-Encoding", "7bit"); |
| 116 | | |
| 117 | 95 | } |
| 118 | | msg.writeTo(new FileOutputStream(new File(Property.get("UPLOADED_FILES_REPOSITORY") + "/test.txt"))); |
| | 96 | |
| 119 | 97 | Transport.send(msg); |
| 120 | 98 | } catch (UnsupportedEncodingException e) { |
| … |
… |
|
| 122 | 100 | e.printStackTrace(); |
| 123 | 101 | } catch (MessagingException e) { |
| 124 | | // TODO Auto-generated catch block |
| 125 | | e.printStackTrace(); |
| 126 | | } catch (IOException e) { |
| 127 | 102 | // TODO Auto-generated catch block |
| 128 | 103 | e.printStackTrace(); |