KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jsmtpd > config > ReadConfig


1 /*
2  *
3  * Jsmtpd, Java SMTP daemon
4  * Copyright (C) 2005 Jean-Francois POUX, jf.poux@laposte.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  */

21 package org.jsmtpd.config;
22
23 import java.io.FileInputStream JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 /**
27  *
28  * Loads the config file<br>
29  * Should be initialised in thread safe environnement<br>
30  * @author Jean-Francois POUX
31  */

32 public class ReadConfig {
33
34     Properties JavaDoc props = new Properties JavaDoc();
35     private static ReadConfig instance = null;
36
37     private ReadConfig() {
38
39     }
40
41     public static ReadConfig getInstance() {
42         if (instance == null)
43             instance = new ReadConfig();
44         return instance;
45     }
46
47     /**
48      *
49      * @param configFile the configuration file path used
50      * @throws ConfigErrorException when it can't load its config file
51      */

52     public void loadConfig(String JavaDoc configFile) throws ConfigErrorException {
53         try {
54             props.load(new FileInputStream JavaDoc(configFile));
55         } catch (Exception JavaDoc e) {
56             throw new ConfigErrorException(e);
57         }
58     }
59
60     /**
61      * @return the version of jsmtpd
62      */

63     public String JavaDoc getVersion() {
64         return (props.getProperty("version", "NA"));
65     }
66
67     /**
68      * @return the tcp port where the listener is bound to
69      */

70     public int getRPort() {
71         return Integer.parseInt(props.getProperty("rPort", "25").trim());
72     }
73
74     /**
75      * @return number of threads to be spawn for handling receiving service
76      */

77     public int getRMaxInstances() {
78         return Integer.parseInt(props.getProperty("rMaxInstances", "10").trim());
79     }
80
81     /**
82      *
83      * @return the temporary path where to store the mails
84      */

85     public String JavaDoc getTempPath() {
86         return props.getProperty("temporaryFolder", "tmp/");
87     }
88
89     /**
90      * @return maximum temporary disk usage in Mo
91      */

92     public int getMaxTemporarySize() {
93         return Integer.parseInt(props.getProperty("maxTemporarySize", "1024").trim());
94     }
95
96     /**
97      *
98      * @return maximum incoming message size in Mo
99      */

100     public int getMaxMessageSize() {
101         return Integer.parseInt(props.getProperty("maxMessageSize", "10").trim());
102     }
103
104     /**
105      *
106      * @return all connections are aborted after this time in seconds
107      */

108     public int getConnectionTimeout() {
109         return Integer.parseInt(props.getProperty("connectionTimeout", "20").trim());
110     }
111
112     /**
113      * @return local domain name, must be FQDN
114      */

115     public String JavaDoc getLocalDomain() {
116         return props.getProperty("localHost", "taldius.ath.cxx").trim();
117     }
118
119     /**
120      * @return number of thread spawn fo delivery service
121      */

122     public int getDMaxInstances() {
123         return Integer.parseInt(props.getProperty("dMaxInstances", "10").trim());
124     }
125
126     /**
127      *
128      * @return true if in safe mode, false otherwise
129      */

130     public boolean getSafeMode() {
131         if (props.getProperty("safeMode", "on").trim().equals("on"))
132             return true;
133         return false;
134     }
135
136     /**
137      *
138      * @return path to store any mails in safe mode
139      */

140     public String JavaDoc getSafeModePath() {
141         return props.getProperty("safeModeFolder", "safeModeFolder/");
142     }
143     /**
144      * @return number of retries before a mail is lost
145      */

146     public int getMaxRetries() {
147         return Integer.parseInt(props.getProperty("dNumRetry", "48").trim());
148     }
149     /**
150      * @return delay between retries in minutes
151      */

152     public int getDelayRetry() {
153         return Integer.parseInt(props.getProperty("dDelayRetry", "30").trim());
154     }
155     
156     public String JavaDoc getSyslog() {
157         return props.getProperty("syslogServer", "");
158     }
159     public int getMaxRcpt () {
160         return Integer.parseInt(props.getProperty("maxRcpt","100"));
161     }
162 }
Popular Tags