1 package org.jent.checksmtp;
3 import java.awt.Dimension;
5 import java.io.FileInputStream;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
9 import java.util.Properties;
13 * <P>This class hold application properties.</P>
14 * <P>"$user.home/.checksmtp.properties" was used to stored data file.</P>
17 * <DT> -.port <DD>Service port number. (Default:8725)
18 * <DT> -.ssl <DD>Service port use SSL. (Default:false) //Not use yet.
19 * <DT> -.enableRemoteConnect <DD>Permit connect from remote host. (Default:false)
20 * <DT> -.serverHost <DD>STMP Server host name. (Default:mail)
21 * <DT> -.serverPort <DD>STMP Server port. (Default:25)
22 * <DT> -.serverSSL <DD>SMTP Server port use SSL. (Default:false)
23 * <DT> -.confirm.timeout <DD> Confirm auto push OK timeput (Default:0 = forever)
24 * <DT> -.ladp <DD>If "true" use LDAP search. (Default:false)
25 * <DT> -.ldap.providerUrl <DD>LDAP Provider URL (Default:ldap://localhost:389
26 * <DT> -.ldap.baseDn <DD>LDAP Search root (Default:C=JP)
27 * <DT> -.ldap.isSjis<DD>Addhoc patch: When LDAP Server use SJIS, this propertiy set "true" (Default:false)
28 * <DT> -.ldap.attribues<DD>LDAP Search attribues separate by space (Defaut:cn)
29 * <DT> -.configDialog.pos.? <DD> Config Dialog position x,y,w,h
30 * <DT> -.confirmDialog.pos.? <DD> Confirm Dialog postion x,y,w,h
33 public class ApplicationProperties {
34 private static final String PREFIX = "org.jent.checksmtp";
35 private static final String SMTP_PORT = PREFIX + ".port";
36 private static final String SMTP_SSL = PREFIX + ".SSL";
37 private static final String SMTP_ENEBLE_REMOTE_CONNECT = PREFIX + ".enableRemoteConnect";
38 private static final String SMTP_SERVER_HOST = PREFIX + ".serverHost";
39 private static final String SMTP_SERVER_PORT = PREFIX + ".serverPort";
40 private static final String SMTP_SERVER_SSL = PREFIX + ".serverSSL";
41 private static final String CONFIRM_TIMEOUT = PREFIX + ".confirmTimeout";
42 private static final String LDAP_PREFIX = PREFIX + ".ldap";
43 private static final String LDAP_PROVIDER_URL = LDAP_PREFIX + ".providerUrl";
44 private static final String LDAP_ROOT = LDAP_PREFIX + ".baseDn";
45 private static final String LDAP_IS_SJIS = LDAP_PREFIX + ".isSjis";
46 private static final String LDAP_IS_ATTRIBUTES = LDAP_PREFIX + ".attributes";
47 private static final String CONFIG_DIALOG_PREFIX = PREFIX + ".configDialog";
48 private static final String CONFIG_DIALOG_POS_X = CONFIG_DIALOG_PREFIX + ".pos.x";
49 private static final String CONFIG_DIALOG_POS_Y = CONFIG_DIALOG_PREFIX + ".pos.y";
50 private static final String CONFIG_DIALOG_POS_W = CONFIG_DIALOG_PREFIX + ".pos.w";
51 private static final String CONFIG_DIALOG_POS_H = CONFIG_DIALOG_PREFIX + ".pos.h";
52 private static final String CONFIRM_DIALOG_PREFIX = PREFIX + ".confirmDialog";
53 private static final String CONFIRM_DIALOG_POS_X = CONFIRM_DIALOG_PREFIX + ".pos.x";
54 private static final String CONFIRM_DIALOG_POS_Y = CONFIRM_DIALOG_PREFIX + ".pos.y";
55 private static final String CONFIRM_DIALOG_POS_W = CONFIRM_DIALOG_PREFIX + ".pos.w";
56 private static final String CONFIRM_DIALOG_POS_H = CONFIRM_DIALOG_PREFIX + ".pos.h";
58 private static final String PROPERTIES_FILENAME = ".checksmtp.properties";
60 private static Properties applicationProperties = new Properties();
62 private static String fileName = PROPERTIES_FILENAME;
64 private static boolean isFileLoaded = false; //Exsist configuration file.
66 public static boolean isFileLoaded() {
72 //InputStream is = ApplicationProperties.class.getClassLoader().getResourceAsStream("checksmtp.properties");
73 fileName = System.getProperty("user.home") + File.separator + PROPERTIES_FILENAME;
74 FileInputStream is = new FileInputStream(fileName);
75 applicationProperties.load(is);
78 } catch (IOException e) {
79 System.err.println("No checksmtp.properties in " + fileName);
83 private ApplicationProperties() {
87 * Application Properties Save
89 public static boolean save() {
91 boolean resultOK = true;
94 fos = new FileOutputStream(fileName);
95 applicationProperties.store(fos, "Appliction Properties");
97 } catch (IOException e) {
99 System.err.println(fileName + "was occrred save error.");
105 public static String getSmtpServerHost() {
106 return applicationProperties.getProperty(SMTP_SERVER_HOST, "mail");
109 public static void setSmtpServerHost(String obj) {
110 applicationProperties.setProperty(SMTP_SERVER_HOST, obj);
113 public static int getSmtpServerPort() {
114 return Integer.parseInt(applicationProperties.getProperty(SMTP_SERVER_PORT, "25"));
117 public static void setSmtpServerPort(int port) {
118 applicationProperties.setProperty(SMTP_SERVER_PORT, new Integer(port).toString());
121 public static boolean getSmtpServerSSL() {
122 //getProperty(str) default value is null. valueOf(null) retrun FALSE.
123 return Boolean.valueOf(applicationProperties.getProperty(SMTP_SERVER_SSL)).booleanValue();
126 public static void setSmtpServerSSL(boolean ssl) {
127 applicationProperties.setProperty(SMTP_SERVER_SSL, Boolean.toString(ssl));
130 public static int getSmtpPort() {
131 return Integer.parseInt(applicationProperties.getProperty(SMTP_PORT, "8725"));
134 public static void setSmtpPort(int port) {
135 applicationProperties.setProperty(SMTP_PORT, new Integer(port).toString());
138 public static boolean getSmtpSSL() {
139 return Boolean.valueOf(applicationProperties.getProperty(SMTP_SSL)).booleanValue();
142 public static void setSmtpSSL(boolean ssl) {
143 applicationProperties.setProperty(SMTP_SSL, Boolean.toString(ssl));
146 public static boolean getSmtpEnebleRemoteConnect() {
147 String str = applicationProperties.getProperty(SMTP_ENEBLE_REMOTE_CONNECT);
148 return Boolean.valueOf(str).booleanValue();
151 public static void setSmtpEnableRemoteConnect(boolean obj) {
152 applicationProperties.setProperty(SMTP_ENEBLE_REMOTE_CONNECT, Boolean.toString(obj));
155 public static String getLdapProviderURL() {
156 return applicationProperties.getProperty(LDAP_PROVIDER_URL, "ldap://localhost:389");
159 public static void setLdapProviderURL(String obj) {
160 applicationProperties.setProperty(LDAP_PROVIDER_URL, obj);
163 public static String getLdapRoot() {
164 return applicationProperties.getProperty(LDAP_ROOT, "C=JP");
167 public static void setLdapRoot(String obj) {
168 applicationProperties.setProperty(LDAP_ROOT, obj);
171 public static boolean getLdapIsSjis() {
172 return Boolean.valueOf(applicationProperties.getProperty(LDAP_IS_SJIS)).booleanValue();
175 public static void setLdapIsSjis(boolean obj) {
176 applicationProperties.setProperty(LDAP_IS_SJIS, Boolean.toString(obj));
179 public static boolean getLdap() {
180 String str = applicationProperties.getProperty(LDAP_PREFIX);
181 //the value true if the string is ignoring case "true".
182 Boolean flg = Boolean.valueOf(str);
183 return flg.booleanValue();
186 public static void setLdap(boolean obj) {
187 applicationProperties.setProperty(LDAP_PREFIX, Boolean.toString(obj));
190 public static String getLdapAttributes() {
191 return applicationProperties.getProperty(LDAP_IS_ATTRIBUTES, "cn");
194 public static void setLdapAttributes(String obj) {
195 applicationProperties.setProperty(LDAP_IS_ATTRIBUTES, obj);
201 public static Dimension getConfigurationDialogSize() {
202 Dimension resultDimension = new Dimension(getConfigDialogPosW(), getConfigDialogPosH());
203 return resultDimension;
205 public static int getConfigDialogPosX() {
206 return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_X, "0"));
209 public static void setConfigDialogPosX(int x) {
210 applicationProperties.setProperty(CONFIG_DIALOG_POS_X, new Integer(x).toString());
213 public static int getConfigDialogPosY() {
214 return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_Y, "0"));
217 public static void setConfigDialogPosY(int y) {
218 applicationProperties.setProperty(CONFIG_DIALOG_POS_Y, new Integer(y).toString());
221 public static int getConfigDialogPosW() {
222 return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_W, "400"));
225 public static void setConfigDialogPosW(int w) {
226 applicationProperties.setProperty(CONFIG_DIALOG_POS_W, new Integer(w).toString());
229 public static int getConfigDialogPosH() {
230 return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_H, "232"));
233 public static void setConfigDialogPosH(int h) {
234 applicationProperties.setProperty(CONFIG_DIALOG_POS_H, new Integer(h).toString());
240 static Dimension getConfirmDialogSize() {
241 Dimension resultDimension = new Dimension(getConfirmDialogPosW(), getConfirmDialogPosH());
242 return resultDimension;
245 public static int getConfirmDialogPosX() {
246 return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_X, "0"));
249 public static void setConfirmDialogPosX(int x) {
250 applicationProperties.setProperty(CONFIRM_DIALOG_POS_X, new Integer(x).toString());
253 public static int getConfirmDialogPosY() {
254 return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_Y, "0"));
257 public static void setConfirmDialogPosY(int y) {
258 applicationProperties.setProperty(CONFIRM_DIALOG_POS_Y, new Integer(y).toString());
261 public static int getConfirmDialogPosW() {
262 return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_W, "400"));
265 public static void setConfirmDialogPosW(int w) {
266 applicationProperties.setProperty(CONFIRM_DIALOG_POS_W, new Integer(w).toString());
269 public static int getConfirmDialogPosH() {
270 return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_H, "177"));
273 public static void setConfirmDialogPosH(int h) {
274 applicationProperties.setProperty(CONFIRM_DIALOG_POS_H, new Integer(h).toString());
278 public static int getConfirmTimeout() {
279 return Integer.parseInt(applicationProperties.getProperty(CONFIRM_TIMEOUT, "0"));
282 public static void setConfirmTimeout(int sec) {
283 applicationProperties.setProperty(CONFIRM_TIMEOUT, new Integer(sec).toString());