1 | package de.ugoe.cs.swe.exercises.settings;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.IOException;
|
---|
5 | import com.thoughtworks.xstream.XStream;
|
---|
6 | import de.ugoe.cs.swe.exercises.misc.FileUtils;
|
---|
7 |
|
---|
8 | public class Settings {
|
---|
9 | private String svnLocation;
|
---|
10 | private String workingDirectory;
|
---|
11 | private String svnUsername;
|
---|
12 | private String svnPassword;
|
---|
13 | private String mysqlHost;
|
---|
14 | private String mysqlDb;
|
---|
15 | private String mysqlUsername;
|
---|
16 | private String mysqlPassword;
|
---|
17 | private String pdfLatexPath;
|
---|
18 | private String researchGroup;
|
---|
19 | private String researchGroupUrl;
|
---|
20 | private boolean mysqlSSL = false;
|
---|
21 | private static Settings settings;
|
---|
22 |
|
---|
23 | private Settings() {
|
---|
24 | }
|
---|
25 |
|
---|
26 | public static Settings getInstance() {
|
---|
27 | if (settings == null)
|
---|
28 | settings = new Settings();
|
---|
29 |
|
---|
30 | return settings;
|
---|
31 | }
|
---|
32 |
|
---|
33 | public boolean isInitialized() {
|
---|
34 | if (svnLocation == "" || workingDirectory == "" || svnUsername == ""
|
---|
35 | || svnPassword == "" || mysqlHost == "" || mysqlDb == ""
|
---|
36 | || mysqlUsername == "" || mysqlPassword == ""
|
---|
37 | || pdfLatexPath == "") {
|
---|
38 | return false;
|
---|
39 | }
|
---|
40 | return true;
|
---|
41 |
|
---|
42 | }
|
---|
43 |
|
---|
44 | private String nullCheck(String str) {
|
---|
45 | if (str == null)
|
---|
46 | return "";
|
---|
47 | else
|
---|
48 | return str;
|
---|
49 |
|
---|
50 | }
|
---|
51 |
|
---|
52 | public String getSvnLocation() {
|
---|
53 | return nullCheck(svnLocation);
|
---|
54 | }
|
---|
55 |
|
---|
56 | public void setSvnLocation(String svnLocation) {
|
---|
57 | this.svnLocation = svnLocation;
|
---|
58 | }
|
---|
59 |
|
---|
60 | public String getWorkingDirectory() {
|
---|
61 | return nullCheck(workingDirectory);
|
---|
62 | }
|
---|
63 |
|
---|
64 | public void setWorkingDirectory(String workingDirectory) {
|
---|
65 | this.workingDirectory = workingDirectory;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public String getSvnUsername() {
|
---|
69 | return nullCheck(svnUsername);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public void setSvnUsername(String svnUsername) {
|
---|
73 | this.svnUsername = svnUsername;
|
---|
74 | }
|
---|
75 |
|
---|
76 | public String getSvnPassword() {
|
---|
77 | return nullCheck(svnPassword);
|
---|
78 | }
|
---|
79 |
|
---|
80 | public void setSvnPassword(String svnPassword) {
|
---|
81 | this.svnPassword = svnPassword;
|
---|
82 | }
|
---|
83 |
|
---|
84 | public String getMysqlHost() {
|
---|
85 | return nullCheck(mysqlHost);
|
---|
86 | }
|
---|
87 |
|
---|
88 | public void setMysqlHost(String mysqlHost) {
|
---|
89 | this.mysqlHost = mysqlHost;
|
---|
90 | }
|
---|
91 |
|
---|
92 | public String getMysqlDb() {
|
---|
93 | return nullCheck(mysqlDb);
|
---|
94 | }
|
---|
95 |
|
---|
96 | public void setMysqlDb(String mysqlDb) {
|
---|
97 | this.mysqlDb = mysqlDb;
|
---|
98 | }
|
---|
99 |
|
---|
100 | public String getMysqlUsername() {
|
---|
101 | return nullCheck(mysqlUsername);
|
---|
102 | }
|
---|
103 |
|
---|
104 | public void setMysqlUsername(String mysqlUsername) {
|
---|
105 | this.mysqlUsername = mysqlUsername;
|
---|
106 | }
|
---|
107 |
|
---|
108 | public String getMysqlPassword() {
|
---|
109 | return nullCheck(mysqlPassword);
|
---|
110 | }
|
---|
111 |
|
---|
112 | public void setMysqlPassword(String mysqlPassword) {
|
---|
113 | this.mysqlPassword = mysqlPassword;
|
---|
114 | }
|
---|
115 |
|
---|
116 | public String getPdfLatexPath() {
|
---|
117 | return nullCheck(pdfLatexPath);
|
---|
118 | }
|
---|
119 |
|
---|
120 | public void setPdfLatexPath(String pdfLatexPath) {
|
---|
121 | this.pdfLatexPath = pdfLatexPath;
|
---|
122 | }
|
---|
123 |
|
---|
124 | public String getResearchGroup() {
|
---|
125 | return nullCheck(researchGroup);
|
---|
126 | }
|
---|
127 |
|
---|
128 | public void setResearchGroup(String researchGroup) {
|
---|
129 | this.researchGroup = researchGroup;
|
---|
130 | }
|
---|
131 |
|
---|
132 | public String getResearchGroupUrl() {
|
---|
133 | return nullCheck(researchGroupUrl);
|
---|
134 | }
|
---|
135 |
|
---|
136 | public void setResearchGroupUrl(String researchGroupUrl) {
|
---|
137 | this.researchGroupUrl = researchGroupUrl;
|
---|
138 | }
|
---|
139 |
|
---|
140 | public boolean isMysqlSSL() {
|
---|
141 | return mysqlSSL;
|
---|
142 | }
|
---|
143 |
|
---|
144 | public void setMysqlSSL(boolean mysqlSSL) {
|
---|
145 | this.mysqlSSL = mysqlSSL;
|
---|
146 | }
|
---|
147 |
|
---|
148 | public void load() {
|
---|
149 | File file = new File(System.getProperty("user.home")
|
---|
150 | + "/exercises_settings.xml");
|
---|
151 | if (file.exists()) {
|
---|
152 | try {
|
---|
153 | String content = FileUtils.readFileAsString(file.getAbsolutePath());
|
---|
154 | XStream xstream = new XStream();
|
---|
155 | xstream.alias("ExercisesSettings", Settings.class);
|
---|
156 | settings = (Settings) xstream.fromXML(content);
|
---|
157 | } catch (IOException e) {
|
---|
158 | e.printStackTrace();
|
---|
159 | }
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | public void save() {
|
---|
164 | File file = new File(System.getProperty("user.home")
|
---|
165 | + "/exercises_settings.xml");
|
---|
166 |
|
---|
167 | XStream xstream = new XStream();
|
---|
168 | xstream.alias("ExercisesSettings", Settings.class);
|
---|
169 | String xml = xstream.toXML(settings);
|
---|
170 | try {
|
---|
171 | FileUtils.writeStringAsFile(file.getAbsolutePath(), xml);
|
---|
172 | } catch (IOException e) {
|
---|
173 | e.printStackTrace();
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | @Override
|
---|
178 | public String toString() {
|
---|
179 | StringBuilder builder = new StringBuilder();
|
---|
180 | builder.append("Settings [mysqlDb=");
|
---|
181 | builder.append(mysqlDb);
|
---|
182 | builder.append(", mysqlHost=");
|
---|
183 | builder.append(mysqlHost);
|
---|
184 | builder.append(", mysqlPassword=");
|
---|
185 | builder.append(mysqlPassword);
|
---|
186 | builder.append(", mysqlSSL=");
|
---|
187 | builder.append(mysqlSSL);
|
---|
188 | builder.append(", mysqlUsername=");
|
---|
189 | builder.append(mysqlUsername);
|
---|
190 | builder.append(", pdfLatexPath=");
|
---|
191 | builder.append(pdfLatexPath);
|
---|
192 | builder.append(", researchGroup=");
|
---|
193 | builder.append(researchGroup);
|
---|
194 | builder.append(", researchGroupUrl=");
|
---|
195 | builder.append(researchGroupUrl);
|
---|
196 | builder.append(", svnLocation=");
|
---|
197 | builder.append(svnLocation);
|
---|
198 | builder.append(", svnPassword=");
|
---|
199 | builder.append(svnPassword);
|
---|
200 | builder.append(", svnUsername=");
|
---|
201 | builder.append(svnUsername);
|
---|
202 | builder.append(", workingDirectory=");
|
---|
203 | builder.append(workingDirectory);
|
---|
204 | builder.append("]");
|
---|
205 | return builder.toString();
|
---|
206 | }
|
---|
207 |
|
---|
208 |
|
---|
209 |
|
---|
210 | }
|
---|