Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/Config.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/Config.java@d81533df4138 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client; | |
2 | |
3 import com.google.gwt.i18n.client.LocaleInfo; | |
4 | |
5 import com.google.gwt.xml.client.Document; | |
6 import com.google.gwt.xml.client.Node; | |
7 | |
8 | |
9 /** | |
10 * A class that is used to handle the global configuration of this client. You | |
11 * can retrieve an instance of this class using the <code>getInstance</code> | |
12 * methods. <b>NOTE:</b> the configuration is initialized using {@link | |
13 * getInstance(Document)} the first time. | |
14 * | |
15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
16 */ | |
17 public class Config { | |
18 | |
19 /** The instance of the configuration. */ | |
20 protected static Config INSTANCE; | |
21 | |
22 /** The xml document that contains the configuration options. */ | |
23 protected Document config; | |
24 | |
25 | |
26 /** | |
27 * Get an instance by using {@link getInstance(Document)} or {@link | |
28 * getInstance()}. | |
29 */ | |
30 private Config(Document config) { | |
31 this.config = config; | |
32 } | |
33 | |
34 | |
35 /** | |
36 * Returns an instance of this class and initializes the configuration of | |
37 * this has not been done so far. | |
38 * | |
39 * @param config The client configuration. | |
40 * | |
41 * @return an instance of this Config class. | |
42 */ | |
43 public static Config getInstance(Document config) { | |
44 if (INSTANCE == null) { | |
45 INSTANCE = new Config(config); | |
46 } | |
47 | |
48 return INSTANCE; | |
49 } | |
50 | |
51 | |
52 /** | |
53 * Returns an instance of this class. If it has not been initialized with a | |
54 * valid configuration, null is returned. | |
55 * | |
56 * @return an instance of this class or null, if the Config has not been | |
57 * initialized using {@link getInstance(Document)} so far. | |
58 */ | |
59 public static Config getInstance() { | |
60 return INSTANCE; | |
61 } | |
62 | |
63 | |
64 /** | |
65 * Returns the URL of the artifact server. | |
66 * | |
67 * @return the artifact server url. | |
68 */ | |
69 public String getServerUrl() { | |
70 Node server = config.getElementsByTagName("server").item(0); | |
71 return server.getFirstChild().getNodeValue(); | |
72 } | |
73 | |
74 | |
75 /** | |
76 * Returns the name of the current locale. | |
77 * | |
78 * @return the name of the current locale. | |
79 */ | |
80 public String getLocale() { | |
81 return LocaleInfo.getCurrentLocale().getLocaleName(); | |
82 } | |
83 | |
84 | |
85 /** | |
86 * Returns the integer configured at | |
87 * <i>/config/projectlist/update-interval/text()</i> or -1 if an error | |
88 * occured or no such option is defined. | |
89 * | |
90 * @return the update interval of the project list. | |
91 */ | |
92 public int getProjectListUpdateInterval() { | |
93 Node projectlist = config.getElementsByTagName("projectlist").item(0); | |
94 | |
95 if (projectlist == null) { | |
96 return -1; | |
97 } | |
98 | |
99 Node interval = config.getElementsByTagName("update-interval").item(0); | |
100 | |
101 if (interval == null) { | |
102 return -1; | |
103 } | |
104 | |
105 String value = interval.getFirstChild().getNodeValue(); | |
106 | |
107 return value != null ? Integer.valueOf(value) : -1; | |
108 } | |
109 } | |
110 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |