java with part. login-triggered startCalculation
2 * Created on Feb 22, 2005
4 * @author Alan Krempler
7 package isac.util.users;
9 import java.io.FileInputStream;
10 import java.io.FileNotFoundException;
11 import java.io.FileOutputStream;
12 import java.io.IOException;
13 import java.util.Enumeration;
14 import java.util.HashMap;
16 import java.util.Properties;
19 * Class for storing/retrieving user settings, i.e. settings which can be set
20 * manually by the user as opposed to the
21 * {@link isac.util.usersettings.UserModel#}, which is an abstraction of the
22 * system's expeience with a user and canot be altered manually. As there is no
23 * fixed set of user settings, you can regard this class as a simple storage
24 * backend for key/value pairs.
26 * @author Alan Krempler
29 public class UserSettings extends Properties implements IUserSettings {
31 private HashMap storage_;
37 public static Map valstr_valint_;
40 * connect the String-representation of a UserSettings-value
41 * with the respective Integer-representation
43 * @see isac.uti.users.IUserSettings
45 private HashMap createValstrValint() {
46 HashMap m = new HashMap();
47 m.put("DUMMY", new Integer(IUserSettings.DUMMY));
48 m.put("RESULT_WITH_LONG_CALCULATION", new Integer(
49 IUserSettings.RESULT_WITH_LONG_CALCULATION));
50 m.put("FORMULAE_ONLY", new Integer(IUserSettings.FORMULAE_ONLY));
51 m.put("SKIP_SPECIFY_START_SOLVE", new Integer(
52 IUserSettings.SKIP_SPECIFY_START_SOLVE));
53 m.put("FORMULA_TACTIC_FORMULA_", new Integer(
54 IUserSettings.FORMULA_TACTIC_FORMULA_));
55 m.put("POP_CALCHEAD_WITH_DESCRIPTIONS", new Integer(
56 IUserSettings.POP_CALCHEAD_WITH_DESCRIPTIONS));
57 //valstr_valint_.put("",
58 // new Integer(IUserSettings.));
62 public UserSettings(String userpath, String username) {
66 //load Properties (keystr, valstr) temporarily
67 Properties keystr_valstr = new Properties();
68 String filename = userpath_ + username + "_settings.txt";
70 FileInputStream propInFile = new FileInputStream(filename);
71 keystr_valstr.load(propInFile);
72 keystr_valstr.list(System.out);
73 } catch (FileNotFoundException e) {
74 System.err.println("Can?t find " + filename);
75 } catch (IOException e) {
76 System.err.println("I/O failed.");
79 //create HashMap (valstr, valint) temporarily
80 HashMap valstr_valint = new HashMap();
81 valstr_valint = this.createValstrValint();
83 //create HashMap (keystr, \\valstr\\ valint) and store it
84 storage_ = new HashMap();
85 Enumeration keystrs = keystr_valstr.propertyNames();//WN050311 how
90 while (keystrs.hasMoreElements()) {
91 keystr = (String) keystrs.nextElement();
92 valstr = keystr_valstr.getProperty(keystr);
93 valint = valstr_valint.get(valstr);
94 storage_.put(keystr, valint);
101 * @return The string value associated with the key parameter; null, if
102 * nothing is stored under this key
104 public int getValue(String key) {
105 return ((Integer) storage_.get(key)).intValue();
110 * The key under which "value" is to be stored. Existing data
111 * unde the same key will be replaced.
113 * The value to be stored under "key"
114 * @return true in case of success, false in case of error, for example if
115 * trying to replace stored values without proper permissions
117 public boolean setValue(String key, int value) {
118 //TODO.WN050311 storage_.put(key, value);
122 //WN050311 just for creation of the first file
123 //beware of the fix path !
124 public static void main(String[] args) {
125 UserSettings s = new UserSettings("isac/xmldata/users/", "x");
126 s.setProperty("start_worksheet", "SKIP_SPECIFY_START_SOLVE");
127 s.setProperty("enter_specify", "SKIP_SPECIFY_START_SOLVE");
128 s.setProperty("next_button", "FORMULAE_ONLY");
130 String filename = "isac/xmldata/users/x_settings.txt";
132 FileOutputStream propOutFile = new FileOutputStream(filename);
133 s.store(propOutFile, "static dialog data of user 'x'");
135 } catch (IOException e) {
136 System.err.println("I/O failed.");