/** * @return first locale from the list defined in {@code cuba.availableLocales} app property, taking into * account {@link #useLocaleLanguageOnly()} return value. */ public Locale getDefaultLocale() { if (globalConfig.getAvailableLocales().isEmpty()) throw new DevelopmentException("Invalid cuba.availableLocales application property"); return globalConfig.getAvailableLocales().entrySet().iterator().next().getValue(); }
@Inject public void setConfiguration(Configuration configuration) { globalConfig = configuration.getConfig(GlobalConfig.class); confDir = globalConfig.getConfDir().replaceAll("\\\\", "/"); }
protected String getPortalNetworkLocation() { return globalConfig.getWebHostName() + ":" + globalConfig.getWebPort() + "/" + globalConfig.getWebContextName(); }
protected String getHost() { return globalConfig.getWebHostName() + ":" + globalConfig.getWebPort(); }
protected String resolveServerPrefix(String uri) { Configuration configStorage = AppBeans.get(Configuration.NAME); GlobalConfig globalConfig = configStorage.getConfig(GlobalConfig.class); String coreUrl = String.format("http://%s:%s/%s/", globalConfig.getWebHostName(), globalConfig.getWebPort(), globalConfig.getWebContextName()); String webUrl = globalConfig.getWebAppUrl() + "/"; return uri.replace(WEB_APP_PREFIX, webUrl).replace(CORE_APP_PREFIX, coreUrl); }
@GetMapping(value = "/locales", produces = "application/json; charset=UTF-8") @ResponseBody public LocalesInfo getLocales() { LocalesInfo localesInfo = new LocalesInfo(); localesInfo.setLocaleSelectVisible(globalConfig.getLocaleSelectVisible()); Map<String, String> locales = new LinkedHashMap<>(); for (Map.Entry<String, Locale> entry : globalConfig.getAvailableLocales().entrySet()) { locales.put(entry.getValue().toLanguageTag(), entry.getKey()); } localesInfo.setLocales(locales); return localesInfo; }
if (!checkCompleted) { GlobalConfig config = AppBeans.get(Configuration.class).getConfig(GlobalConfig.class); if (config.getLogIncorrectWebAppPropertiesEnabled()) { StringBuilder sb = new StringBuilder(); if (!request.getServerName().equals(config.getWebHostName())) { sb.append("***** cuba.webHostName=").append(config.getWebHostName()) .append(", actual=").append(request.getServerName()).append("\n"); if (request.getServerPort() != Integer.parseInt(config.getWebPort())) { sb.append("***** cuba.webPort=").append(config.getWebPort()) .append(", actual=").append(request.getServerPort()).append("\n"); if (contextPath.startsWith("/")) contextPath = contextPath.substring(1); if (!contextPath.equals(config.getWebContextName())) { sb.append("***** cuba.webContextName=").append(config.getWebContextName()) .append(", actual=").append(contextPath).append("\n");
protected String getWebAppName(GlobalConfig config) { return config.getWebContextName(); }
@Inject public JavaClassLoader(Configuration configuration) { super(new URL[0], Thread.currentThread().getContextClassLoader()); this.proxyClassLoader = new ProxyClassLoader(Thread.currentThread().getContextClassLoader(), compiled); GlobalConfig config = configuration.getConfig(GlobalConfig.class); this.rootDir = config.getConfDir() + "/"; this.cubaClassPath = config.getCubaClasspathDirectories(); this.classPath = buildClasspath(); this.sourceProvider = new SourceProvider(rootDir); }
/** * @param path path relative to the root of webapp * @return Full absolute path including protocol, domain and webapp prefix */ public String composeFullAbsolutePath(String path) { String webAppUrl = configuration.getConfig(GlobalConfig.class).getWebAppUrl(); webAppUrl = StringUtils.chomp(webAppUrl, "/"); //remove last slash return path.startsWith("/") ? webAppUrl.concat(path) : webAppUrl.concat("/").concat(path); }
@Inject public void setConfiguration(Configuration configuration) { tempDir = configuration.getConfig(GlobalConfig.class).getTempDir(); }
@Deprecated protected void copyParamsToCredentials(Map<String, Object> params, AbstractClientCredentials credentials) { // for compatibility only Object clientType = params.get(ClientType.class.getName()); if (clientType != null && credentials.getClientType() == null) { credentials.setClientType(ClientType.valueOf((String) clientType)); } Object clientInfo = params.get(SessionParams.CLIENT_INFO.getId()); if (clientInfo != null && credentials.getClientInfo() == null) { credentials.setClientInfo((String) clientInfo); } Object ipAddress = params.get(SessionParams.IP_ADDRESS.getId()); if (ipAddress != null && credentials.getIpAddress() == null) { credentials.setIpAddress((String) ipAddress); } Object hostName = params.get(SessionParams.HOST_NAME.getId()); if (hostName != null) { credentials.setHostName((String) hostName); } if (!globalConfig.getLocaleSelectVisible()) { credentials.setOverrideLocale(false); } } }
protected Locale resolveLocale(@Nullable Locale requestLocale) { Map<String, Locale> locales = globalConfig.getAvailableLocales(); if (globalConfig.getLocaleSelectVisible()) { String lastLocale = getCookieValue(COOKIE_LOCALE); if (lastLocale != null) { for (Locale locale : locales.values()) { if (locale.toLanguageTag().equals(lastLocale)) { return locale; } } } } if (requestLocale != null) { Locale requestTrimmedLocale = messageTools.trimLocale(requestLocale); if (locales.containsValue(requestTrimmedLocale)) { return requestTrimmedLocale; } // if not found and application locale contains country, try to match by language only if (!StringUtils.isEmpty(requestLocale.getCountry())) { Locale appLocale = Locale.forLanguageTag(requestLocale.getLanguage()); for (Locale locale : locales.values()) { if (Locale.forLanguageTag(locale.getLanguage()).equals(appLocale)) { return locale; } } } } // return default locale return messageTools.getDefaultLocale(); }
protected String getAppName() { return config.getWebContextName(); }
@Override public String getNodeName() { Configuration configuration = AppBeans.get(Configuration.NAME); GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class); return globalConfig.getWebHostName() + ":" + globalConfig.getWebPort(); } }
public static String getControllerURL(String mapping) { if (mapping == null) throw new IllegalArgumentException("Mapping cannot be null"); Configuration configuration = AppBeans.get(Configuration.NAME); GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class); StringBuilder sb = new StringBuilder(globalConfig.getWebAppUrl()).append(getControllerPrefix()); if (!mapping.startsWith("/")) { sb.append("/"); } sb.append(mapping); return sb.toString(); }
@Inject public void setConfiguration(Configuration configuration) { tempDir = configuration.getConfig(GlobalConfig.class).getTempDir(); }
@Deprecated protected void copyParamsToCredentials(Map<String, Object> params, AbstractClientCredentials credentials) { // for compatibility only Object clientType = params.get(ClientType.class.getName()); if (clientType != null) { credentials.setClientType(ClientType.valueOf((String) clientType)); } Object clientInfo = params.get(SessionParams.CLIENT_INFO.getId()); if (clientInfo != null) { credentials.setClientInfo((String) clientInfo); } Object ipAddress = params.get(SessionParams.IP_ADDRESS.getId()); if (ipAddress != null) { credentials.setIpAddress((String) ipAddress); } Object hostName = params.get(SessionParams.HOST_NAME.getId()); if (hostName != null) { credentials.setHostName((String) hostName); } if (!globalConfig.getLocaleSelectVisible()) { credentials.setOverrideLocale(false); } RemoteClientInfo remoteClientInfo = RemoteClientInfo.get(); if (remoteClientInfo != null) { String address = remoteClientInfo.getAddress(); if (!trustedLoginHandler.checkAddress(address)) { credentials.setIpAddress(address); } } }
protected String makeClientInfo(String userAgent) { //noinspection UnnecessaryLocalVariable String serverInfo = String.format("REST API (%s:%s/%s) %s", globalConfig.getWebHostName(), globalConfig.getWebPort(), globalConfig.getWebContextName(), StringUtils.trimToEmpty(userAgent)); return serverInfo; }
protected Locale localeFromString(String localeStr) { return StringUtils.isBlank(localeStr) ? globalConfig.getAvailableLocales().values().iterator().next() : LocaleUtils.toLocale(localeStr); }