Search in sources :

Example 16 with GlobalConfig

use of com.haulmont.cuba.core.global.GlobalConfig in project cuba by cuba-platform.

the class SiteSettings method getFreeMarkerSettings.

public Properties getFreeMarkerSettings() {
    GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
    Map<String, Locale> availableLocales = globalConfig.getAvailableLocales();
    if (availableLocales.isEmpty()) {
        throw new IllegalStateException("Property cuba.availableLocales is not configured");
    }
    Locale locale = availableLocales.values().iterator().next();
    FormatStrings formatStrings = formatStringsRegistry.getFormatStrings(locale);
    final Properties freemarkerSettings = new Properties();
    freemarkerSettings.setProperty("number_format", "#");
    freemarkerSettings.setProperty("datetime_format", formatStrings.getDateTimeFormat());
    freemarkerSettings.setProperty("date_format", formatStrings.getDateFormat());
    freemarkerSettings.setProperty("template_exception_handler", "rethrow");
    return freemarkerSettings;
}
Also used : Locale(java.util.Locale) GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) FormatStrings(com.haulmont.chile.core.datatypes.FormatStrings) Properties(java.util.Properties)

Example 17 with GlobalConfig

use of com.haulmont.cuba.core.global.GlobalConfig in project cuba by cuba-platform.

the class CubaUIProvider method getTheme.

@Override
public String getTheme(UICreateEvent event) {
    // get theme from cookies before app ui initialized for smooth theme enabling
    WebConfig webConfig = configuration.getConfig(WebConfig.class);
    GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
    String appWindowTheme = webConfig.getAppWindowTheme();
    String userAppTheme = getCookieValue(event.getRequest().getCookies(), App.APP_THEME_COOKIE_PREFIX + globalConfig.getWebContextName());
    if (userAppTheme != null) {
        if (!Objects.equals(userAppTheme, appWindowTheme)) {
            // check theme support
            ThemeConstantsRepository themeRepository = AppBeans.get(ThemeConstantsRepository.NAME);
            Set<String> supportedThemes = themeRepository.getAvailableThemes();
            if (supportedThemes.contains(userAppTheme)) {
                return userAppTheme;
            }
        }
    }
    return super.getTheme(event);
}
Also used : GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) ThemeConstantsRepository(com.haulmont.cuba.gui.theme.ThemeConstantsRepository) WebConfig(com.haulmont.cuba.web.WebConfig)

Aggregations

GlobalConfig (com.haulmont.cuba.core.global.GlobalConfig)17 Configuration (com.haulmont.cuba.core.global.Configuration)7 Locale (java.util.Locale)2 FormatStrings (com.haulmont.chile.core.datatypes.FormatStrings)1 ClientType (com.haulmont.cuba.core.global.ClientType)1 ThemeConstantsRepository (com.haulmont.cuba.gui.theme.ThemeConstantsRepository)1 WebConfig (com.haulmont.cuba.web.WebConfig)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Constructor (java.lang.reflect.Constructor)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Properties (java.util.Properties)1 UUID (java.util.UUID)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1