/*
 * This file is part of DebGen Biobank Software developed by ASTRID Research.
 * All rights reserved. Reproduction, modification, use or disclosure
 * to third parties without express authority is forbidden.
 *
 * Copyright ASTRID Research Inc., Hungary, 2009-2011.
 *
 * ASTRID Research
 * Headquaters: Csapo utca 42. Debrecen H-4029 HUNGARY
 * Phone: +36-52-533-173        Fax: +36-52-533-174
 * Web: http://www.astrid.hu    E-mail: info@astrid.hu
 *
 * Project name: DebGen Biobank Software project.
 * URLS:
 * Developers: Istvan Zoltan Nagy (istvan.nagy@astrid.hu)
 */
package hu.astrid.debgen.server.startup;

import hu.astrid.debgen.localization.service.LocalizationService;

/**
 * Returns the applications parameters set in the web.xml
 * @author inagy
 */
public class ApplicationParameters {

    /**
     * The name of the application
     */
    static String applicationName;
    /**
     * The URL of the application
     */
    static String applicationURL;
    /**
     * The URI of the application
     */
    static String applicationURI;
    /**
     * The locale ISO Code of the application
     */
    static String localeIsoCode;
    /**
     * The language code of the application
     */
    static String language;

    /**
     * Sets the applications name
     * @param applicationName The new name
     */
    public static void setApplicationName(String applicationName) {
        ApplicationParameters.applicationName = applicationName.toUpperCase().replaceAll(" ", "_");
    }

    /**
     * Sets the applications URL
     * @param applicationURL The new URL
     */
    public static void setApplicationURL(String applicationURL) {
        ApplicationParameters.applicationURL = applicationURL;
    }

    /**
     * Sets the applications URI
     * @param applicationURI The new URI
     */
    public static void setApplicationURI(String applicationURI) {
        ApplicationParameters.applicationURI = applicationURI;
    }

    /**
     * Sets the applications language
     * @param language The new language
     */
    public static void setLanguage(String language) {
        ApplicationParameters.language = language;
    }

    /**
     * Sets the applications locale ISO code
     * @param localeIsoCode The new ISO code
     */
    public static void setLocaleIsoCode(String localeIsoCode) {
        ApplicationParameters.localeIsoCode = localeIsoCode;
    }

    public static String getApplicationName() {
        return new LocalizationService().getMessage(applicationName);
    }

    public static String getApplicationURL() {
        return applicationURL;
    }

    public static String getApplicationURI() {
        return applicationURI;
    }

    public static String getLanguageCode() {
        return ApplicationParameters.language;
    }

    /**
     * Sets the language to default (useful when the specified language can't be find) 
     */
    static void fallbackToDefaultLanguage() {
        language = "hun";
        localeIsoCode = "HU";
    }

    public static String getLocaleIsoCode() {
        return localeIsoCode;
    }

    public String getIsoCode() {
        return localeIsoCode;
    }

    public String getLanguage() {
        return language;
    }

    public ApplicationParameters() {
    }

    public String getThisApplicationName() {
        return applicationName;
    }
}
