/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2015 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */

package org.geomajas.gwt.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.LocaleInfo;
import org.geomajas.annotation.Api;
import org.geomajas.gwt.client.i18n.VersionMessages;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * Global settings for the Geomajas GWT face.
 * </p>
 * 
 * @author Pieter De Graef
 * @since 1.6.0
 */
@Api(allMethods = true)
public final class Geomajas {

	private static final VersionMessages MESSAGES = GWT.create(VersionMessages.class);

	private Geomajas() {
		// do not allow instantiation.
	}

	/**
	 * Returns the current version of Geomajas as a string.
	 *
	 * @return Geomajas version
	 */
	public static String getVersion() {
		return MESSAGES.version();
	}

	/**
	 * Returns a list of locales that can be used in this version of Geomajas. The default is english, and 'native'
	 * means that your browsers locale should be used (if supported - default otherwise).
	 *
	 * @return supported locales
	 */
	public static Map<String, String> getSupportedLocales() {
		Map<String, String> locales = new HashMap<String, String>();
		for (String localeName : LocaleInfo.getAvailableLocaleNames()) {
			String displayName = LocaleInfo.getLocaleNativeDisplayName(localeName);
			locales.put(localeName, displayName);
		}
		return locales;
	}

	/**
	 * Return the base directory for the web application.
	 * 
	 * @return base directory for application for SmartGWT
	 */
	public static native String getIsomorphicDir()
	/*-{
		return $wnd.isomorphicDir;
	}-*/;
	
	/**
	 * Return the Spring dispatcher URL for the web application. The URL ends with a slash.
	 * 
	 * @return the dispatcher URL
	 * @since 1.10.0
	 */
	public static String getDispatcherUrl() {
		String moduleBaseUrl = GWT.getModuleBaseURL();
		// remove last slash
		moduleBaseUrl = moduleBaseUrl.substring(0, moduleBaseUrl.length() - 1);
		// replace module part by /d
		int contextEndIndex = moduleBaseUrl.lastIndexOf("/");
		if (contextEndIndex > 6) {
			return moduleBaseUrl.substring(0, contextEndIndex) + "/d/";
		} else {
			// fall back to module base URL
			return GWT.getModuleBaseURL();
		}
	}

}
@@ -767,16 +767,43 @@
 e Graef%0A
+ * @author Jan Venstermans%0A
  * @sinc
@@ -954,16 +954,55 @@
 lass);%0A%0A
+%09private static String dispatcherUrl;%0A%0A
 %09private
@@ -2211,16 +2211,514 @@
 Url() %7B%0A
+%09%09if (dispatcherUrl == null) %7B%0A%09%09%09dispatcherUrl = getModuleBaseDispatcherUrl();%0A%09%09%7D%0A%09%09return dispatcherUrl;%0A%09%7D%0A%0A%09/**%0A%09 * Set the Spring dispatcher URL. The URL should ends with a slash.%0A%09 *%0A%09 * @param dispatcherUrl url to desired dispatcher%0A%09 * @since 1.16.0%0A%09 */%0A%09public static void setDispatcherUrl(String dispatcherUrl) %7B%0A%09%09Geomajas.dispatcherUrl = dispatcherUrl;%0A%09%7D%0A%0A%09/**%0A%09 *%0A%09 * @return dispatcher ur based on GWT.getModuleBaseURL().%0A%09 */%0A%09private static String getModuleBaseDispatcherUrl() %7B%0A
 %09%09String

Allow custom configuration of dispatcherUrl of org.geomajas.gwt.client.Geomajas util class