XMLMailBuilderImpl xref

View Javadoc

    1   package com.ozacc.mail.impl;
    2
    3   import java.io.File;
    4   import java.io.IOException;
    5
    6   import org.w3c.dom.Document;
    7   import org.w3c.dom.Element;
    8   import org.xml.sax.SAXException;
    9
    10  import com.ozacc.mail.Mail;
    11  import com.ozacc.mail.MailBuildException;
    12  import com.ozacc.mail.MailBuilder;
    13
    14  /***
    15   * ¥á¡¼¥?¥Ç¡¼¥¿¤ÎXML¥Õ¥¡¥¤¥?¤«¤éMail¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤¹¤?¥¯¥é¥¹¡£
    16   * <p>
    17   * ¥½¡¼¥¹XML¤òÆÉ¤ß¹?¤àºÝ¤Ë¡¢DTD¥Ð¥?¥Ç¡¼¥·¥ç¥ó¤¬¼Â¹Ô¤µ¤?¤Þ¤¹¤Î¤ÇÂÅÅö¤ÊXML¥Ç¡¼¥¿(Valid XML Document)¤Ç¤Ê¤±¤?¤Ð¤¤¤±¤Þ¤»¤ó¡£
    18   * ¥á¡¼¥?¥Ç¡¼¥¿XML¤ÎDTD¤Ï¡¢<a href="http://www.ozacc.com/library/dtd/ozacc-mail.dtd">http://www.ozacc.com/library/dtd/ozacc-mail.dtd</a>¤ò»²¾È¡£
    19   *
    20   * @since 1.0.1
    21   * @author Tomohiro Otsuka
    22   * @version $Id: XMLMailBuilderImpl.java,v 1.5 2004/09/17 23:07:16 otsuka Exp $
    23   */
    24  public class XMLMailBuilderImpl extends AbstractXMLMailBuilder implements MailBuilder {
    25
    26  	/***
    27  	 * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
    28  	 */
    29  	public XMLMailBuilderImpl() {
    30  		super();
    31  	}
    32
    33  	/***
    34  	 * @see com.ozacc.mail.MailBuilder#buildMail(java.lang.String)
    35  	 */
    36  	public Mail buildMail(String classPath) throws MailBuildException {
    37  		Document doc;
    38  		try {
    39  			doc = getDocumentFromClassPath(classPath);
    40  		} catch (SAXException e) {
    41  			throw new MailBuildException("XML¤Î¥Ñ¡¼¥¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£" + e.getMessage(), e);
    42  		} catch (IOException e) {
    43  			throw new MailBuildException("XML¥Õ¥¡¥¤¥?¤ÎÆÉ¤ß¹?¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£", e);
    44  		}
    45
    46  		return buildMail(doc);
    47  	}
    48
    49  	/***
    50  	 * @see com.ozacc.mail.MailBuilder#buildMail(java.io.File)
    51  	 */
    52  	public Mail buildMail(File file) throws MailBuildException {
    53  		Document doc;
    54  		try {
    55  			doc = getDocumentFromFile(file);
    56  		} catch (SAXException e) {
    57  			throw new MailBuildException("XML¤Î¥Ñ¡¼¥¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£" + e.getMessage(), e);
    58  		} catch (IOException e) {
    59  			throw new MailBuildException("XML¥Õ¥¡¥¤¥?¤ÎÆÉ¤ß¹?¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£", e);
    60  		}
    61
    62  		return buildMail(doc);
    63  	}
    64
    65  	/***
    66  	 * DOM Document¤«¤éMail¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤·¤Þ¤¹¡£
    67  	 *
    68  	 * @param doc ¥á¡¼¥?¥Ç¡¼¥¿¤ÎDOM Document
    69  	 * @return À¸À®¤µ¤?¤¿Mail¥¤¥ó¥¹¥¿¥ó¥¹
    70  	 */
    71  	protected Mail buildMail(Document doc) {
    72  		Element root = doc.getDocumentElement();
    73
    74  		Mail mail = new Mail();
    75  		setReturnPath(root, mail);
    76  		setFrom(root, mail);
    77  		setRecipients(root, mail);
    78  		setReplyTo(root, mail);
    79  		setSubject(root, mail);
    80  		setText(root, mail);
    81
    82  		setHtml(root, mail);
    83
    84  		return mail;
    85  	}
    86
    87  }