Coverage report

  %line %branch
com.ozacc.mail.fetch.impl.sk_jp.CorrectedContentTypeDataSource
0% 
0% 

 1  
 /*
 2  
  * @(#) $Id: CorrectedContentTypeDataSource.java,v 1.1.2.2 2004/10/24 10:27:40 otsuka Exp $
 3  
  * $Revision: 1.1.2.2 $
 4  
  * Copyright (c) 2000 Shin Kinoshita All Rights Reserved.
 5  
  */
 6  
 package com.ozacc.mail.fetch.impl.sk_jp;
 7  
 
 8  
 import java.io.IOException;
 9  
 import java.io.InputStream;
 10  
 import java.io.OutputStream;
 11  
 import javax.activation.DataSource;
 12  
 import javax.mail.MessageAware;
 13  
 import javax.mail.MessageContext;
 14  
 import javax.mail.MessagingException;
 15  
 import javax.mail.Part;
 16  
 import javax.mail.internet.ContentType;
 17  
 import javax.mail.internet.ParseException;
 18  
 
 19  
 /**
 20  
  * Content-Type:¤ÎÉÔŬ¹ç¤òISO-2022-JP¤ËÊäÀµ¤·¤Þ¤¹¡£
 21  
  * »ÈÍÑÊ?Ë¡¤Ï<PRE>
 22  
  * Object o = new DataHandler(
 23  
  *               new CorrectedContentTypeDataSource(part, charset)
 24  
  *            ).getContent();
 25  
  * </PRE><P>¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£</P><P>
 26  
  * ¥¹¥?¥Ã¥É¥»¡¼¥Õ¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¤Î¤ÇÍøÍѼÔ¦¤ÇÇÓ¾À©¸æ¤ò¹Ô¤Ã¤Æ¤¯¤À¤µ¤¤¡£
 27  
  * </P>
 28  
  * @author Shin
 29  
  * @version $Revision: 1.1.2.2 $ $Date: 2004/10/24 10:27:40 $
 30  
  */
 31  
 class CorrectedContentTypeDataSource implements DataSource, MessageAware {
 32  
 
 33  
 	protected DataSource source;
 34  
 
 35  
 	protected String defaultCharset;
 36  
 
 37  
 	protected String forceCharset;
 38  
 
 39  0
 	public CorrectedContentTypeDataSource() {}
 40  
 
 41  0
 	public CorrectedContentTypeDataSource(DataSource dataSource, String defaultCharset) {
 42  0
 		setDataSource(dataSource);
 43  0
 		setDefaultCharset(defaultCharset);
 44  0
 	}
 45  
 
 46  0
 	public CorrectedContentTypeDataSource(Part part, String defaultCharset)
 47  
 																			throws MessagingException {
 48  0
 		setPart(part);
 49  0
 		setDefaultCharset(defaultCharset);
 50  0
 	}
 51  
 
 52  
 	public void setPart(Part part) throws MessagingException {
 53  
 		// getDataHandler() method creates a implicit DataSource.
 54  0
 		setDataSource(part.getDataHandler().getDataSource());
 55  0
 	}
 56  
 
 57  
 	public void setDataSource(DataSource newSource) {
 58  0
 		source = newSource;
 59  0
 	}
 60  
 
 61  
 	public void setDefaultCharset(String defaultCharset) {
 62  0
 		this.defaultCharset = defaultCharset;
 63  0
 	}
 64  
 
 65  
 	/**
 66  
 	 * »ØÄꤵ¤?¤¿Ê¸»ú¥³¡¼¥É¤Ç´û¸¤Îʸ»ú¥³¡¼¥É¤ò¾å½ñ¤­¤·¤Þ¤¹¡£
 67  
 	 * 
 68  
 	 * @param forceCharset ¶¯À©Åª¤ËŬÍѤ¹¤?ʸ»ú¥³¡¼¥É
 69  
 	 * @author Tomohiro Otsuka
 70  
 	 */
 71  
 	public void setForceCharset(String forceCharset) {
 72  0
 		this.forceCharset = forceCharset;
 73  0
 	}
 74  
 
 75  
 	public String getContentType() {
 76  0
 		ContentType contentType = null;
 77  
 		try {
 78  0
 			contentType = new ContentType(source.getContentType());
 79  0
 		} catch (ParseException e) {
 80  0
 			return "text/plain; charset=" + defaultCharset;
 81  
 		}
 82  0
 		String specifiedCharset = contentType.getParameter("charset");
 83  0
 		if (specclass="keyword">ifiedCharset == null) {
 84  
 			// Content-Type:¤¬Â¸ºß¤·¤Ê¤¤¾?¹ç¤Ï"text/plain"¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦¡£
 85  
 			// ËÜÅö¤Ëtext/plain¤À¤Ã¤¿¾?¹ç¤ÏÀµ¤·¤¯¤Ê¤¤»ö¤Ë¤Ê¤?¤¬¡¢
 86  
 			// charset=ISO-2022-JP¤Ë¤¹¤?¾?¹ç¤Ï°?±?ɽ¼¨¾å¤ÏÌäÂê¤Ê¤¤¡£
 87  0
 			contentType.setParameter("charset", defaultCharset);
 88  0
 		} else if (forceCharset != null) {
 89  0
 			contentType.setParameter("charset", forceCharset);
 90  
 		}
 91  0
 		return contentType.toString();
 92  
 	}
 93  
 
 94  
 	public String getName() {
 95  0
 		return source.getName();
 96  
 	}
 97  
 
 98  
 	public InputStream getInputStream() throws IOException {
 99  0
 		return source.getInputStream();
 100  
 	}
 101  
 
 102  
 	public OutputStream getOutputStream() throws IOException {
 103  0
 		return source.getOutputStream();
 104  
 	}
 105  
 
 106  
 	public synchronized MessageContext getMessageContext() {
 107  0
 		if (source instanceof MessageAware) {
 108  0
 			return ((MessageAware)source).getMessageContext();
 109  
 		}
 110  0
 		throw new RuntimeException(source + " isn't MessageAware.");
 111  
 	}
 112  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.