ingo@9: package de.intevation.flys.client.client;
ingo@9:
ingo@229: import com.google.gwt.i18n.client.LocaleInfo;
ingo@229:
ingo@9: import com.google.gwt.xml.client.Document;
ingo@9: import com.google.gwt.xml.client.Node;
ingo@9:
ingo@9:
ingo@9: /**
ingo@9: * A class that is used to handle the global configuration of this client. You
ingo@9: * can retrieve an instance of this class using the getInstance
ingo@9: * methods. NOTE: the configuration is initialized using {@link
ingo@9: * getInstance(Document)} the first time.
ingo@9: *
ingo@9: * @author Ingo Weinzierl
ingo@9: */
ingo@9: public class Config {
ingo@9:
ingo@9: /** The instance of the configuration. */
ingo@9: protected static Config INSTANCE;
ingo@9:
ingo@9: /** The xml document that contains the configuration options.*/
ingo@9: protected Document config;
ingo@9:
ingo@9:
ingo@9: /**
ingo@9: * Get an instance by using {@link getInstance(Document)} or {@link
ingo@9: * getInstance()}.
ingo@9: */
ingo@9: private Config(Document config) {
ingo@9: this.config = config;
ingo@9: }
ingo@9:
ingo@9:
ingo@9: /**
ingo@9: * Returns an instance of this class and initializes the configuration of
ingo@9: * this has not been done so far.
ingo@9: *
ingo@9: * @param config The client configuration.
ingo@9: *
ingo@9: * @return an instance of this Config class.
ingo@9: */
ingo@9: public static Config getInstance(Document config) {
ingo@9: if (INSTANCE == null) {
ingo@9: INSTANCE = new Config(config);
ingo@9: }
ingo@9:
ingo@9: return INSTANCE;
ingo@9: }
ingo@9:
ingo@9:
ingo@9: /**
ingo@9: * Returns an instance of this class. If it has not been initialized with a
ingo@9: * valid configuration, null is returned.
ingo@9: *
ingo@9: * @return an instance of this class or null, if the Config has not been
ingo@9: * initialized using {@link getInstance(Document)} so far.
ingo@9: */
ingo@9: public static Config getInstance() {
ingo@9: return INSTANCE;
ingo@9: }
ingo@9:
ingo@9:
ingo@9: /**
ingo@9: * Returns the URL of the artifact server.
ingo@9: *
ingo@9: * @return the artifact server url.
ingo@9: */
ingo@9: public String getServerUrl() {
ingo@9: Node server = config.getElementsByTagName("server").item(0);
ingo@9: return server.getFirstChild().getNodeValue();
ingo@9: }
ingo@229:
ingo@229:
ingo@229: /**
ingo@229: * Returns the name of the current locale.
ingo@229: *
ingo@229: * @return the name of the current locale.
ingo@229: */
ingo@229: public String getLocale() {
ingo@229: return LocaleInfo.getCurrentLocale().getLocaleName();
ingo@229: }
ingo@9: }
ingo@9: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :