OSDN Git Service

c5728ed04034dfdcbee166d62de9d185a0a4be9a
[coroid/inqubus.git] / frontend / src / saccubus / properties / BasicSetting.java
1 /* $Id$ */
2 package saccubus.properties;
3
4 import java.io.File;
5 import java.util.Properties;
6 import saccubus.converter.classic.profile.User;
7
8 /**
9  * 基本設定.
10  * @author yuki
11  */
12 public class BasicSetting {
13
14     private static final String PROP_TEMP_DIR = "TempDir";
15     private static final String PROP_MAILADDR = "MailAddress";
16     private static final String PROP_PASSWORD = "Password";
17     private static final String PROP_USE_PROXY = "UseProxy";
18     private static final String PROP_PROXY = "Proxy";
19     private static final String PROP_PROXY_PORT = "ProxyPort";
20     private final File tempDir;
21     private final User user;
22     private final boolean proxyUse;
23     private final String proxyHost;
24     private final int proxyPort;
25
26     public BasicSetting(File tempDir, String mail, String password, boolean proxyUse, String proxyHost, int proxyPort) {
27         this.tempDir = tempDir;
28         this.user = new User(mail, password);
29         this.proxyUse = proxyUse;
30         this.proxyHost = proxyHost;
31         this.proxyPort = proxyPort;
32     }
33
34     public File getTempDir() {
35         return tempDir;
36     }
37
38     public User getUser() {
39         return user;
40     }
41
42     public String getProxyHost() {
43         return proxyHost;
44     }
45
46     public int getProxyPort() {
47         return proxyPort;
48     }
49
50     public boolean isProxyUse() {
51         return proxyUse;
52     }
53
54     public void save(Properties prop) {
55         prop.setProperty(PROP_TEMP_DIR, getTempDir().getPath());
56         prop.setProperty(PROP_MAILADDR, getUser().getMail());
57         prop.setProperty(PROP_PASSWORD, getUser().getPassword());
58         prop.setProperty(PROP_USE_PROXY, Boolean.toString(isProxyUse()));
59         prop.setProperty(PROP_PROXY, getProxyHost());
60         prop.setProperty(PROP_PROXY_PORT, Integer.toString(getProxyPort()));
61     }
62
63     public static BasicSetting load(Properties prop, String user, String pass) {
64         String tempDir = prop.getProperty(PROP_TEMP_DIR, ".");
65         if (user == null) {
66             user = prop.getProperty(PROP_MAILADDR, "");
67         }
68         if (pass == null) {
69             pass = prop.getProperty(PROP_PASSWORD, "");
70         }
71         boolean proxyUse = Boolean.parseBoolean(prop.getProperty(PROP_USE_PROXY, "false"));
72         String proxyHost = prop.getProperty(PROP_PROXY, "");
73         int proxyPort = Integer.parseInt(prop.getProperty(PROP_PROXY_PORT, "-1"));
74
75         return new BasicSetting(new File(tempDir), user, pass, proxyUse, proxyHost, proxyPort);
76     }
77 }