OSDN Git Service

Support: [ #25090 ] TLS/SSL SMTP server connection suuport. Ph.1
[mdc/BetaProject.git] / src / org / jent / checksmtp / ApplicationProperties.java
1 package org.jent.checksmtp;
2
3 import java.awt.Dimension;
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
8
9 import java.util.Properties;
10
11
12 /**
13  * <P>This class hold application properties.</P>
14  * <P>"$user.home/.checksmtp.properties" was used to stored data file.</P>
15  * <H3>Properties</H3>
16  * <DL>
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
31  * </DL>
32  */
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";
57   
58   private static final String PROPERTIES_FILENAME = ".checksmtp.properties";
59   
60   private static Properties applicationProperties = new Properties();
61   
62   private static String fileName = PROPERTIES_FILENAME;
63   
64   private static boolean isFileLoaded = false; //Exsist configuration file.
65   
66   public static boolean isFileLoaded() {
67     return isFileLoaded;
68   }
69   
70   static {
71     try {
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);
76       isFileLoaded = true;
77       is.close();
78     } catch (IOException e) {
79       System.err.println("No checksmtp.properties in " + fileName);
80     }
81   }
82   
83   private ApplicationProperties() {
84   }
85   
86   /**
87    * Application Properties Save
88    */
89   public static boolean save() {
90     FileOutputStream fos;
91     boolean resultOK = true;
92     
93     try {
94       fos = new FileOutputStream(fileName);
95       applicationProperties.store(fos, "Appliction Properties");
96       fos.close();
97     } catch (IOException e) {
98       resultOK = false;
99       System.err.println(fileName + "was occrred save error.");
100       e.printStackTrace();
101     }
102     return resultOK;
103   }
104   
105   public static String getSmtpServerHost() {
106     return applicationProperties.getProperty(SMTP_SERVER_HOST, "mail");
107   }
108   
109   public static void setSmtpServerHost(String obj) {
110     applicationProperties.setProperty(SMTP_SERVER_HOST, obj);
111   }
112   
113   public static int getSmtpServerPort() {
114     return Integer.parseInt(applicationProperties.getProperty(SMTP_SERVER_PORT, "25"));
115   }
116  
117   public static void setSmtpServerPort(int port) {
118     applicationProperties.setProperty(SMTP_SERVER_PORT, new Integer(port).toString());
119   }
120
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();
124   }
125   
126   public static void setSmtpServerSSL(boolean ssl) {
127     applicationProperties.setProperty(SMTP_SERVER_SSL, Boolean.toString(ssl));
128   }
129   
130   public static int getSmtpPort() {
131     return Integer.parseInt(applicationProperties.getProperty(SMTP_PORT, "8725"));
132   }
133   
134   public static void setSmtpPort(int port) {
135     applicationProperties.setProperty(SMTP_PORT, new Integer(port).toString());
136   }
137
138   public static boolean getSmtpSSL() {
139     return Boolean.valueOf(applicationProperties.getProperty(SMTP_SSL)).booleanValue();
140   }
141
142   public static void setSmtpSSL(boolean ssl) {
143     applicationProperties.setProperty(SMTP_SSL, Boolean.toString(ssl));
144   }
145
146   public static boolean getSmtpEnebleRemoteConnect() {
147     String str = applicationProperties.getProperty(SMTP_ENEBLE_REMOTE_CONNECT);
148     return Boolean.valueOf(str).booleanValue();
149   }
150   
151   public static void setSmtpEnableRemoteConnect(boolean obj) {
152     applicationProperties.setProperty(SMTP_ENEBLE_REMOTE_CONNECT, Boolean.toString(obj));
153   }
154   
155   public static String getLdapProviderURL() {
156     return applicationProperties.getProperty(LDAP_PROVIDER_URL, "ldap://localhost:389");
157   }
158   
159   public static void setLdapProviderURL(String obj) {
160     applicationProperties.setProperty(LDAP_PROVIDER_URL, obj);
161   }
162   
163   public static String getLdapRoot() {
164     return applicationProperties.getProperty(LDAP_ROOT, "C=JP");
165   }
166   
167   public static void setLdapRoot(String obj) {
168     applicationProperties.setProperty(LDAP_ROOT, obj);
169   }
170   
171   public static boolean getLdapIsSjis() {
172     return Boolean.valueOf(applicationProperties.getProperty(LDAP_IS_SJIS)).booleanValue();
173   }
174   
175   public static void setLdapIsSjis(boolean obj) {
176     applicationProperties.setProperty(LDAP_IS_SJIS, Boolean.toString(obj));
177   }
178   
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();
184   }
185   
186   public static void setLdap(boolean obj) {
187     applicationProperties.setProperty(LDAP_PREFIX, Boolean.toString(obj));
188   }
189   
190   public static String getLdapAttributes() {
191     return applicationProperties.getProperty(LDAP_IS_ATTRIBUTES, "cn");
192   }
193   
194   public static void setLdapAttributes(String obj) {
195     applicationProperties.setProperty(LDAP_IS_ATTRIBUTES, obj);
196   }
197   
198   //
199   // Config Dialog
200   //
201   public static Dimension getConfigurationDialogSize() {
202     Dimension resultDimension = new Dimension(getConfigDialogPosW(), getConfigDialogPosH());
203     return resultDimension;
204   }
205   public static int getConfigDialogPosX() {
206     return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_X, "0"));
207   }
208   
209   public static void setConfigDialogPosX(int x) {
210     applicationProperties.setProperty(CONFIG_DIALOG_POS_X, new Integer(x).toString());
211   }
212   
213   public static int getConfigDialogPosY() {
214     return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_Y, "0"));
215   }
216   
217   public static void setConfigDialogPosY(int y) {
218     applicationProperties.setProperty(CONFIG_DIALOG_POS_Y, new Integer(y).toString());
219   }
220   
221   public static int getConfigDialogPosW() {
222     return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_W, "400"));
223   }
224   
225   public static void setConfigDialogPosW(int w) {
226     applicationProperties.setProperty(CONFIG_DIALOG_POS_W, new Integer(w).toString());
227   }
228   
229   public static int getConfigDialogPosH() {
230     return Integer.parseInt(applicationProperties.getProperty(CONFIG_DIALOG_POS_H, "232"));
231   }
232   
233   public static void setConfigDialogPosH(int h) {
234     applicationProperties.setProperty(CONFIG_DIALOG_POS_H, new Integer(h).toString());
235   }
236   
237   //
238   // Confirm Dialog
239   //
240   static Dimension getConfirmDialogSize() {
241     Dimension resultDimension = new Dimension(getConfirmDialogPosW(), getConfirmDialogPosH());
242     return resultDimension;
243   }
244   
245   public static int getConfirmDialogPosX() {
246     return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_X, "0"));
247   }
248   
249   public static void setConfirmDialogPosX(int x) {
250     applicationProperties.setProperty(CONFIRM_DIALOG_POS_X, new Integer(x).toString());
251   }
252   
253   public static int getConfirmDialogPosY() {
254     return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_Y, "0"));
255   }
256   
257   public static void setConfirmDialogPosY(int y) {
258     applicationProperties.setProperty(CONFIRM_DIALOG_POS_Y, new Integer(y).toString());
259   }
260   
261   public static int getConfirmDialogPosW() {
262     return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_W, "400"));
263   }
264   
265   public static void setConfirmDialogPosW(int w) {
266     applicationProperties.setProperty(CONFIRM_DIALOG_POS_W, new Integer(w).toString());
267   }
268   
269   public static int getConfirmDialogPosH() {
270     return Integer.parseInt(applicationProperties.getProperty(CONFIRM_DIALOG_POS_H, "177"));
271   }
272   
273   public static void setConfirmDialogPosH(int h) {
274     applicationProperties.setProperty(CONFIRM_DIALOG_POS_H, new Integer(h).toString());
275   }
276   
277   //CONFIRM_TIMEOUT
278     public static int getConfirmTimeout() {
279     return Integer.parseInt(applicationProperties.getProperty(CONFIRM_TIMEOUT, "0"));
280   }
281   
282   public static void setConfirmTimeout(int sec) {
283     applicationProperties.setProperty(CONFIRM_TIMEOUT, new Integer(sec).toString());
284   }
285 }