Revision 2383

tmp/org.txm.core/src/java/org/txm/core/preferences/TXMPreferences.java (revision 2383)
47 47
 * of command scope or alternative scope so the preference will not be saved in the local scope .prefs file if its a default value.
48 48
 * TODO: when we'll use IProject for managing Corporas, the local node should be stored in the ProjectScope instead of in the InstanceScope.
49 49
 * TODO: need to determine if we'll use this class to persistence of TXM results. At this moment, we persist result by calling flush() that creates a file named by the result node qualifier,
50
 *  eg. org.txm.partition.core.functions.PartitionDimensions@732982cb.prefs
50
 * eg. org.txm.partition.core.functions.PartitionDimensions@732982cb.prefs
51 51
 * (We can also define a custom Scope to do that, for example to change the saved object location or the filename)
52 52
 *
53 53
 *
......
55 55
 * @author sjacquot
56 56
 *
57 57
 */
58
//FIXME: AFTER some tests, the local nodes are flushed when editing a Charts engine preference from the UI, actually the prefs are flushed if we change a charts engine preference and then it becomes
58
// FIXME: AFTER some tests, the local nodes are flushed when editing a Charts engine preference from the UI, actually the prefs are flushed if we change a charts engine preference and then it becomes
59 59
// different from the local result, eg. "Show Legend" or "Rendering colors mode". See if it's what we want.
60 60
// Otherwise, to avoid that we need to define our own Scope, but the problem will disappear when
61 61
// we'll use the ProjectScope.
62 62
public abstract class TXMPreferences extends AbstractPreferenceInitializer {
63

  
63
	
64 64
	/**
65 65
	 * Scope used for storing the command preferences.
66 66
	 */
67
	//public static IScopeContext scope = InstanceScope.INSTANCE;
68

  
67
	// public static IScopeContext scope = InstanceScope.INSTANCE;
69 68
	
69
	
70 70
	public static IEclipsePreferences preferencesRootNode = Platform.getPreferencesService().getRootNode();
71 71
	
72 72
	/**
73 73
	 * Alternative nodes to look up when getting a preference.
74 74
	 */
75 75
	public static ArrayList<String> alternativeNodesQualifiers = new ArrayList<String>();
76

  
77

  
76
	
77
	
78 78
	// TXMResult internal parameters, essentially for Links and Persistence
79 79
	public final static String RESULT_PARAMETERS_NODE_PATH = "result_parameters_node_path"; //$NON-NLS-1$
80
	
80 81
	public final static String PARENT_PARAMETERS_NODE_PATH = "parent_parameters_node_path"; //$NON-NLS-1$
82
	
81 83
	public final static String BUNDLE_ID = "bundle_id"; //$NON-NLS-1$
84
	
82 85
	public final static String USER_NAME = "user_name"; //$NON-NLS-1$
86
	
83 87
	public final static String LAZY_NAME = "lazy_name"; //$NON-NLS-1$
88
	
84 89
	public final static String VISIBLE = "visible"; //$NON-NLS-1$
90
	
85 91
	public static final String LOCK = "locked_result"; //$NON-NLS-1$
86 92
	
87 93
	/**
......
98 104
	
99 105
	
100 106
	
101
	// Command preferences shared strings 
107
	// Command preferences shared strings
102 108
	/**
103 109
	 * Queries.
104 110
	 */
105 111
	public static final String QUERIES = "queries"; //$NON-NLS-1$
106

  
112
	
107 113
	/**
108 114
	 * Query.
109 115
	 */
110 116
	public static final String QUERY = "query"; //$NON-NLS-1$
111

  
117
	
112 118
	/**
113 119
	 * Structural unit.
114 120
	 */
115 121
	public static final String STRUCTURAL_UNIT = "structural_unit"; //$NON-NLS-1$
116

  
122
	
117 123
	/***
118 124
	 * Structural unit property.
119 125
	 */
120
	public static final String STRUCTURAL_UNIT_PROPERTY = "structural_unit_property"; //$NON-NLS-1$	
121

  
126
	public static final String STRUCTURAL_UNIT_PROPERTY = "structural_unit_property"; //$NON-NLS-1$
127
	
122 128
	/**
123 129
	 * Structural unit properties.
124 130
	 */
125 131
	public static final String STRUCTURAL_UNIT_PROPERTIES = "structural_unit_properties"; //$NON-NLS-1$
126

  
132
	
127 133
	/**
128 134
	 * Unit property.
129 135
	 */
130
	public static final String UNIT_PROPERTY =  "unit_property"; //$NON-NLS-1$
131

  
136
	public static final String UNIT_PROPERTY = "unit_property"; //$NON-NLS-1$
137
	
132 138
	/**
133 139
	 * Unit properties.
134 140
	 */
135
	public static final String UNIT_PROPERTIES =  "unit_properties"; //$NON-NLS-1$
141
	public static final String UNIT_PROPERTIES = "unit_properties"; //$NON-NLS-1$
136 142
	
137 143
	/**
138 144
	 * List of values
139 145
	 */
140 146
	public static final String VALUES = "values"; //$NON-NLS-1$
141

  
147
	
142 148
	/**
143 149
	 * Matches.
144 150
	 */
145 151
	public static final String MATCHES = "matches"; //$NON-NLS-1$
146

  
152
	
147 153
	/**
148 154
	 * Minimum frequency filter value.
149 155
	 */
150 156
	public static final String F_MIN = "f_min"; //$NON-NLS-1$
151

  
157
	
152 158
	/**
153 159
	 * Maximum frequency filter value.
154 160
	 */
155 161
	public static final String F_MAX = "f_max"; //$NON-NLS-1$
156

  
162
	
157 163
	/**
158
	 * V max filter (max number of lines). 
164
	 * V max filter (max number of lines).
159 165
	 */
160 166
	public static final String V_MAX = "v_max"; //$NON-NLS-1$
161

  
167
	
162 168
	/**
163 169
	 * Separator used when converting list from and to string.
164 170
	 */
165
	public static final String LIST_SEPARATOR =  "\t"; //$NON-NLS-1$
166

  
171
	public static final String LIST_SEPARATOR = "\t"; //$NON-NLS-1$
172
	
167 173
	/**
168 174
	 * Number of lines to display per page.
169 175
	 */
170 176
	public static final String N_LINES_PER_PAGE = "n_lines_per_page"; //$NON-NLS-1$
171

  
177
	
172 178
	/**
173 179
	 * Encoding.
174 180
	 */
......
183 189
	 * Default unit/token property String.
184 190
	 */
185 191
	public final static String DEFAULT_UNIT_PROPERTY = "word"; //$NON-NLS-1$
186

  
192
	
187 193
	/**
188 194
	 * Default structural unit String.
189 195
	 */
190 196
	public final static String DEFAULT_STRUCTURAL_UNIT = "text"; //$NON-NLS-1$
191

  
197
	
192 198
	/**
193 199
	 * Default structural unit property String.
194 200
	 */
......
196 202
	// End of command preferences shared strings
197 203
	
198 204
	
199

  
205
	
200 206
	/**
201
	 * Preferences node qualifier of the instance. 
207
	 * Preferences node qualifier of the instance.
202 208
	 */
203 209
	protected String commandPreferencesNodeQualifier;
204 210
	
205 211
	/**
206
	 * TXMPreferences instances map 
212
	 * TXMPreferences instances map
207 213
	 */
208 214
	protected static Map<Class<? extends TXMPreferences>, TXMPreferences> instances = new HashMap<>();
209

  
215
	
210 216
	@Override
211 217
	/**
212 218
	 * Sub classes should not forget to call this to set TXMResults main behavior (visible, etc...)
213 219
	 */
214 220
	public void initializeDefaultPreferences() {
215

  
221
		
216 222
		Preferences preferences = this.getDefaultPreferencesNode();
217 223
		preferences.putBoolean(TBXPreferences.VISIBLE, true);
218 224
		preferences.putBoolean(TBXPreferences.LOCK, false);
219 225
		preferences.put(TBXPreferences.CORPUS_VERSION, "0.8.0");
220 226
	}
221

  
227
	
222 228
	/**
223 229
	 * 
224 230
	 */
......
226 232
		super();
227 233
		TXMPreferences.instances.put(this.getClass(), this);
228 234
		this.commandPreferencesNodeQualifier = FrameworkUtil.getBundle(this.getClass()).getSymbolicName();
229
		Log.finest("TXMPreferences.TXMPreferences(): initializing preferences for node = " + this.commandPreferencesNodeQualifier + " (" + this.getClass() +")");
235
		Log.finest("TXMPreferences.TXMPreferences(): initializing preferences for node = " + this.commandPreferencesNodeQualifier + " (" + this.getClass() + ")");
230 236
	}
