teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
teichmann@5861: * Software engineering by Intevation GmbH
teichmann@5861: *
teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3)
teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the
teichmann@5993: * documentation coming with Dive4Elements River for details.
teichmann@5861: */
teichmann@5861:
teichmann@5835: package org.dive4elements.river.client.client;
ingo@9:
ingo@229: import com.google.gwt.i18n.client.LocaleInfo;
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:
felix@1347: /** The xml document that contains the configuration options. */
ingo@9: protected Document config;
ingo@9:
christian@6479: protected String helpUrl;
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: /**
christian@6418: * Returns the URL of the FLYS/d4e-Wiki.
christian@6418: *
christian@6418: * @return wiki base URL
christian@6418: */
christian@6418: public String getWikiUrl() {
christian@6479: return this.helpUrl;
christian@6479: }
christian@6479:
christian@6479: public void setWikiUrl(String url) {
christian@6479: this.helpUrl = url;
christian@6418: }
christian@6418:
christian@6418:
christian@6418: /**
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@585:
andre@8503: public boolean getHideLogout() {
andre@8503: Node hide_logout = config.getElementsByTagName("hide-logout").item(0);
andre@8503: if (hide_logout == null) {
andre@8503: return false;
andre@8503: }
andre@8503: String value = hide_logout.getFirstChild().getNodeValue();
andre@8503: return value.toLowerCase().equals("true");
andre@8503: }
ingo@585:
ingo@585: /**
ingo@585: * Returns the integer configured at
ingo@585: * /config/projectlist/update-interval/text() or -1 if an error
ingo@585: * occured or no such option is defined.
ingo@585: *
ingo@585: * @return the update interval of the project list.
ingo@585: */
ingo@585: public int getProjectListUpdateInterval() {
ingo@585: Node projectlist = config.getElementsByTagName("projectlist").item(0);
ingo@585:
ingo@585: if (projectlist == null) {
ingo@585: return -1;
ingo@585: }
ingo@585:
ingo@585: Node interval = config.getElementsByTagName("update-interval").item(0);
ingo@585:
ingo@585: if (interval == null) {
ingo@585: return -1;
ingo@585: }
ingo@585:
ingo@585: String value = interval.getFirstChild().getNodeValue();
ingo@585:
ingo@585: return value != null ? Integer.valueOf(value) : -1;
ingo@585: }
ingo@9: }
ingo@9: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :