4 * Created on 2000/08/09, 14:07
\r
7 package jp.co.areaweb.tools.mail;
\r
10 import java.io.FileInputStream;
\r
11 import java.io.IOException;
\r
12 import javax.xml.parsers.*; // jaxp.jar
\r
13 import org.w3c.dom.*; // jaxp.jar
\r
16 * JavaMailを使用する機能拡張版
\r
17 * @author techno-infinitus Co,Ltd. Yuu Hayashi.
\r
20 public class YuuMailXml extends SendMail {
\r
22 * Creates new YuuMail
\r
23 * @param siteData DATA
\r
25 public YuuMailXml(SiteData siteData) {
\r
28 public YuuMailXml(String propertyFile) {
\r
29 super(propertyFile);
\r
32 public void setXmlData(Node sendMailTag) throws java.io.FileNotFoundException {
\r
33 NodeList nl = sendMailTag.getChildNodes();
\r
34 for (int i=0; i < nl.getLength(); i++) {
\r
35 Node mailDataTag = nl.item(i);
\r
36 if (mailDataTag.getNodeType() == Node.ELEMENT_NODE) {
\r
37 String nodeName = mailDataTag.getNodeName();
\r
38 if (nodeName.equals("to")) {
\r
39 this.setTo(mailDataTag.getFirstChild().getNodeValue());
\r
41 else if (nodeName.equals("cc")) {
\r
42 Node ccNode = mailDataTag.getFirstChild();
\r
43 if (ccNode != null) {
\r
44 this.setCc(ccNode.getNodeValue());
\r
47 else if (nodeName.equals("bcc")) {
\r
48 Node bccNode = mailDataTag.getFirstChild();
\r
49 if (bccNode != null) {
\r
50 this.setBcc(bccNode.getNodeValue());
\r
53 else if (nodeName.equals("from")) {
\r
54 Node fromNode = mailDataTag.getFirstChild();
\r
55 if (fromNode != null) {
\r
56 this.setFrom(fromNode.getNodeValue());
\r
59 else if (nodeName.equals("subject")) {
\r
60 this.setSubject(mailDataTag.getFirstChild().getNodeValue());
\r
62 else if (nodeName.equals("content")) {
\r
63 this.setContent(mailDataTag.getFirstChild().getNodeValue());
\r
65 else if (nodeName.equals("attachment")) {
\r
66 Node attachNode = mailDataTag.getFirstChild();
\r
67 File attachFile = new File(attachNode.getNodeValue());
\r
68 Attr attrNode = (Attr)mailDataTag.getAttributes().getNamedItem("file");
\r
69 if (attrNode != null) {
\r
70 this.setAttachment(attachFile, attrNode.getValue());
\r
73 this.setAttachment(attachFile);
\r
80 public void setXmlData(String inputFile) throws IOException {
\r
82 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
\r
83 DocumentBuilder builder = factory.newDocumentBuilder();
\r
84 Node rootNode = builder.parse(new FileInputStream(inputFile));
\r
85 NodeList rootNodeList = rootNode.getChildNodes();
\r
86 for (int j=0; j < rootNodeList.getLength(); j++) {
\r
87 setXmlData(rootNodeList.item(j));
\r
90 catch (javax.xml.parsers.ParserConfigurationException pce) {
\r
91 pce.printStackTrace();
\r
92 throw new IOException("javax.xml.parsers.ParserConfigurationException");
\r
94 catch (org.xml.sax.SAXException saxe) {
\r
95 saxe.printStackTrace();
\r
96 throw new IOException("org.xml.sax.SAXException");
\r
101 * "jp.co.areaweb.tools.common.YuuMailXml <property.xml> <sendMail.xml>"
\r
102 * @param args parameter
\r
104 public static void main(java.lang.String[] args) {
\r
106 String propertyFile;
\r
108 if (args.length < 2) {
\r
109 inputfile = "sendMail.xml";
\r
110 if (args.length < 1) {
\r
111 propertyFile = "property.xml";
\r
114 propertyFile = args[0];
\r
118 inputfile = args[1];
\r
119 propertyFile = args[0];
\r
123 YuuMailXml mail = new YuuMailXml(new SiteDataXml(propertyFile));
\r
124 mail.setXmlData(inputfile);
\r
127 catch (Exception e) {
\r
128 e.printStackTrace();
\r