231

  
232

  
237
	
238
	
233 239
	/**
234 240
	 * 
235 241
	 * @param key
236 242
	 * @return
237 243
	 */
238
	public double getDouble(String key)	{
244
	public double getDouble(String key) {
239 245
		return getDouble(key, this.commandPreferencesNodeQualifier);
240 246
	}
241

  
247
	
242 248
	/**
243 249
	 * 
244 250
	 * @param key
245 251
	 * @return
246 252
	 */
247
	public boolean getBoolean(String key)	{
253
	public boolean getBoolean(String key) {
248 254
		return getBoolean(key, this.commandPreferencesNodeQualifier);
249 255
	}
250

  
256
	
251 257
	/**
252 258
	 * 
253 259
	 * @param key
254 260
	 * @return
255 261
	 */
256
	public int getInt(String key)	{
262
	public int getInt(String key) {
257 263
		return getInt(key, this.commandPreferencesNodeQualifier);
258 264
	}
259

  
265
	
260 266
	/**
261 267
	 * 
262 268
	 * @param key
263 269
	 * @return
264 270
	 */
265
	public long getLong(String key)	{
271
	public long getLong(String key) {
266 272
		return getLong(key, this.commandPreferencesNodeQualifier);
267 273
	}
268 274
	
......
271 277
	 * @param key
272 278
	 * @return
273 279
	 */
274
	public String getString(String key)	{
280
	public String getString(String key) {
275 281
		return getString(key, this.commandPreferencesNodeQualifier);
276 282
	}
277 283
	
278

  
284
	
279 285
	/**
280 286
	 * 
281 287
	 * @param key
282 288
	 * @return
283 289
	 */
284
	public float getFloat(String key)	{
290
	public float getFloat(String key) {
285 291
		return getFloat(key, this.commandPreferencesNodeQualifier);
286 292
	}
287

  
288

  
293
	
294
	
289 295
	/**
290 296
	 * Gets the preferences node qualifier of the instance.
297
	 * 
291 298
	 * @return the preferencesNode
292 299
	 */
293 300
	public String getPreferencesNodeQualifier() {
294 301
		return commandPreferencesNodeQualifier;
295 302
	}
296

  
297 303
	
298 304
	
299 305
	
300
//	/**
301
//	 * Stores a pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
302
//	 * 
303
//	 * @param key
304
//	 * @param pValue
305
//	 */
306
//	public static void remove(String key, String node)	{
307
//		scope.getNode(node).remove(key);
308
//	}
309

  
306
	
307
	// /**
308
	// * Stores a pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
309
	// *
310
	// * @param key
311
	// * @param pValue
312
	// */
313
	// public static void remove(String key, String node) {
314
	// scope.getNode(node).remove(key);
315
	// }
316
	
310 317
	/**
311 318
	 * Saves all preferences and session results in the default app directory.
312 319
	 */
313 320
	public static void saveAll() {
314

  
321
		
315 322
		Log.fine("Saving preferences and session results...");
316 323
		
317 324
		try {
318 325
			preferencesRootNode.flush();
319
		} catch(Exception e) {
326
		}
327
		catch (Exception e) {
320 328
			Log.severe("Error while saving preferences and session results.");
321 329
			e.printStackTrace();
322 330
		}
323 331
	}
324

  
332
	
325 333
	/**
326 334
	 * Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
327 335
	 * Returns the value of a key in the specified parameters if exists.
......
329 337
	 * Otherwise try to get it from the specified node qualifier if exists.
330 338
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
331 339
	 * Returns <code>false</code> if no value has been found for the specified key.
340
	 * 
332 341
	 * @param commandParameters
333 342
	 * @param nodePath
334 343
	 * @param result
335 344
	 * @param key
336 345
	 * @return
337 346
	 */
338
	public static Serializable getSerializable(String key, TXMParameters commandParameters, TXMResult result, String nodePath)	{
339
		if(commandParameters != null && commandParameters.get(key) != null)	{
347
	public static Serializable getSerializable(String key, TXMParameters commandParameters, TXMResult result, String nodePath) {
348
		if (commandParameters != null && commandParameters.get(key) != null) {
340 349
			return (Serializable) commandParameters.get(key);
341 350
		}
342 351
		return getSerializable(key, result, nodePath);
343 352
	}
344

  
345

  
346
	public static Serializable getSerializable(String key, TXMParameters commandParameters, TXMResult result)	{
353
	
354
	
355
	public static Serializable getSerializable(String key, TXMParameters commandParameters, TXMResult result) {
347 356
		return getSerializable(key, commandParameters, result, result.getCommandPreferencesNodePath());
348 357
	}
349

  
358
	
350 359
	/**
351 360
	 * Looks for the value of the specified <code>key</code> in preference nodes.
352 361
	 * Returns the value of the local result node if exists.
353 362
	 * Otherwise try to get it from the specified node qualifier if exists.
354 363
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
355 364
	 * Returns defaultValue if no value has been found for the specified key.
365
	 * 
356 366
	 * @param nodePath
357 367
	 * @param result
358 368
	 * @param key
359 369
	 * @return
360 370
	 */
361
	public static Serializable getSerializable(String key, TXMResult result, String nodePath, Serializable defaultValue)	{
362

  
371
	public static Serializable getSerializable(String key, TXMResult result, String nodePath, Serializable defaultValue) {
372
		
363 373
		nodePath = findNodePath(nodePath, result, key);
364

  
374
		
365 375
		String data_default = DefaultScope.INSTANCE.getNode(nodePath).get(key, "");
366 376
		if (data_default.length() == 0) {
367 377
			return null;
368 378
		}
369

  
379
		
370 380
		try {
371 381
			defaultValue = fromString(data_default);
372
		} catch (Exception e) {
382
		}
383
		catch (Exception e) {
373 384
			Log.printStackTrace(e);
374 385
		}
375

  
386
		
376 387
		String data_return = preferencesRootNode.node(nodePath).get(key, "");
377 388
		if (data_return.length() == 0) {
378 389
			return defaultValue;
379 390
		}
380

  
391
		
381 392
		try {
382 393
			return fromString(data_return);
383
		} catch (Exception e) {
394
		}
395
		catch (Exception e) {
384 396
			Log.printStackTrace(e);
385 397
		}
386 398
		return null;
387 399
	}
388

  
400
	
389 401
	/**
390 402
	 * Looks for the value of the specified <code>key</code> in preference nodes.
391 403
	 * Returns the value of the local result node if exists.
392 404
	 * Otherwise try to get it from the specified node qualifier if exists.
393 405
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
394 406
	 * Returns <code>false</code> if no value has been found for the specified key.
407
	 * 
395 408
	 * @param nodePath
396 409
	 * @param result
397 410
	 * @param key
398 411
	 * @return
399 412
	 */
400
	public static Serializable getSerializable(String key, TXMResult result, String nodePath)	{
413
	public static Serializable getSerializable(String key, TXMResult result, String nodePath) {
401 414
		return getSerializable(key, result, nodePath, false);
402 415
	}
403

  
416
	
404 417
	/**
405 418
	 *
406 419
	 * @param nodePath
407 420
	 * @param key
408 421
	 * @return
409 422
	 */
410
	public static Serializable getSerializable(String key, String nodePath)	{
423
	public static Serializable getSerializable(String key, String nodePath) {
411 424
		return getSerializable(key, null, nodePath);
412 425
	}
413

  
426
	
414 427
	/**
415 428
	 *
416 429
	 * @param result
417 430
	 * @param key
418 431
	 * @return
419 432
	 */
420
	public static Serializable getSerializable(String key, TXMResult result)	{
433
	public static Serializable getSerializable(String key, TXMResult result) {
421 434
		return getSerializable(key, result, null);
422 435
	}
423

  
436
	
424 437
	/**
425 438
	 * Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
426 439
	 * Returns the value of a key in the specified parameters if exists.
......
428 441
	 * Otherwise try to get it from the specified node qualifier if exists.
429 442
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
430 443
	 * Returns <code>false</code> if no value has been found for the specified key.
444
	 * 
431 445
	 * @param commandParameters
432 446
	 * @param nodePath
433 447
	 * @param result
434 448
	 * @param key
435 449
	 * @return
436 450
	 */
437
	public static boolean getBoolean(String key, TXMParameters commandParameters, TXMResult result, String nodePath)	{
438
		if(commandParameters != null && commandParameters.get(key) != null)	{
451
	public static boolean getBoolean(String key, TXMParameters commandParameters, TXMResult result, String nodePath) {
452
		if (commandParameters != null && commandParameters.get(key) != null) {
439 453
			return (Boolean) commandParameters.get(key);
440 454
		}
441 455
		return getBoolean(key, result, nodePath);
442 456
	}
443

  
444

  
445
	public static boolean getBoolean(String key, TXMParameters commandParameters, TXMResult result)	{
457
	
458
	
459
	public static boolean getBoolean(String key, TXMParameters commandParameters, TXMResult result) {
446 460
		return getBoolean(key, commandParameters, result, result.getCommandPreferencesNodePath());
447 461
	}
448

  
462
	
449 463
	/**
450 464
	 * Looks for the value of the specified <code>key</code> in preference nodes.
451 465
	 * Returns the value of the local result node if exists.
452 466
	 * Otherwise try to get it from the specified node qualifier if exists.
453 467
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
454 468
	 * Returns defaultValue if no value has been found for the specified key.
469
	 * 
455 470
	 * @param nodePath
456 471
	 * @param result
457 472
	 * @param key
458 473
	 * @return
459 474
	 */
460
	public static boolean getBoolean(String key, TXMResult result, String nodePath, boolean defaultValue)	{
461

  
475
	public static boolean getBoolean(String key, TXMResult result, String nodePath, boolean defaultValue) {
476
		
462 477
		nodePath = findNodePath(nodePath, result, key);
463

  
478
		
464 479
		defaultValue = DefaultScope.INSTANCE.getNode(nodePath).getBoolean(key, defaultValue);
465 480
		return preferencesRootNode.node(nodePath).getBoolean(key, defaultValue);
466 481
	}
467

  
482
	
468 483
	/**
469 484
	 * Looks for the value of the specified <code>key</code> in preference nodes.
470 485
	 * Returns the value of the local result node if exists.
471 486
	 * Otherwise try to get it from the specified node qualifier if exists.
472 487
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
473 488
	 * Returns <code>false</code> if no value has been found for the specified key.
489
	 * 
474 490
	 * @param nodePath
475 491
	 * @param result
476 492
	 * @param key
477 493
	 * @return
478 494
	 */
479
	public static boolean getBoolean(String key, TXMResult result, String nodePath)	{
495
	public static boolean getBoolean(String key, TXMResult result, String nodePath) {
480 496
		return getBoolean(key, result, nodePath, false);
481 497
	}
482

  
498
	
483 499
	/**
484 500
	 *
485 501
	 * @param nodePath
486 502
	 * @param key
487 503
	 * @return
488 504
	 */
489
	public static boolean getBoolean(String key, String nodePath)	{
505
	public static boolean getBoolean(String key, String nodePath) {
490 506
		return getBoolean(key, null, nodePath);
491 507
	}
492

  
508
	
493 509
	/**
494 510
	 *
495 511
	 * @param result
496 512
	 * @param key
497 513
	 * @return
498 514
	 */
499
	public static boolean getBoolean(String key, TXMResult result)	{
515
	public static boolean getBoolean(String key, TXMResult result) {
500 516
		return getBoolean(key, result, null);
501 517
	}
502

  
503

  
504

  
518
	
519
	
520
	
505 521
	/**
506 522
	 * Try to cast and create a typed object from the String value of the key.
523
	 * 
507 524
	 * @param commandParameters
508 525
	 * @param result
509 526
	 * @param nodePath
510 527
	 * @param key
511 528
	 * @return
512 529
	 */
513
	//FIXME: does not work, need to test furthermore
514
	//	public static Object get(TXMResultParameters commandParameters, TXMResult result, String nodePath, String key)	{
530
	// FIXME: does not work, need to test furthermore
531
	// public static Object get(TXMResultParameters commandParameters, TXMResult result, String nodePath, String key) {
515 532
	//
516 533
	//
517
	//		if(commandParameters != null && commandParameters.get(key) != null)	{
518
	//			return commandParameters.get(key);
519
	//		}
534
	// if(commandParameters != null && commandParameters.get(key) != null) {
535
	// return commandParameters.get(key);
536
	// }
520 537
	//
521
	//		nodePath = findNodeQualifier(nodePath, result, key);
538
	// nodePath = findNodeQualifier(nodePath, result, key);
522 539
	//
523
	//		String stringValue = getString(nodePath, key);
540
	// String stringValue = getString(nodePath, key);
524 541
	//
525
	//		try {
526
	//			// double
527
	//			try {
528
	//				return Double.parseDouble(stringValue);
529
	//			}
530
	//			catch(NumberFormatException e) {
531
	//			}
532
	//			// float
533
	//			try {
534
	//				return Float.parseFloat(stringValue);
535
	//			}
536
	//			catch(NumberFormatException e) {
537
	//			}
538
	//			// long
539
	//			try {
540
	//				return Long.parseLong(stringValue);
541
	//			}
542
	//			catch(NumberFormatException e) {
543
	//			}
544
	//			// integer
545
	//			try {
546
	//				return Integer.parseInt(stringValue);
547
	//			}
548
	//			catch(NumberFormatException e) {
549
	//			}
550
	//			// short
551
	//			try {
552
	//				return Short.parseShort(stringValue);
553
	//			}
554
	//			catch(NumberFormatException e) {
555
	//			}
556
	//			// boolean
557
	//			try {
558
	//				return Boolean.parseBoolean(stringValue);
559
	//			}
560
	//			catch(NumberFormatException e) {
561
	//			}
562
	//		}
563
	//		catch(Exception e) {
564
	//			// TODO Auto-generated catch block
565
	//			e.printStackTrace();
566
	//			System.err.println("TXMPreferences.get(): can't parse and primitive cast the specified string value: " + stringValue + "."); //$NON-NLS-1$
567
	//		}
568
	//		return stringValue;
569
	//	}
570

  
571

  
572

  
573
//	/**
574
//	 * Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
575
//	 * Returns the value of a key in the specified parameters if exists.
576
//	 * Otherwise try to get it from the local result node if exists.
577
//	 * Otherwise try to get it from the specified node qualifier if exists.
578
//	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
579
//	 * Returns an empty <code>String</code> if no value has been found for the specified key.
580
//	 * @param commandParameters
581
//	 * @param nodePath
582
//	 * @param result
583
//	 * @param key
584
//	 * @return
585
//	 */
586
//	public static String getString(String key, TXMParameters commandParameters, TXMResult result, String nodePath)	{
587
//		if(commandParameters != null && commandParameters.get(key) != null)	{
588
//			return (String) commandParameters.get(key);
589
//		}
590
//		return getString(key, result, nodePath);
591
//	}
592
//
593
//	public static String getString(String key, TXMParameters commandParameters, TXMResult result)	{
594
//		return getString(key, commandParameters, result, result.getCommandPreferencesNodePath());
595
//	}
596

  
597

  
542
	// try {
543
	// // double
544
	// try {
545
	// return Double.parseDouble(stringValue);
546
	// }
547
	// catch(NumberFormatException e) {
548
	// }
549
	// // float
550
	// try {
551
	// return Float.parseFloat(stringValue);
552
	// }
553
	// catch(NumberFormatException e) {
554
	// }
555
	// // long
556
	// try {
557
	// return Long.parseLong(stringValue);
558
	// }
559
	// catch(NumberFormatException e) {
560
	// }
561
	// // integer
562
	// try {
563
	// return Integer.parseInt(stringValue);
564
	// }
565
	// catch(NumberFormatException e) {
566
	// }
567
	// // short
568
	// try {
569
	// return Short.parseShort(stringValue);
570
	// }
571
	// catch(NumberFormatException e) {
572
	// }
573
	// // boolean
574
	// try {
575
	// return Boolean.parseBoolean(stringValue);
576
	// }
577
	// catch(NumberFormatException e) {
578
	// }
579
	// }
580
	// catch(Exception e) {
581
	// // TODO Auto-generated catch block
582
	// e.printStackTrace();
583
	// System.err.println("TXMPreferences.get(): can't parse and primitive cast the specified string value: " + stringValue + "."); //$NON-NLS-1$
584
	// }
585
	// return stringValue;
586
	// }
587
	
588
	
589
	
590
	// /**
591
	// * Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
592
	// * Returns the value of a key in the specified parameters if exists.
593
	// * Otherwise try to get it from the local result node if exists.
594
	// * Otherwise try to get it from the specified node qualifier if exists.
595
	// * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
596
	// * Returns an empty <code>String</code> if no value has been found for the specified key.
597
	// * @param commandParameters
598
	// * @param nodePath
599
	// * @param result
600
	// * @param key
601
	// * @return
602
	// */
603
	// public static String getString(String key, TXMParameters commandParameters, TXMResult result, String nodePath) {
604
	// if(commandParameters != null && commandParameters.get(key) != null) {
605
	// return (String) commandParameters.get(key);
606
	// }
607
	// return getString(key, result, nodePath);
608
	// }
609
	//
610
	// public static String getString(String key, TXMParameters commandParameters, TXMResult result) {
611
	// return getString(key, commandParameters, result, result.getCommandPreferencesNodePath());
612
	// }
613
	
614
	
598 615
	/**
599 616
	 * Looks for the value of the specified <code>key</code> in preference nodes.
600 617
	 * Returns the value of the local result node if exists.
601 618
	 * Otherwise try to get it from the specified node qualifier if exists.
602 619
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
603 620
	 * Returns defaultValue if no value has been found for the specified key.
621
	 * 
604 622
	 * @param nodePath
605 623
	 * @param result
606 624
	 * @param key
607 625
	 * @return
608 626
	 */
609 627
	public static String getString(String key, TXMResult result, String nodePath, String defaultValue) {
610

  
628
		
611 629
		nodePath = findNodePath(nodePath, result, key);
612

  
613
		//System.out.println("--- TXMPreferences.getString() node path = " + nodePath);
614 630
		
615
		//FIXME defaultValue is always replaced even if set
631
		// System.out.println("--- TXMPreferences.getString() node path = " + nodePath);
632
		
633
		// FIXME defaultValue is always replaced even if set
616 634
		defaultValue = DefaultScope.INSTANCE.getNode(nodePath).get(key, defaultValue);
617 635
		return preferencesRootNode.node(nodePath).get(key, defaultValue);
618 636
	}
619

  
637
	
620 638
	/**
621 639
	 * Looks for the value of the specified <code>key</code> in preference nodes.
622 640
	 * Returns the value of the local result node if exists.
623 641
	 * Otherwise try to get it from the specified node qualifier if exists.
624 642
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
625 643
	 * Returns defaultValue if no value has been found for the specified key.
644
	 * 
626 645
	 * @param nodePath
627 646
	 * @param result
628 647
	 * @param key
629 648
	 * @return
630 649
	 */
631 650
	public static Date getDate(String key, TXMResult result, String nodePath, Date defaultValue) {
632

  
651
		
633 652
		nodePath = findNodePath(nodePath, result, key);
634

  
635
		//System.out.println("--- TXMPreferences.getString() node path = " + nodePath);
636 653
		
654
		// System.out.println("--- TXMPreferences.getString() node path = " + nodePath);
655
		
637 656
		Date v = null;
638 657
		try {
639 658
			v = TXMResult.ID_TIME_FORMAT.parse(DefaultScope.INSTANCE.getNode(nodePath).get(key, null));
640
		} catch (Exception e) { }
659
		}
660
		catch (Exception e) {
661
		}
641 662
		if (v != null) {
642 663
			defaultValue = v;
643 664
		}
644 665
		v = null;
645 666
		try {
646 667
			v = TXMResult.ID_TIME_FORMAT.parse(preferencesRootNode.node(nodePath).get(key, null));
647
		} catch (Exception e) { }
668
		}
669
		catch (Exception e) {
670
		}
648 671
		
649 672
		if (v != null) {
650 673
			return defaultValue;
651
		} else {
674
		}
675
		else {
652 676
			return v;
653 677
		}
654 678
	}
655

  
679
	
656 680
	/**
657 681
	 * Looks for the value of the specified <code>key</code> in preference nodes.
658 682
	 * Returns the value of the local result node if exists.
659 683
	 * Otherwise try to get it from the specified node qualifier if exists.
660 684
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
661 685
	 * Returns an empty <code>String</code> if no value has been found for the specified key.
686
	 * 
662 687
	 * @param nodePath
663 688
	 * @param result
664 689
	 * @param key
665 690
	 * @return
666 691
	 */
667
	public static String getString(String key, TXMResult result, String nodePath)	{
692
	public static String getString(String key, TXMResult result, String nodePath) {
668 693
		return getString(key, result, nodePath, ""); //$NON-NLS-1$
669 694
	}
670 695
	
......
674 699
	 * Otherwise try to get it from the specified node qualifier if exists.
675 700
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
676 701
	 * Returns a 0 time <code>Date</code> if no value has been found for the specified key.
702
	 * 
677 703
	 * @param nodePath
678 704
	 * @param result
679 705
	 * @param key
680 706
	 * @return
681 707
	 */
682
	public static Date getDate(String key, TXMResult result, String nodePath)	{
683
		return getDate(key, result, nodePath, new Date(0)); //$NON-NLS-1$
708
	public static Date getDate(String key, TXMResult result, String nodePath) {
709
		return getDate(key, result, nodePath, new Date(0)); // $NON-NLS-1$
684 710
	}
685

  
686

  
711
	
712
	
687 713
	/**
688 714
	 *
689 715
	 * @param nodePath
690 716
	 * @param key
691 717
	 * @return
692 718
	 */
693
	public static String getString(String key, String nodePath)	{
719
	public static String getString(String key, String nodePath) {
694 720
		return getString(key, null, nodePath);
695 721
	}
696

  
697

  
722
	
723
	
698 724
	/**
699 725
	 *
700 726
	 * @param result
701 727
	 * @param key
702 728
	 * @return
703 729
	 */
704
	public static String getString(String key, TXMResult result)	{
730
	public static String getString(String key, TXMResult result) {
705 731
		return getString(key, result, null);
706 732
	}
707

  
708

  
709

  
710

  
733
	
734
	
735
	
736
	
711 737
	/**
712 738
	 * Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
713 739
	 * Returns the value of a key in the specified parameters if exists.
......
715 741
	 * Otherwise try to get it from the specified node qualifier if exists.
716 742
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
717 743
	 * Returns 0 if no value has been found for the specified key.
744
	 * 
718 745
	 * @param commandParameters
719 746
	 * @param nodePath
720 747
	 * @param result
721 748
	 * @param key
722 749
	 * @return
723 750
	 */
724
	public static int getInt(String key, TXMParameters commandParameters, TXMResult result, String nodePath)	{
725
		if(commandParameters != null && commandParameters.get(key) != null)	{
751
	public static int getInt(String key, TXMParameters commandParameters, TXMResult result, String nodePath) {
752
		if (commandParameters != null && commandParameters.get(key) != null) {
726 753
			return (Integer) commandParameters.get(key);
727 754
		}
728 755
		return getInt(key, result, nodePath);
729 756
	}
730

  
731

  
732
	public static int getInt(String key, TXMParameters commandParameters, TXMResult result)	{
757
	
758
	
759
	public static int getInt(String key, TXMParameters commandParameters, TXMResult result) {
733 760
		return getInt(key, commandParameters, result, result.getCommandPreferencesNodePath());
734 761
	}
735

  
762
	
736 763
	/**
737 764
	 * Looks for the value of the specified <code>key</code> in preference nodes.
738 765
	 * Returns the value of the local result node if exists.
739 766
	 * Otherwise try to get it from the specified node qualifier if exists.
740 767
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
741 768
	 * Returns defaultValue if no value has been found for the specified key.
769
	 * 
742 770
	 * @param nodePath
743 771
	 * @param result
744 772
	 * @param key
745 773
	 * @return
746 774
	 */
747
	public static int getInt(String key, TXMResult result, String nodePath)	{
775
	public static int getInt(String key, TXMResult result, String nodePath) {
748 776
		nodePath = findNodePath(nodePath, result, key);
749

  
777
		
750 778
		int defaultValue = DefaultScope.INSTANCE.getNode(nodePath).getInt(key, 0);
751 779
		return preferencesRootNode.node(nodePath).getInt(key, defaultValue);
752

  
780
		
753 781
	}
754

  
782
	
755 783
	/**
756 784
	 *
757 785
	 * @param nodePath
758 786
	 * @param key
759 787
	 * @return
760 788
	 */
761
	public static int getInt(String key, String nodePath)	{
789
	public static int getInt(String key, String nodePath) {
762 790
		return getInt(key, null, nodePath);
763 791
	}
764

  
792
	
765 793
	/**
766 794
	 *
767 795
	 * @param result
768 796
	 * @param key
769 797
	 * @return
770 798
	 */
771
	public static int getInt(String key, TXMResult result)	{
799
	public static int getInt(String key, TXMResult result) {
772 800
		return getInt(key, result, null);
773 801
	}
774

  
775

  
802
	
803
	
776 804
	/**
777 805
	 * Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
778 806
	 * Returns the value of a key in the specified parameters if exists.
......
780 808
	 * Otherwise try to get it from the specified node qualifier if exists.
781 809
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
782 810
	 * Returns 0L if no value has been found for the specified key.
811
	 * 
783 812
	 * @param commandParameters
784 813
	 * @param nodePath
785 814
	 * @param result
786 815
	 * @param key
787 816
	 * @return
788 817
	 */
789
	public static long getLong(String key, TXMParameters commandParameters, TXMResult result, String nodePath)	{
790
		if(commandParameters != null && commandParameters.get(key) != null)	{
818
	public static long getLong(String key, TXMParameters commandParameters, TXMResult result, String nodePath) {
819
		if (commandParameters != null && commandParameters.get(key) != null) {
791 820
			return (Long) commandParameters.get(key);
792 821
		}
793 822
		return getLong(key, result, nodePath);
794 823
	}
795

  
796
	public static long getLong(String key, TXMParameters commandParameters, TXMResult result)	{
824
	
825
	public static long getLong(String key, TXMParameters commandParameters, TXMResult result) {
797 826
		return getLong(key, commandParameters, result, result.getCommandPreferencesNodePath());
798 827
	}
799

  
800

  
801

  
828
	
829
	
830
	
802 831
	/**
803 832
	 * Looks for the value of the specified <code>key</code> in preference nodes.
804 833
	 * Returns the value of the local result node if exists.
805 834
	 * Otherwise try to get it from the specified node qualifier if exists.
806 835
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
807 836
	 * Returns defaultValue if no value has been found for the specified key.
837
	 * 
808 838
	 * @param nodePath
809 839
	 * @param result
810 840
	 * @param key
811 841
	 * @param defaultValue
812 842
	 * @return
813 843
	 */
814
	public static long getLong(String key, TXMResult result, String nodePath, long defaultValue)	{
844
	public static long getLong(String key, TXMResult result, String nodePath, long defaultValue) {
815 845
		nodePath = findNodePath(nodePath, result, key);
816

  
846
		
817 847
		defaultValue = DefaultScope.INSTANCE.getNode(nodePath).getLong(key, defaultValue);
818 848
		return preferencesRootNode.node(nodePath).getLong(key, defaultValue);
819

  
849
		
820 850
	}
821

  
851
	
822 852
	/**
823 853
	 * Looks for the value of the specified <code>key</code> in preference nodes.
824 854
	 * Returns the value of the local result node if exists.
825 855
	 * Otherwise try to get it from the specified node qualifier if exists.
826 856
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
827 857
	 * Returns 0L if no value has been found for the specified key.
858
	 * 
828 859
	 * @param nodePath
829 860
	 * @param result
830 861
	 * @param key
831 862
	 * @param defaultValue
832 863
	 * @return
833 864
	 */
834
	public static long getLong(String key, TXMResult result, String nodePath)	{
865
	public static long getLong(String key, TXMResult result, String nodePath) {
835 866
		return getLong(key, result, nodePath, 0L);
836 867
	}
837

  
868
	
838 869
	/**
839 870
	 *
840 871
	 * @param nodePath
841 872
	 * @param key
842 873
	 * @return
843 874
	 */
844
	public static long getLong(String key, String nodePath)	{
875
	public static long getLong(String key, String nodePath) {
845 876
		return getLong(key, null, nodePath);
846 877
	}
847

  
878
	
848 879
	/**
849 880
	 *
850 881
	 * @param result
851 882
	 * @param key
852 883
	 * @return
853 884
	 */
854
	public static long getLong(String key, TXMResult result)	{
885
	public static long getLong(String key, TXMResult result) {
855 886
		return getLong(key, result, null);
856 887
	}
857

  
858

  
888
	
889
	
859 890
	/**
860 891
	 * Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
861 892
	 * Returns the value of a key in the specified parameters if exists.
......
863 894
	 * Otherwise try to get it from the specified node qualifier if exists.
864 895
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
865 896
	 * Returns 0.0d if no value has been found for the specified key.
897
	 * 
866 898
	 * @param commandParameters
867 899
	 * @param nodePath
868 900
	 * @param result
869 901
	 * @param key
870 902
	 * @return
871 903
	 */
872
	public static double getDouble(String key, TXMParameters commandParameters, TXMResult result, String nodePath)	{
873
		if(commandParameters != null && commandParameters.get(key) != null)	{
904
	public static double getDouble(String key, TXMParameters commandParameters, TXMResult result, String nodePath) {
905
		if (commandParameters != null && commandParameters.get(key) != null) {
874 906
			return (Double) commandParameters.get(key);
875 907
		}
876 908
		return getDouble(key, result, nodePath);
877 909
	}
878

  
879
	public static double getDouble(String key, TXMParameters commandParameters, TXMResult result)	{
910
	
911
	public static double getDouble(String key, TXMParameters commandParameters, TXMResult result) {
880 912
		return getDouble(key, commandParameters, result, result.getCommandPreferencesNodePath());
881 913
	}
882

  
883

  
914
	
915
	
884 916
	/**
885 917
	 * Looks for the value of the specified <code>key</code> in preference nodes.
886 918
	 * Returns the value of the local result node if exists.
887 919
	 * Otherwise try to get it from the specified node qualifier if exists.
888 920
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
889 921
	 * Returns defaultValue if no value has been found for the specified key.
922
	 * 
890 923
	 * @param nodePath
891 924
	 * @param result
892 925
	 * @param key
893 926
	 * @return
894 927
	 */
895
	public static double getDouble(String key, String nodePath, TXMResult result, double defaultValue)	{
928
	public static double getDouble(String key, String nodePath, TXMResult result, double defaultValue) {
896 929
		nodePath = findNodePath(nodePath, result, key);
897

  
930
		
898 931
		defaultValue = DefaultScope.INSTANCE.getNode(nodePath).getDouble(key, defaultValue);
899 932
		return preferencesRootNode.node(nodePath).getDouble(key, defaultValue);
900 933
	}
901

  
934
	
902 935
	/**
903 936
	 * Looks for the value of the specified <code>key</code> in preference nodes.
904 937
	 * Returns the value of the local result node if exists.
905 938
	 * Otherwise try to get it from the specified node qualifier if exists.
906 939
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
907 940
	 * Returns 0.0d if no value has been found for the specified key.
941
	 * 
908 942
	 * @param nodePath
909 943
	 * @param result
910 944
	 * @param key
911 945
	 * @return
912 946
	 */
913
	public static double getDouble(String key, TXMResult result, String nodePath)	{
947
	public static double getDouble(String key, TXMResult result, String nodePath) {
914 948
		return getDouble(key, nodePath, result, 0.0d);
915 949
	}
916

  
917

  
950
	
951
	
918 952
	/**
919 953
	 *
920 954
	 * @param nodePath
921 955
	 * @param key
922 956
	 * @return
923 957
	 */
924
	public static double getDouble(String key, String nodePath)	{
958
	public static double getDouble(String key, String nodePath) {
925 959
		return getDouble(key, null, nodePath);
926 960
	}
927

  
928

  
961
	
962
	
929 963
	/**
930 964
	 *
931 965
	 * @param result
932 966
	 * @param key
933 967
	 * @return
934 968
	 */
935
	public static double getDouble(String key, TXMResult result)	{
969
	public static double getDouble(String key, TXMResult result) {
936 970
		return getDouble(key, result, null);
937 971
	}
938

  
939

  
940

  
941

  
972
	
973
	
974
	
975
	
942 976
	/**
943 977
	 * Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
944 978
	 * Returns the value of a key in the specified parameters if exists.
......
946 980
	 * Otherwise try to get it from the specified node qualifier if exists.
947 981
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
948 982
	 * Returns 0f if no value has been found for the specified key.
983
	 * 
949 984
	 * @param commandParameters
950 985
	 * @param nodePath
951 986
	 * @param result
952 987
	 * @param key
953 988
	 * @return
954 989
	 */
955
	public static float getFloat(String key, TXMParameters commandParameters, TXMResult result, String nodePath)	{
956
		if(commandParameters != null && commandParameters.get(key) != null)	{
990
	public static float getFloat(String key, TXMParameters commandParameters, TXMResult result, String nodePath) {
991
		if (commandParameters != null && commandParameters.get(key) != null) {
957 992
			return (Float) commandParameters.get(key);
958 993
		}
959 994
		return getFloat(key, result, nodePath);
960 995
	}
961

  
962
	public static float getFloat(String key, TXMParameters commandParameters, TXMResult result)	{
996
	
997
	public static float getFloat(String key, TXMParameters commandParameters, TXMResult result) {
963 998
		return getFloat(key, commandParameters, result, result.getCommandPreferencesNodePath());
964 999
	}
965

  
1000
	
966 1001
	/**
967 1002
	 * Looks for the value of the specified <code>key</code> in preference nodes.
968 1003
	 * Returns the value of the local result node if exists.
969 1004
	 * Otherwise try to get it from the specified node qualifier if exists.
970 1005
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
971 1006
	 * Returns defaultValue if no value has been found for the specified key.
1007
	 * 
972 1008
	 * @param nodePath
973 1009
	 * @param result
974 1010
	 * @param key
975 1011
	 * @return
976 1012
	 */
977
	public static float getFloat(String key, String nodePath, TXMResult result, float defaultValue)	{
1013
	public static float getFloat(String key, String nodePath, TXMResult result, float defaultValue) {
978 1014
		nodePath = findNodePath(nodePath, result, key);
979

  
1015
		
980 1016
		defaultValue = DefaultScope.INSTANCE.getNode(nodePath).getFloat(key, defaultValue);
981 1017
		return preferencesRootNode.node(nodePath).getFloat(key, defaultValue);
982 1018
	}
983

  
984

  
1019
	
1020
	
985 1021
	public static Serializable toSerializable(byte[] bytes) {
986

  
1022
		
987 1023
		try {
988 1024
			ByteArrayInputStream breader = new ByteArrayInputStream(bytes);
989 1025
			ObjectInputStream reader = new ObjectInputStream(breader);
990

  
1026
			
991 1027
			Object o = reader.readObject();
992 1028
			reader.close();
993 1029
			breader.close();
994
			return (Serializable)o;
995
		} catch (Exception e) {
1030
			return (Serializable) o;
1031
		}
1032
		catch (Exception e) {
996 1033
			Log.severe("Error while loading bytes: " + e.getLocalizedMessage());
997 1034
			Log.printStackTrace(e);
998 1035
		}
999 1036
		return null;
1000 1037
	}
1001

  
1038
	
1002 1039
	public static Serializable getSerializable(String key, String nodePath, TXMResult result, Serializable defaultValue) {
1003

  
1040
		
1004 1041
		try {
1005 1042
			byte[] defaultBytes = toByteArray(defaultValue);
1006

  
1043
			
1007 1044
			nodePath = findNodePath(nodePath, result, key);
1008

  
1045
			
1009 1046
			defaultBytes = DefaultScope.INSTANCE.getNode(nodePath).getByteArray(key, defaultBytes);
1010 1047
			byte[] bytes = preferencesRootNode.node(nodePath).getByteArray(key, defaultBytes);
1011

  
1048
			
1012 1049
			return toSerializable(bytes);
1013
		} catch (Exception e) {
1014
			System.out.println("Error while reading "+key+" byte preference: "+e.getLocalizedMessage());
1050
		}
1051
		catch (Exception e) {
1052
			System.out.println("Error while reading " + key + " byte preference: " + e.getLocalizedMessage());
1015 1053
			Log.printStackTrace(e);
1016 1054
		}
1017 1055
		return null;
1018 1056
	}
1019

  
1020

  
1057
	
1058
	
1021 1059
	/**
1022 1060
	 * Looks for the value of the specified <code>key</code> in preference nodes.
1023 1061
	 * Returns the value of the local result node if exists.
1024 1062
	 * Otherwise try to get it from the specified node qualifier if exists.
1025 1063
	 * Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
1026 1064
	 * Returns 0f if no value has been found for the specified key.
1065
	 * 
1027 1066
	 * @param nodePath
1028 1067
	 * @param result
1029 1068
	 * @param key
1030 1069
	 * @return
1031 1070
	 */
1032
	public static float getFloat(String key, TXMResult result, String nodePath)	{
1071
	public static float getFloat(String key, TXMResult result, String nodePath) {
1033 1072
		return getFloat(key, nodePath, result, 0f);
1034 1073
	}
1035

  
1036

  
1074
	
1075
	
1037 1076
	/**
1038 1077
	 *
1039 1078
	 * @param nodePath
1040 1079
	 * @param key
1041 1080
	 * @return
1042 1081
	 */
1043
	public static float getFloat(String key, String nodePath)	{
1082
	public static float getFloat(String key, String nodePath) {
1044 1083
		return getFloat(key, null, nodePath);
1045 1084
	}
1046

  
1085
	
1047 1086
	/**
1048 1087
	 *
1049 1088
	 * @param result
1050 1089
	 * @param key
1051 1090
	 * @return
1052 1091
	 */
1053
	public static float getFloat(String key, TXMResult result)	{
1092
	public static float getFloat(String key, TXMResult result) {
1054 1093
		return getFloat(key, result, null);
1055 1094
	}
1056

  
1057

  
1095
	
1096
	
1058 1097
	/**
1059 1098
	 * Checks if a local node exists for the specified TXM result.
1099
	 * 
1060 1100
	 * @param result
1061 1101
	 * @return <code>true</code> if the node exists, otherwise <code>false</code>
1062 1102
	 */
1063
	public static boolean resultScopeNodeExists(TXMResult result)	{
1103
	public static boolean resultScopeNodeExists(TXMResult result) {
1064 1104
		// FIXME: SJ: this code seems to create the node but it shouldn't
1065 1105
		return preferencesRootNode.node(result.getParametersNodePath()) != null;
1066 1106
		// Try this one instead
1067
//		try {
1068
//			return preferencesRootNode.nodeExists(result.getParametersNodePath());
1069
//		}
1070
//		catch (BackingStoreException e) {
1071
//			// TODO Auto-generated catch block
1072
//			e.printStackTrace();
1073
//		}
1074
//		return false;
1107
		// try {
1108
		// return preferencesRootNode.nodeExists(result.getParametersNodePath());
1109
		// }
1110
		// catch (BackingStoreException e) {
1111
		// // TODO Auto-generated catch block
1112
		// e.printStackTrace();
1113
		// }
1114
		// return false;
1075 1115
	}
1076

  
1116
	
1077 1117
	/**
1078 1118
	 * 
1079 1119
	 * @param scope
......
1081 1121
	 * @param key
1082 1122
	 * @return
1083 1123
	 */
1084
	public static boolean keyExists(String nodePath, String key)	{
1124
	public static boolean keyExists(String nodePath, String key) {
1085 1125
		
1086
//		if (!nodePath.startsWith("/instance")) {
1087
//			nodePath = "/instance/" + nodePath;
1088
//		}
1089

  
1126
		// if (!nodePath.startsWith("/instance")) {
1127
		// nodePath = "/instance/" + nodePath;
1128
		// }
1090 1129
		
1091
		if(preferencesRootNode.node(nodePath) != null)	{
1130
		
1131
		if (preferencesRootNode.node(nodePath) != null) {
1092 1132
			try {
1093 1133
				return Arrays.asList(preferencesRootNode.node(nodePath).keys()).contains(key);
1094 1134
			}
1095
			catch(BackingStoreException e) {
1135
			catch (BackingStoreException e) {
1096 1136
				e.printStackTrace();
1097 1137
			}
1098 1138
		}
1099 1139
		return false;
1100 1140
	}
1101

  
1141
	
1102 1142
	/**
1103 1143
	 * Checks if a preference is defined as empty.
1104 1144
	 * Can be used to determine whatever a functionality is available or not by overriding the preference as empty.
1105 1145
	 * Essentially used for UI purpose, eg. to hide or disable a button that modify a preference.
1146
	 * 
1106 1147
	 * @param nodePath
1107 1148
	 * @param key
1108 1149
	 * @return
1109 1150
	 */
1110
	public static boolean isEmpty(String nodePath, String key)	{
1151
	public static boolean isEmpty(String nodePath, String key) {
1111 1152
		return getString(key, nodePath).equals("");
1112 1153
	}
1113

  
1114

  
1154
	
1155
	
1115 1156
	/**
1116 1157
	 * Sets a preference as empty.
1117 1158
	 * Can be used to determine whatever a functionality is available or not by overriding the preference as empty.
1118 1159
	 * Essentially used for UI purpose, eg. to hide or disable a button that modify a preference.
1160
	 * 
1119 1161
	 * @param nodePath
1120 1162
	 * @param key
1121 1163
	 */
1122
	public static void setEmpty(String nodePath, String key)	{
1164
	public static void setEmpty(String nodePath, String key) {
1123 1165
		if (!nodePath.startsWith("/instance")) {
1124 1166
			nodePath = "/instance/" + nodePath;
1125 1167
		}
1126 1168
		preferencesRootNode.node(nodePath).put(key, "");
1127 1169
	}
1128

  
1170
	
1129 1171
	/**
1130 1172
	 * Gets the default preference node of the initializer instance.
1173
	 * 
1131 1174
	 * @return
1132 1175
	 */
1133
	public IEclipsePreferences getDefaultPreferencesNode()	{
1176
	public IEclipsePreferences getDefaultPreferencesNode() {
1134 1177
		return DefaultScope.INSTANCE.getNode(this.commandPreferencesNodeQualifier);
1135 1178
	}
1136 1179
	
......
1140 1183
	public static String dumpToString(String nodePath) {
1141 1184
		StringBuilder sb = new StringBuilder();
1142 1185
		Preferences preferences = preferencesRootNode.node(nodePath);
1143

  
1186
		
1144 1187
		try {
1145 1188
			String[] keys = preferences.keys();
1146
			for(int i = 0; i < keys.length; i++) {
1147
				sb.append(keys[i] + " = " + preferences.get(keys[i], "")+"\t");
1189
			for (int i = 0; i < keys.length; i++) {
1190
				sb.append(keys[i] + " = " + preferences.get(keys[i], "") + "\t");
1148 1191
			}
1149 1192
		}
1150
		catch(BackingStoreException e) {
1193
		catch (BackingStoreException e) {
1151 1194
			// TODO Auto-generated catch block
1152 1195
			e.printStackTrace();
1153 1196
		}
......
1173 1216
				String[] subchildren = preferencesRootNode.node(children).childrenNames();
1174 1217
				Arrays.sort(subchildren);
1175 1218
				for (String children2 : subchildren) {
1176
					System.out.println(" scope: " + children + "  node: "+ children2); //$NON-NLS-1$
1219
					System.out.println(" scope: " + children + "  node: " + children2); //$NON-NLS-1$
1177 1220
					String[] keys = preferencesRootNode.node(children).node(children2).keys();
1178 1221
					Arrays.sort(keys);
1179 1222
					for (String key2 : keys) {
......
1181 1224
					}
1182 1225
				}
1183 1226
			}
1184
		} catch (Exception e) {
1185
			e.printStackTrace();;
1186 1227
		}
1228
		catch (Exception e) {
1229
			e.printStackTrace();
1230
			;
1231
		}
1187 1232
	}
1188

  
1233
	
1189 1234
	/**
1190 1235
	 * Dumps the keys and values of the specified node of the specified scope.
1236
	 * 
1191 1237
	 * @param nodePath
1192 1238
	 */
1193
	public static void dump(IScopeContext scope, String nodePath)	{
1239
	public static void dump(IScopeContext scope, String nodePath) {
1194 1240
		IEclipsePreferences preferences = scope.getNode(nodePath);
1195 1241
		System.out.println("TXMPreferences.dump(): ***************************************************************");
1196 1242
		System.out.println("TXMPreferences.dump(): node qualifier = " + nodePath);
1197 1243
		System.out.println("TXMPreferences.dump():" + preferences.absolutePath());
1198 1244
		try {
1199 1245
			String[] keys = preferences.keys();
1200
			for(int i = 0; i < keys.length; i++) {
1246
			for (int i = 0; i < keys.length; i++) {
1201 1247
				System.out.println("TXMPreferences.dump(): " + keys[i] + " = " + preferences.get(keys[i], ""));
1202 1248
			}
1203 1249
		}
1204
		catch(BackingStoreException e) {
1250
		catch (BackingStoreException e) {
1205 1251
			// TODO Auto-generated catch block
1206 1252
			e.printStackTrace();
1207 1253
		}
1208 1254
	}
1209

  
1210

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff