Changeset 1952
- Timestamp:
- 12/03/07 11:54:52 (12 months ago)
- Files:
-
- 1 modified
-
trunk/components/common/src/prefs.java (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/components/common/src/prefs.java
r1951 r1952 15 15 import java.lang.reflect.InvocationTargetException; 16 16 import java.lang.reflect.Method; 17 import java.util.Arrays; 18 import java.util.HashSet; 17 19 import java.util.Properties; 20 import java.util.Set; 18 21 import java.util.prefs.BackingStoreException; 19 22 import java.util.prefs.Preferences; … … 73 76 * Cache the root node at start up 74 77 */ 75 private finalstatic Preferences prefs = Preferences.userRoot().node(ROOT);78 private static Preferences prefs = Preferences.userRoot().node(ROOT); 76 79 77 80 /** … … 128 131 " load_nowarn [FILE...] : read current profile from a file or standard in", 129 132 " set KEY=VALUE : set value on current profile", 133 " sys COMMANDS : applies commands as above to system preferences", 130 134 " ", 131 135 "Note: profiles are created on demand. Later properties override earlier ones." }; … … 152 156 public static String[] print(String[] args) { 153 157 for (String string : args) { 154 System.out.println(string); 158 if (string != null) { 159 System.out.println(string); 160 } 155 161 } 156 162 return new String[] {}; … … 162 168 public static String[] printErr(String[] args) { 163 169 for (String string : args) { 164 System.err.println(string); 170 if (string != null) { 171 System.err.println(string); 172 } 165 173 } 166 174 return args; … … 216 224 } 217 225 226 } 227 228 /** 229 * Replaces the user {@link Preferences} instance with the system 230 * {@link Preferences} and continues dispatching. 231 */ 232 public static String[] sys(String[] args) throws Throwable { 233 prefs = Preferences.systemRoot().node(ROOT); 234 return dispatch(args); 218 235 } 219 236 … … 288 305 args = notNull(args); 289 306 307 String[] keys = _node().keys(); 290 308 if (args.length == 0) { 291 String[] keys = _node().keys();292 309 if (keys.length == 0) { 293 310 return args; 294 } 295 return get(keys); 296 } 297 311 } else if (keys.length == 1) { 312 return get(args(keys[0], "UNKNOWNKEYJUSTTOFORCELENGTH2")); 313 } else { 314 return get(keys); 315 } 316 } else if (args.length == 1) { 317 String key = args[0] == null ? "" : args[0]; 318 String value = _node().get(key, ""); 319 return args(value); 320 } 321 322 Set<String> availableKeys = new HashSet<String>(Arrays.asList(_node() 323 .keys())); 298 324 String[] rv = new String[args.length]; 299 325 for (int i = 0; i < rv.length; i++) { 300 326 String key = args[i] == null ? "" : args[i]; 301 String value = _node().get(key, ""); 302 if (rv.length == 1) { 303 rv[i] = value; 304 } else { 327 if (availableKeys.contains(key)) { 328 String value = _node().get(key, ""); 305 329 rv[i] = key + "=" + value; 306 330 } 307 308 331 } 309 332 return rv; 333 310 334 } 311 335
