Search in sources :

Example 1 with LocaleSetting

use of org.mifos.config.LocaleSetting in project head by mifos.

the class MifosInternationalizedHtmlTag method renderHtmlStartElement.

/**
     * Renders an <html> element with appropriate language attributes.
     * @since Struts 1.2
     */
@Override
protected String renderHtmlStartElement() {
    StringBuffer sb = new StringBuffer("<html");
    Locale locale = ApplicationContextProvider.getBean(PersonnelServiceFacade.class).getUserPreferredLocale();
    String languageCode = locale.getLanguage();
    String countryCode = locale.getCountry();
    LocaleSetting configLocale = new LocaleSetting();
    String direction = configLocale.getDirection();
    setLocaleIntoHttpSession(languageCode, countryCode);
    boolean validLanguage = ((languageCode != null) && (languageCode.length() > 0));
    boolean validCountry = countryCode.length() > 0;
    if (this.xhtml) {
        this.pageContext.setAttribute(Globals.XHTML_KEY, "true", PageContext.PAGE_SCOPE);
        sb.append(" xmlns=\"http://www.w3.org/1999/xhtml\"");
    }
    if ((this.lang || this.locale || this.xhtml) && validLanguage) {
        sb.append(" lang=\"");
        appendLangIfCountryIsValid(sb, languageCode, countryCode, validCountry);
    }
    if (this.xhtml && validLanguage) {
        sb.append(" xml:lang=\"");
        appendLangIfCountryIsValid(sb, languageCode, countryCode, validCountry);
    }
    appendLang(sb, languageCode);
    setDirection(sb, languageCode, direction);
    sb.append(">");
    return sb.toString();
}
Also used : Locale(java.util.Locale) LocaleSetting(org.mifos.config.LocaleSetting) PersonnelServiceFacade(org.mifos.application.admin.servicefacade.PersonnelServiceFacade)

Example 2 with LocaleSetting

use of org.mifos.config.LocaleSetting in project head by mifos.

the class ViewOrganizationSettingsServiceFacadeWebTier method getLocaleInfo.

private Properties getLocaleInfo() {
    LocaleSetting configLocale = new LocaleSetting();
    Properties localeInfo = new Properties();
    localeInfo.setProperty("localeCountryCode", configLocale.getCountryCode());
    localeInfo.setProperty("localeLanguageCode", configLocale.getLanguageCode());
    localeInfo.setProperty("localeDirection", configLocale.getDirection());
    return localeInfo;
}
Also used : LocaleSetting(org.mifos.config.LocaleSetting) Properties(java.util.Properties)

Example 3 with LocaleSetting

use of org.mifos.config.LocaleSetting in project head by mifos.

the class StandardTestingService method setLocale.

@Override
public void setLocale(String languageCode, String countryCode) throws MifosException {
    try {
        LocaleSetting configLocale = new LocaleSetting();
        configLocale.setLanguageCode(languageCode);
        configLocale.setCountryCode(countryCode);
        Localization localization = Localization.getInstance();
        localization.setConfigLocale(configLocale);
        if (SecurityContextHolder.getContext() != null) {
            if (SecurityContextHolder.getContext().getAuthentication() != null) {
                if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) {
                    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
                    user.setPreferredLocaleId(Localization.getInstance().getLocaleId(Localization.getInstance().getConfiguredLocale()));
                }
            }
        }
        StaticHibernateUtil.startTransaction();
        PersonnelBO p = (PersonnelBO) StaticHibernateUtil.getSessionTL().get(PersonnelBO.class, (short) 1);
        p.setPreferredLocale(Localization.getInstance().getConfiguredLocaleId());
        StaticHibernateUtil.getSessionTL().update(p);
        StaticHibernateUtil.commitTransaction();
        MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
        configMgr.setProperty("Localization.LanguageCode", languageCode);
        configMgr.setProperty("Localization.CountryCode", countryCode);
    } catch (MifosRuntimeException e) {
        throw new MifosException("The locale " + languageCode + "_" + countryCode + " is not supported by Mifos.");
    }
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosException(org.mifos.core.MifosException) LocaleSetting(org.mifos.config.LocaleSetting) MifosUser(org.mifos.security.MifosUser) Localization(org.mifos.config.Localization) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 4 with LocaleSetting

use of org.mifos.config.LocaleSetting in project head by mifos.

the class ApplicationInitializer method setAttributesOnContext.

public void setAttributesOnContext(ServletContext servletContext) throws TaskSystemException {
    // FIXME: replace with Spring-managed beans
    final MifosScheduler mifosScheduler = new MifosScheduler();
    final ShutdownManager shutdownManager = new ShutdownManager();
    Configuration.getInstance();
    configureAuditLogValues(Localization.getInstance().getConfiguredLocale());
    LocaleSetting configLocale = new LocaleSetting();
    @SuppressWarnings("deprecation") final UserLocale userLocale = new UserLocale(ApplicationContextProvider.getBean(PersonnelServiceFacade.class));
    if (servletContext != null) {
        mifosScheduler.initialize();
        servletContext.setAttribute(MifosScheduler.class.getName(), mifosScheduler);
        servletContext.setAttribute(ShutdownManager.class.getName(), shutdownManager);
        servletContext.setAttribute(LocaleSetting.class.getSimpleName(), configLocale);
        servletContext.setAttribute(UserLocale.class.getSimpleName(), userLocale);
    }
}
Also used : LocaleSetting(org.mifos.config.LocaleSetting) ShutdownManager(org.mifos.application.admin.system.ShutdownManager) PersonnelServiceFacade(org.mifos.application.admin.servicefacade.PersonnelServiceFacade) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler) UserLocale(org.mifos.config.UserLocale)

Aggregations

LocaleSetting (org.mifos.config.LocaleSetting)4 PersonnelServiceFacade (org.mifos.application.admin.servicefacade.PersonnelServiceFacade)2 Locale (java.util.Locale)1 Properties (java.util.Properties)1 ShutdownManager (org.mifos.application.admin.system.ShutdownManager)1 Localization (org.mifos.config.Localization)1 UserLocale (org.mifos.config.UserLocale)1 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)1 MifosException (org.mifos.core.MifosException)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 MifosScheduler (org.mifos.framework.components.batchjobs.MifosScheduler)1 MifosUser (org.mifos.security.MifosUser)1