Coverage report

  %line %branch
com.ozacc.mail.impl.XMLMailBuilderImpl
60% 
83% 

 1  
 package com.ozacc.mail.impl;
 2  
 
 3  
 import java.io.File;
 4  
 import java.io.IOException;
 5  
 
 6  
 import javax.xml.parsers.FactoryConfigurationError;
 7  
 
 8  
 import org.apache.commons.logging.Log;
 9  
 import org.apache.commons.logging.LogFactory;
 10  
 import org.w3c.dom.Document;
 11  
 import org.w3c.dom.Element;
 12  
 import org.xml.sax.SAXException;
 13  
 
 14  
 import com.ozacc.mail.Mail;
 15  
 import com.ozacc.mail.MailBuildException;
 16  
 import com.ozacc.mail.MultipleMailBuilder;
 17  
 
 18  
 /**
 19  
  * ¥á¡¼¥?¥Ç¡¼¥¿¤ÎXML¥Õ¥¡¥¤¥?¤«¤éMail¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤¹¤?¥¯¥é¥¹¡£
 20  
  * <p>
 21  
  * ¥½¡¼¥¹XML¤òÆÉ¤ß¹?¤àºÝ¤Ë¡¢DTD¥Ð¥?¥Ç¡¼¥·¥ç¥ó¤¬¼Â¹Ô¤µ¤?¤Þ¤¹¤Î¤ÇÂÅÅö¤ÊXML¥Ç¡¼¥¿(Valid XML Document)¤Ç¤Ê¤±¤?¤Ð¤¤¤±¤Þ¤»¤ó¡£
 22  
  * ¥á¡¼¥?¥Ç¡¼¥¿XML¤ÎDTD¤Ï¡¢<a href="http://www.ozacc.com/library/dtd/ozacc-mail.dtd">http://www.ozacc.com/library/dtd/ozacc-mail.dtd</a>¤ò»²¾È¡£
 23  
  * 
 24  
  * @since 1.0.1
 25  
  * @author Tomohiro Otsuka
 26  
  * @version $Id: XMLMailBuilderImpl.java,v 1.5.2.1 2005/01/21 22:16:31 otsuka Exp $
 27  
  */
 28  5
 public class XMLMailBuilderImpl extends AbstractXMLMailBuilder implements MultipleMailBuilder {
 29  
 
 30  5
 	private static Log log = LogFactory.getLog(XMLMailBuilderImpl.class);
 31  
 
 32  
 	/**
 33  
 	 * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
 34  
 	 */
 35  
 	public XMLMailBuilderImpl() {
 36  30
 		super();
 37  30
 	}
 38  
 
 39  
 	/**
 40  
 	 * @see com.ozacc.mail.MailBuilder#buildMail(java.lang.String)
 41  
 	 */
 42  
 	public Mail buildMail(String classPath) throws MailBuildException {
 43  9
 		Document doc = retrieveDocument(classPath);
 44  9
 		return buildMail(doc.getDocumentElement());
 45  
 	}
 46  
 
 47  
 	/**
 48  
 	 * @see com.ozacc.mail.MailBuilder#buildMail(java.io.File)
 49  
 	 */
 50  
 	public Mail buildMail(File file) throws MailBuildException {
 51  20
 		Document doc = retrieveDocument(file);
 52  20
 		return buildMail(doc.getDocumentElement());
 53  
 	}
 54  
 
 55  
 	/**
 56  
 	 * @param classPath
 57  
 	 * @return 
 58  
 	 * @throws MailBuildException
 59  
 	 */
 60  
 	private Document retrieveDocument(String classPath) throws MailBuildException {
 61  
 		try {
 62  9
 			return getDocumentFromClassPath(classPath);
 63  0
 		} catch (SAXException e) {
 64  0
 			throw new MailBuildException("XML¤Î¥Ñ¡¼¥¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£" + e.getMessage(), e);
 65  0
 		} catch (IOException e) {
 66  0
 			throw new MailBuildException("XML¥Õ¥¡¥¤¥?¤ÎÆÉ¤ß¹?¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£", e);
 67  
 		}
 68  
 	}
 69  
 
 70  
 	/**
 71  
 	 * @param file
 72  
 	 * @return 
 73  
 	 * @throws MailBuildException
 74  
 	 */
 75  
 	private Document retrieveDocument(File file) throws MailBuildException {
 76  
 		try {
 77  23
 			return getDocumentFromFile(file);
 78  0
 		} catch (SAXException e) {
 79  0
 			throw new MailBuildException("XML¤Î¥Ñ¡¼¥¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£" + e.getMessage(), e);
 80  0
 		} catch (IOException e) {
 81  0
 			throw new MailBuildException("XML¥Õ¥¡¥¤¥?¤ÎÆÉ¤ß¹?¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£", e);
 82  
 		}
 83  
 	}
 84  
 
 85  
 	/**
 86  
 	 * »ØÄꤵ¤?¤¿XML¤ÎmailÍ×ÁǤ«¤éMail¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤·¤Þ¤¹¡£
 87  
 	 * 
 88  
 	 * @param root ¥á¡¼¥?¥Ç¡¼¥¿¤ÎmailÍ×ÁÇ
 89  
 	 * @return À¸À®¤µ¤?¤¿Mail¥¤¥ó¥¹¥¿¥ó¥¹
 90  
 	 */
 91  
 	protected Mail buildMail(Element root) {
 92  36
 		Mail mail = new Mail();
 93  36
 		setReturnPath(root, mail);
 94  36
 		setFrom(root, mail);
 95  36
 		setRecipients(root, mail);
 96  36
 		setReplyTo(root, mail);
 97  36
 		setSubject(root, mail);
 98  36
 		setText(root, mail);
 99  36
 		setHtml(root, mail);
 100  36
 		return mail;
 101  
 	}
 102  
 
 103  
 	/**
 104  
 	 * @see com.ozacc.mail.MultipleMailBuilder#buildMail(java.lang.String, java.lang.String)
 105  
 	 */
 106  
 	public Mail buildMail(String classPath, String mailId) throws MailBuildException {
 107  0
 		if (mailId == null || "".equals(mailId)) {
 108  0
 			throw new IllegalArgumentException("¥á¡¼¥?ID¤¬»ØÄꤵ¤?¤Æ¤¤¤Þ¤»¤ó¡£");
 109  
 		}
 110  0
 		Document doc = retrieveDocument(classPath);
 111  0
 		if (Mail.DOCTYPE_PUBLIC.equals(doc.getDoctype().getPublicId())) {
 112  0
 			throw new MailBuildException("»ØÄꤵ¤?¤¿¥¯¥é¥¹¥Ñ¥¹¤ÎXML¤Ï¥·¥ó¥°¥?¥á¡¼¥?¥Æ¥ó¥×¥?¡¼¥È¤Ç¤¹¡£[classPath='" + classPath
 113  0
 					+ "']");
 114  
 		}
 115  0
 		Element mailElem = doc.getElementById(mailId);
 116  0
 		return buildMail(mailElem);
 117  
 	}
 118  
 
 119  
 	/**
 120  
 	 * @see com.ozacc.mail.MultipleMailBuilder#buildMail(java.io.File, java.lang.String)
 121  
 	 */
 122  
 	public Mail buildMail(File file, String mailId) throws MailBuildException {
 123  3
 		if (mailId == null || "".equals(mailId)) {
 124  0
 			throw new IllegalArgumentException("¥á¡¼¥?ID¤¬»ØÄꤵ¤?¤Æ¤¤¤Þ¤»¤ó¡£");
 125  
 		}
 126  3
 		Document doc = retrieveDocument(file);
 127  3
 		if (Mail.DOCTYPE_PUBLIC.equals(doc.getDoctype().getPublicId())) {
 128  0
 			throw new MailBuildException("»ØÄꤵ¤?¤¿¥Õ¥¡¥¤¥?¤ÎXML¤Ï¥·¥ó¥°¥?¥á¡¼¥?¥Æ¥ó¥×¥?¡¼¥È¤Ç¤¹¡£[filePath='"
 129  0
 					+ file.getAbsolutePath() + "']");
 130  
 		}
 131  3
 		return buildMail(doc, mailId);
 132  
 	}
 133  
 
 134  
 	/**
 135  
 	 * ¥Þ¥?¥Á¥×¥?¥á¡¼¥?¥Æ¥ó¥×¥?¡¼¥È¤ÎXML¥É¥­¥å¥á¥ó¥È¾å¤Î»ØÄꤵ¤?¤¿ID¤¬¼¨¤¹¥á¡¼¥?¥Æ¥ó¥×¥?¡¼¥È¤«¤éMail¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤·¤ÆÊÖ¤·¤Þ¤¹¡£
 136  
 	 * 
 137  
 	 * @param doc
 138  
 	 * @param mailId
 139  
 	 * @return À¸À®¤µ¤?¤¿Mail¥¤¥ó¥¹¥¿¥ó¥¹
 140  
 	 * @throws FactoryConfigurationError 
 141  
 	 */
 142  
 	protected Mail buildMail(Document doc, String mailId) throws FactoryConfigurationError {
 143  3
 		Element mailElem = doc.getElementById(mailId);
 144  3
 		if (mailElem == null) {
 145  1
 			throw new MailBuildException("»ØÄꤵ¤?¤¿ID[" + mailId + "]¤Î¥á¡¼¥?¥Ç¡¼¥¿¤Ï¸«¤Ä¤«¤ê¤Þ¤»¤ó¤Ç¤·¤¿¡£");
 146  
 		}
 147  2
 		log.debug(mailElem);
 148  2
 		return buildMail(mailElem);
 149  
 	}
 150  
 
 151  
 }

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