OSDN Git Service

ver 2.23 init
[hayashilib/hayashi.git] / src / jp / co / areaweb / tools / mail / SiteDataXml.java
1 package jp.co.areaweb.tools.mail;
2
3 import javax.xml.parsers.*;         // jaxp.jar
4 import org.w3c.dom.*;               // jaxp.jar
5 import java.io.FileInputStream;
6
7 public class SiteDataXml extends SiteData {
8     public SiteDataXml(String propertyFile) throws javax.xml.parsers.ParserConfigurationException,org.xml.sax.SAXException {
9         super(propertyFile);
10         try {
11             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
12             DocumentBuilder builder = factory.newDocumentBuilder();
13             Node rootNode = builder.parse(new FileInputStream(propertyFile));
14             NodeList rootNodeList = rootNode.getChildNodes();
15             for (int j=0; j < rootNodeList.getLength(); j++) {
16                 Node propertyTag = rootNodeList.item(j);
17                 NodeList nl = propertyTag.getChildNodes();
18                 for (int i=0; i < nl.getLength(); i++) {
19                     Node mailDataTag = nl.item(i);
20                     if (mailDataTag.getNodeType() == Node.ELEMENT_NODE) {
21                         String nodeName = mailDataTag.getNodeName();
22                         if (nodeName.equals("smtp")) {
23                             this.MAIL_SMTP = paseValue(mailDataTag);
24                         }
25                         else if (nodeName.equals("from")) {
26                             this.MAIL_FROM = paseValue(mailDataTag);
27                         }
28                         else if (nodeName.equals("to")) {
29                             this.MAIL_TO = paseValue(mailDataTag);
30                         }
31                         else if (nodeName.equals("cc")) {
32                             this.MAIL_CC = paseValue(mailDataTag);
33                         }
34                         else if (nodeName.equals("bcc")) {
35                             this.MAIL_BCC = paseValue(mailDataTag);
36                         }
37                     }
38                 }
39             }
40         }
41         catch(Exception e) {
42             // Print out the error message
43             System.out.println(e);
44         }
45     }
46     
47     protected static String paseValue(Node tag) {
48         Node node = tag.getFirstChild();
49         if (node != null) {
50             return node.getNodeValue();
51         }
52         else {
53             return "";
54         }
55     }
56 }