| 1 |
package org.jent.checksmtp; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.io.FileInputStream; |
| 5 |
import java.io.FileNotFoundException; |
| 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> -.enableRemoteConnect <DD>Permit connect from remote host. (Default:false) |
| 19 |
* <DT> -.serverHost <DD>STMP Server host name. (Default:mail) |
| 20 |
* <DT> -.serverPort <DD>STMP Server port. (Default:25) |
| 21 |
* <DT> -.ladp <DD>If "true" use LDAP search. (Default:false) |
| 22 |
* <DT> -.ldap.providerUrl <DD>LDAP Provider URL (Default:ldap://localhost:389 |
| 23 |
* <DT> -.ldap.baseDn <DD>LDAP Search root (Default:C=JP) |
| 24 |
* <DT> -.ldap.isSjis<DD>Addhoc patch: When LDAP Server use SJIS, this propertiy set "true" (Default:false) |
| 25 |
* <DT> -.ldap.attribues<DD>LDAP Search attribues separate by space (Defaut:cn) |
| 26 |
* </DL> |
| 27 |
*/ |
| 28 |
public class ApplicationProperties |
| 29 |
{ |
| 30 |
private static final String PREFIX = "org.jent.checksmtp"; |
| 31 |
private static final String SMTP_PORT = PREFIX + ".port"; |
| 32 |
private static final String SMTP_ENEBLE_REMOTE_CONNECT = PREFIX + ".enableRemoteConnect"; |
| 33 |
private static final String SMTP_SERVER_HOST = PREFIX + ".serverHost"; |
| 34 |
private static final String SMTP_SERVER_PORT = PREFIX + ".serverPort"; |
| 35 |
private static final String LDAP_PREFIX = PREFIX + ".ldap"; |
| 36 |
private static final String LDAP_PROVIDER_URL = LDAP_PREFIX + ".providerUrl"; |
| 37 |
private static final String LDAP_ROOT = LDAP_PREFIX + ".baseDn"; |
| 38 |
private static final String LDAP_IS_SJIS = LDAP_PREFIX + ".isSjis"; |
| 39 |
private static final String LDAP_IS_ATTRIBUTES = LDAP_PREFIX + ".attributes"; |
| 40 |
|
| 41 |
private static final String PROPERTIES_FILENAME = ".checksmtp.properties"; |
| 42 |
|
| 43 |
private static Properties applicationProperties = new Properties(); |
| 44 |
|
| 45 |
private static String fileName = PROPERTIES_FILENAME; |
| 46 |
|
| 47 |
static { |
| 48 |
try |
| 49 |
{ |
| 50 |
//InputStream is = ApplicationProperties.class.getClassLoader().getResourceAsStream("checksmtp.properties"); |
| 51 |
fileName = System.getProperty("user.home") + File.separator + PROPERTIES_FILENAME; |
| 52 |
FileInputStream is = new FileInputStream(fileName); |
| 53 |
applicationProperties.load(is); |
| 54 |
is.close(); |
| 55 |
} |
| 56 |
catch (IOException e) |
| 57 |
{ |
| 58 |
System.err.println("No checksmtp.properties in " + fileName); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
private ApplicationProperties() |
| 63 |
{ |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Application Properties Save |
| 68 |
*/ |
| 69 |
public static void save() |
| 70 |
{ |
| 71 |
FileOutputStream fos; |
| 72 |
try |
| 73 |
{ |
| 74 |
fos = new FileOutputStream(fileName); |
| 75 |
applicationProperties.store(fos, "Appliction Properties"); |
| 76 |
fos.close(); |
| 77 |
} |
| 78 |
catch (IOException e) |
| 79 |
{ |
| 80 |
System.err.println(fileName + "was occrred save error."); |
| 81 |
e.printStackTrace(); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public static String getSmtpServerHost() |
| 86 |
{ |
| 87 |
return applicationProperties.getProperty(SMTP_SERVER_HOST, "mail"); |
| 88 |
} |
| 89 |
|
| 90 |
public static void setSmtpServerHost(String obj) |
| 91 |
{ |
| 92 |
applicationProperties.setProperty(SMTP_SERVER_HOST, obj); |
| 93 |
} |
| 94 |
|
| 95 |
public static int getSmtpServerPort() |
| 96 |
{ |
| 97 |
return Integer.parseInt(applicationProperties.getProperty(SMTP_SERVER_PORT, "25")); |
| 98 |
} |
| 99 |
|
| 100 |
public static void setSmtpServerPort(int port) |
| 101 |
{ |
| 102 |
applicationProperties.setProperty(SMTP_SERVER_PORT, new Integer(port).toString()); |
| 103 |
} |
| 104 |
|
| 105 |
public static int getSmtpPort() |
| 106 |
{ |
| 107 |
return Integer.parseInt(applicationProperties.getProperty(SMTP_PORT, "8725")); |
| 108 |
} |
| 109 |
|
| 110 |
public static void setSmtpPort(int port) |
| 111 |
{ |
| 112 |
applicationProperties.setProperty(SMTP_PORT, new Integer(port).toString()); |
| 113 |
} |
| 114 |
|
| 115 |
public static boolean getSmtpEnebleRemoteConnect() |
| 116 |
{ |
| 117 |
String str = applicationProperties.getProperty(SMTP_ENEBLE_REMOTE_CONNECT); |
| 118 |
return new Boolean(str).booleanValue(); |
| 119 |
} |
| 120 |
|
| 121 |
public static void setSmtpEnableRemoteConnect(boolean obj) |
| 122 |
{ |
| 123 |
applicationProperties.setProperty(SMTP_ENEBLE_REMOTE_CONNECT, Boolean.toString(obj)); |
| 124 |
} |
| 125 |
|
| 126 |
public static String getLdapProviderURL() |
| 127 |
{ |
| 128 |
return applicationProperties.getProperty(LDAP_PROVIDER_URL, "ldap://localhost:389"); |
| 129 |
} |
| 130 |
|
| 131 |
public static void setLdapProviderURL(String obj) |
| 132 |
{ |
| 133 |
applicationProperties.setProperty(LDAP_PROVIDER_URL, obj); |
| 134 |
} |
| 135 |
|
| 136 |
public static String getLdapRoot() |
| 137 |
{ |
| 138 |
return applicationProperties.getProperty(LDAP_ROOT, "C=JP"); |
| 139 |
} |
| 140 |
|
| 141 |
public static void setLdapRoot(String obj) |
| 142 |
{ |
| 143 |
applicationProperties.setProperty(LDAP_ROOT, obj); |
| 144 |
} |
| 145 |
|
| 146 |
public static boolean getLdapIsSjis() |
| 147 |
{ |
| 148 |
return new Boolean(applicationProperties.getProperty(LDAP_IS_SJIS)).booleanValue(); |
| 149 |
} |
| 150 |
|
| 151 |
public static void setLdapRoot(boolean obj) |
| 152 |
{ |
| 153 |
applicationProperties.setProperty(LDAP_IS_SJIS, Boolean.toString(obj)); |
| 154 |
} |
| 155 |
|
| 156 |
public static boolean getLdap() |
| 157 |
{ |
| 158 |
String str = applicationProperties.getProperty(LDAP_PREFIX); |
| 159 |
Boolean flg = new Boolean(str); |
| 160 |
return flg.booleanValue(); |
| 161 |
} |
| 162 |
|
| 163 |
public static void setLdap(boolean obj) |
| 164 |
{ |
| 165 |
applicationProperties.setProperty(LDAP_PREFIX, Boolean.toString(obj)); |
| 166 |
} |
| 167 |
|
| 168 |
public static String getLdapAttributes() |
| 169 |
{ |
| 170 |
return applicationProperties.getProperty(LDAP_IS_ATTRIBUTES, "cn"); |
| 171 |
} |
| 172 |
|
| 173 |
public static void setLdapAttributes(String obj) |
| 174 |
{ |
| 175 |
applicationProperties.setProperty(LDAP_IS_ATTRIBUTES, obj); |
| 176 |
} |
| 177 |
|
| 178 |
} |