source: main/trunk/greenstone3/src/java/org/greenstone/util/Configuration.java@ 25635

Last change on this file since 25635 was 25635, checked in by sjm84, 12 years ago

Fixing Greenstone 3's use (or lack thereof) of generics, this was done automatically so we may want to change it over time. This change will also auto-format any files that have not already been formatted.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/**
2 *#########################################################################
3 * Configuration
4 * A component of the GAI application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * <BR><BR>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * <BR><BR>
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * <BR><BR>
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *########################################################################
32 */
33package org.greenstone.util;
34
35import java.awt.Color;
36import java.util.Locale;
37import java.util.Hashtable;
38import java.util.StringTokenizer;
39
40// eventually this class will hold configuration settings from a config file. For now, lets use static info
41// loosely copied from Gatherer Configuration
42public class Configuration {
43
44 static private Hashtable<String, String> hash = null;
45
46 /** The first of three patterns used during tokenization, this pattern handles a comma separated list. */
47 static final private String TOKENIZER_PATTERN1 = " ,\n\t";
48 /** The second of three patterns used during tokenization, this pattern handles an underscore separated list. */
49 static final private String TOKENIZER_PATTERN2 = "_\n\t";
50 /** The last of three patterns used during tokenization, this pattern handles an comma separated list containing spaces. */
51 static final private String TOKENIZER_PATTERN3 = ",\n\t";
52
53 public Configuration() {
54
55 hash = new Hashtable<String, String>();
56
57
58 // load up all the initial stuff
59 hash.put("admin.log", "true");
60 hash.put("admin.conf", "true");
61 hash.put("admin.ext", "true");
62 hash.put("admin.monitor", "true");
63 hash.put("coloring.workspace_selection_foreground", "0, 0, 0");
64 hash.put("coloring.workspace_selection_background", "176, 208, 176");
65 hash.put("coloring.table_noneditable_background", "255, 255, 255");
66 hash.put("coloring.table_editable_background", "255, 255, 255");
67 hash.put("coloring.collection_tree_background", "224, 240, 224");
68 hash.put("coloring.collection_tree_foreground", "0, 0, 0");
69 hash.put("coloring.workspace_tree_foreground", "0, 0, 0");
70 hash.put("coloring.workspace_tree_background", "218, 237, 252");
71 hash.put("coloring.workspace_heading_background", "128, 180, 216");
72 hash.put("coloring.workspace_heading_foreground", "0, 0, 0");
73
74 }
75
76 /** Retrieve whether the named property is set or not */
77 static public boolean get(String property) {
78 String value = hash.get(property);
79 return (value != null && value.equalsIgnoreCase("true"));
80 }
81
82 /** Retrieve the value of the named property as a String */
83 static public String getString(String property) {
84 return hash.get(property);
85 }
86
87 /** Retrieve the value of the named property as a Locale. */
88 static public Locale getLocale(String property) {
89 Locale result = Locale.getDefault();
90 try {
91 String raw = hash.get(property);
92 if (raw==null) {
93 return result;
94 }
95 // Locale is a underscore separated code.
96 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN2);
97 String language = tokenizer.nextToken();
98 if(tokenizer.hasMoreTokens()) {
99 String country = tokenizer.nextToken();
100 result = new Locale(language, country);
101 }
102 else {
103 result = new Locale(language);
104 }
105 }
106 catch(Exception error) {
107 error.printStackTrace();
108 }
109 return result;
110 }
111
112 /** Retrieve the value of the named property as a Color. */
113 static public Color getColor(String property) {
114 Color result = Color.white; // Default
115 String raw = hash.get(property);
116 if (raw == null || raw.equals("")) {
117 return result;
118 }
119 try {
120 // Color is a RGB triplet list, comma separated (also remove whitespace)
121 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN1);
122 int red = Integer.parseInt(tokenizer.nextToken());
123 int green = Integer.parseInt(tokenizer.nextToken());
124 int blue = Integer.parseInt(tokenizer.nextToken());
125 result = new Color(red, green, blue);
126 }
127 catch(Exception error) {
128 error.printStackTrace();
129 }
130 return result;
131 }
132}
Note: See TracBrowser for help on using the repository browser.