List of usage examples for java.util Locale toString
@Override public final String toString()
Locale
object, consisting of language, country, variant, script, and extensions as below: language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensionsLanguage is always lower case, country is always upper case, script is always title case, and extensions are always lower case.
From source file:org.apereo.portal.layout.dlm.remoting.ChannelListController.java
private ChannelBean getChannel(IPortletDefinition definition, WebRequest request, Locale locale) { ChannelBean channel = new ChannelBean(); channel.setId(definition.getPortletDefinitionId().getStringId()); channel.setDescription(definition.getDescription(locale.toString())); channel.setFname(definition.getFName()); channel.setName(definition.getName(locale.toString())); channel.setState(definition.getLifecycleState().toString()); channel.setTitle(definition.getTitle(locale.toString())); channel.setTypeId(definition.getType().getId()); // See api docs for postProcessIconUrlParameter() below IPortletDefinitionParameter iconParameter = definition.getParameter(ICON_URL_PARAMETER_NAME); if (iconParameter != null) { IPortletDefinitionParameter evaluated = postProcessIconUrlParameter(iconParameter, request); channel.setIconUrl(evaluated.getValue()); }/*from w w w .j a v a 2 s . c o m*/ return channel; }
From source file:org.codice.ddf.registry.api.impl.RegistryStoreImpl.java
private String getConnectionType(Bundle bundle, String pid) { if (connectionType != null) { return connectionType; }/*w ww . j a v a 2 s . c o m*/ Locale locale = Locale.getDefault(); if (bundle != null) { if (metaTypeService != null) { MetaTypeInformation mti = metaTypeService.getMetaTypeInformation(bundle); if (mti != null) { try { connectionType = mti.getObjectClassDefinition(pid, locale.toString()).getName(); return connectionType; } catch (IllegalArgumentException e) { LOGGER.debug("Unable to get connection type for registry configuration. ", e); return null; } } } } // fallback to nothing found return null; }
From source file:com.ichi2.anki.PreferenceContext.java
private void initializeLanguageDialog(PreferenceScreen screen) { ListPreference languageSelection = (ListPreference) screen.findPreference(LANGUAGE); if (languageSelection != null) { Map<String, String> items = new TreeMap<>(); for (String localeCode : LanguageUtil.APP_LANGUAGES) { Locale loc = LanguageUtil.getLocale(localeCode); items.put(loc.getDisplayName(), loc.toString()); }//w w w.ja va 2 s .c om CharSequence[] languageDialogLabels = new CharSequence[items.size() + 1]; CharSequence[] languageDialogValues = new CharSequence[items.size() + 1]; languageDialogLabels[0] = getResources().getString(R.string.language_system); languageDialogValues[0] = ""; int i = 1; for (Map.Entry<String, String> e : items.entrySet()) { languageDialogLabels[i] = e.getKey(); languageDialogValues[i] = e.getValue(); i++; } languageSelection.setEntries(languageDialogLabels); languageSelection.setEntryValues(languageDialogValues); } }
From source file:org.jahia.ajax.gwt.utils.GWTInitializer.java
public static String generateInitializerStructure(HttpServletRequest request, HttpSession session, Locale locale, Locale uilocale) { StringBuilder buf = new StringBuilder(); JahiaUser user = (JahiaUser) session.getAttribute(Constants.SESSION_USER); if (uilocale == null) { Locale sessionLocale = (Locale) session.getAttribute(Constants.SESSION_UI_LOCALE); JCRUserNode userNode = null;/* w w w . ja v a2 s . co m*/ if (user != null) { userNode = JahiaUserManagerService.getInstance().lookupUserByPath(user.getLocalPath()); } uilocale = sessionLocale != null ? UserPreferencesHelper.getPreferredLocale(userNode, sessionLocale) : UserPreferencesHelper.getPreferredLocale(userNode, LanguageCodeConverters.resolveLocaleForGuest(request)); } if (locale == null) { String language = request.getParameter("lang"); if (!StringUtils.isEmpty(language)) { locale = LanguageCodeConverters.getLocaleFromCode(language); } if (locale == null) { locale = (Locale) session.getAttribute(Constants.SESSION_LOCALE); } if (locale == null) { locale = Locale.ENGLISH; } } buf.append("<meta name=\"gwt:property\" content=\"locale=") .append(StringEscapeUtils.escapeXml(uilocale.toString())).append("\"/>"); addCss(buf, request, false); // creat parameters map Map<String, String> params = new HashMap<String, String>(); RenderContext renderContext = (RenderContext) request.getAttribute("renderContext"); String serviceEntrypoint = buildServiceBaseEntrypointUrl(request); params.put(JahiaGWTParameters.SERVICE_ENTRY_POINT, serviceEntrypoint); String contextPath = request.getContextPath(); params.put(JahiaGWTParameters.CONTEXT_PATH, contextPath); params.put(JahiaGWTParameters.SERVLET_PATH, (request.getAttribute("servletPath") == null) ? request.getServletPath() : (String) request.getAttribute("servletPath")); params.put(JahiaGWTParameters.PATH_INFO, request.getPathInfo()); params.put(JahiaGWTParameters.QUERY_STRING, request.getQueryString()); boolean devMode = SettingsBean.getInstance().isDevelopmentMode(); params.put(JahiaGWTParameters.DEVELOPMENT_MODE, devMode ? "true" : "false"); boolean areaAutoActivated = SettingsBean.getInstance().isAreaAutoActivated(); params.put(JahiaGWTParameters.AREA_AUTO_ACTIVATED, areaAutoActivated ? "true" : "false"); if (devMode) { params.put(JahiaGWTParameters.MODULES_SOURCES_DISK_PATH, StringEscapeUtils.escapeJavaScript(SettingsBean.getInstance().getModulesSourcesDiskPath())); } if (user != null) { String name = user.getUsername(); int index = name.indexOf(":"); if (index > 0) { String displayname = name.substring(0, index); params.put(JahiaGWTParameters.CURRENT_USER_NAME, displayname); } else { params.put(JahiaGWTParameters.CURRENT_USER_NAME, name); } params.put(JahiaGWTParameters.CURRENT_USER_PATH, user.getLocalPath()); } else { params.put(JahiaGWTParameters.CURRENT_USER_NAME, "guest"); params.put(JahiaGWTParameters.CURRENT_USER_PATH, "/users/guest"); } params.put(JahiaGWTParameters.LANGUAGE, locale.toString()); params.put(JahiaGWTParameters.LANGUAGE_DISPLAY_NAME, WordUtils.capitalizeFully(locale.getDisplayName(locale))); params.put(JahiaGWTParameters.UI_LANGUAGE, uilocale.toString()); params.put(JahiaGWTParameters.UI_LANGUAGE_DISPLAY_NAME, WordUtils.capitalizeFully(uilocale.getDisplayName(uilocale))); try { if (renderContext != null) { params.put(JahiaGWTParameters.WORKSPACE, renderContext.getMainResource().getWorkspace()); if (renderContext.getSite() != null) { params.put(JahiaGWTParameters.SITE_UUID, renderContext.getSite().getIdentifier()); params.put(JahiaGWTParameters.SITE_KEY, renderContext.getSite().getSiteKey()); } } else { if (request.getParameter("site") != null) { params.put(JahiaGWTParameters.SITE_UUID, StringEscapeUtils.escapeXml(request.getParameter("site"))); } if (request.getParameter("workspace") != null) { params.put(JahiaGWTParameters.WORKSPACE, request.getParameter("workspace")); } else { params.put(JahiaGWTParameters.WORKSPACE, "default"); } } } catch (RepositoryException e) { logger.error("Error when getting site id", e); } // put live workspace url if (request.getAttribute("url") != null) { URLGenerator url = (URLGenerator) request.getAttribute("url"); params.put(JahiaGWTParameters.BASE_URL, url.getContext() + url.getBase()); params.put(JahiaGWTParameters.STUDIO_URL, url.getContext() + url.getStudio()); params.put(JahiaGWTParameters.STUDIO_VISUAL_URL, url.getContext() + url.getStudioVisual()); addLanguageSwitcherLinks(renderContext, params, url); } else { params.put(JahiaGWTParameters.BASE_URL, contextPath + Render.getRenderServletPath() + "/" + params.get("workspace") + "/" + locale.toString()); } if (SettingsBean.getInstance().isUseWebsockets()) { params.put(JahiaGWTParameters.USE_WEBSOCKETS, "true"); } String customCkeditorConfig = getCustomCKEditorConfig(request, renderContext); if (customCkeditorConfig != null) { params.put("ckeCfg", customCkeditorConfig); } // add jahia parameter dictionary buf.append("<script type=\"text/javascript\">\n"); buf.append(getJahiaGWTConfig(params)); buf.append("\n</script>\n"); addJavaScript(buf, request, renderContext); return buf.toString(); }
From source file:org.jahia.services.search.spell.CompositeSpellChecker.java
/** * {@inheritDoc}//w w w. j a v a2 s . c o m */ public String check(QueryRootNode aqt) throws IOException { final Map<String, String> spellcheckInfo = new HashMap<String, String>(); try { aqt.accept(new TraversingQueryNodeVisitor() { public Object visit(RelationQueryNode node, Object data) throws RepositoryException { if (!spellcheckInfo.containsKey("statement") && node.getOperation() == RelationQueryNode.OPERATION_SPELLCHECK) { String spellCheckParams = node.getStringValue(); String[] s = spellCheckParams.split(SEPARATOR_IN_SUGGESTION); spellcheckInfo.put("statement", s[0]); spellcheckInfo.put("maxTermCount", StringUtils.substringAfter(s[1], MAX_TERMS_PARAM + "=")); if (s.length > 2) { spellcheckInfo.put("sites", StringUtils.substringAfter(s[2], SITES_PARAM + "=")); } } else if (!spellcheckInfo.containsKey("language") && node.getRelativePath() != null && node.getRelativePath().getNumOperands() > 0) { Name propertyName = ((LocationStepQueryNode) node.getRelativePath().getOperands()[0]) .getNameTest(); if ("language".equals(propertyName.getLocalName())) { spellcheckInfo.put("language", node.getStringValue()); } } return super.visit(node, data); } public Object visit(PathQueryNode node, Object data) throws RepositoryException { for (int i : new int[] { 0, 1 }) { if (node.getPathSteps().length > i + 1 && "sites".equals(node.getPathSteps()[i].getNameTest().getLocalName())) { spellcheckInfo.put("sites", node.getPathSteps()[++i].getNameTest().getLocalName()); } } return super.visit(node, data); } }, null); if (!spellcheckInfo.containsKey("statement")) { // no spellcheck operation in query return null; } if (!spellcheckInfo.containsKey("language")) { Locale locale = JCRSessionFactory.getInstance().getCurrentLocale(); if (locale != null) { spellcheckInfo.put("language", locale.toString()); } } } catch (RepositoryException e) { logger.debug("issue while checking " + aqt, e.getMessage()); } int maxTermCount = 1; String maxTermCountStr = spellcheckInfo.get("maxTermCount"); if (!StringUtils.isEmpty(maxTermCountStr) && StringUtils.isNumeric(maxTermCountStr)) { int parsedMaxTermCount = Integer.parseInt(maxTermCountStr); if (parsedMaxTermCount > 1) { maxTermCount = parsedMaxTermCount; } } return spellChecker.suggest(spellcheckInfo.get("statement"), StringUtils.split(spellcheckInfo.get("sites"), "*"), spellcheckInfo.get("language"), maxTermCount); }
From source file:com.vmware.identity.SsoController.java
/** * Handle SAML AuthnRequest for default tenant *//* ww w . ja va 2s . com*/ @RequestMapping(value = "/SAML2/SSO", method = { RequestMethod.GET, RequestMethod.POST }) public void ssoDefaultTenant(Locale locale, Model model, HttpServletRequest request, HttpServletResponse response) throws IOException { logger.info("Welcome to SP-initiated AuthnRequest handler! " + "The client locale is " + locale.toString() + ", DEFAULT tenant"); sso(locale, Shared.getDefaultTenant(), model, request, response); }
From source file:com.opoopress.maven.plugins.plugin.ThemeMojo.java
private void updateThemeConfigurationFile(ConfigImpl siteConfig, File themeDir) throws MojoFailureException { File config = new File(themeDir, "theme.yml"); if (!config.exists()) { throw new MojoFailureException("Config file '" + config + "' not exists."); }// w w w . j a v a 2s . com Locale loc = Locale.getDefault(); //locale from parameter String localeString = locale; //locale from site configuration if (StringUtils.isBlank(localeString)) { localeString = siteConfig.get("locale"); } if (StringUtils.isNotEmpty(localeString)) { loc = LocaleUtils.toLocale(localeString); } File localeConfig = new File(themeDir, "theme_" + loc.toString() + ".yml"); if (localeConfig.exists()) { config.renameTo(new File(themeDir, "theme-original.yml")); localeConfig.renameTo(config); } }
From source file:com.enonic.cms.business.portal.rendering.portalfunctions.PortalFunctions.java
public String getLocale() { ResolverContext resolverContext = new ResolverContext(request, context.getSite(), context.getMenuItem(), null);//from w w w .j av a 2 s . c o m Locale locale = localeResolverService.getLocale(resolverContext); if (locale == null) { return null; } return locale.toString(); }
From source file:org.codice.ddf.admin.core.impl.ConfigurationAdminImpl.java
/** * Return a display name for the given <code>bundle</code>: * * <ol>//from w ww .j ava2s .c o m * <li>If the bundle has a non-empty <code>Bundle-Name</code> manifest header that value is * returned. * <li>Otherwise the symbolic name is returned if set * <li>Otherwise the bundle's location is returned if defined * <li>Finally, as a last resort, the bundles id is returned * </ol> * * @param bundle the bundle which name to retrieve * @return the bundle name - see the description of the method for more details. */ public String getName(Bundle bundle) { Locale locale = Locale.getDefault(); final String loc = locale == null ? null : locale.toString(); String name = bundle.getHeaders(loc).get(Constants.BUNDLE_NAME); if (name == null || name.length() == 0) { name = bundle.getSymbolicName(); if (name == null) { name = bundle.getLocation(); if (name == null) { name = String.valueOf(bundle.getBundleId()); } } } return name; }
From source file:org.jahia.services.workflow.jbpm.JBPMMailProducer.java
public Collection<Message> produce(final Execution execution) { final Map<String, Object> vars = ((ExecutionImpl) execution).getVariables(); Locale locale = (Locale) vars.get("locale"); if (templateKey != null) { MailTemplate template = null;//from w w w . j a va 2 s .co m MailTemplateRegistry templateRegistry = ((ProcessEngine) SpringContextSingleton .getBean("processEngine")).get(MailTemplateRegistry.class); if (locale != null) { template = (templateRegistry.getTemplate(templateKey + "." + locale.toString())); if (template == null) { template = (templateRegistry.getTemplate(templateKey + "." + locale.getLanguage())); } } if (template == null) { template = templateRegistry.getTemplate(templateKey); } setTemplate(template); } if (ServicesRegistry.getInstance().getMailService().isEnabled() && getTemplate() != null) { try { return JCRTemplate.getInstance().doExecuteWithSystemSession(null, "default", locale, new JCRCallback<Collection<Message>>() { public Collection<Message> doInJCR(JCRSessionWrapper session) throws RepositoryException { try { scriptEngine = ScriptEngineUtils.getInstance() .getEngineByName(getTemplate().getLanguage()); bindings = null; Message email = instantiateEmail(); fillFrom(email, execution, session); fillRecipients(email, execution, session); fillSubject(email, execution, session); fillContent(email, execution, session); Address[] addresses = email.getRecipients(Message.RecipientType.TO); if (addresses != null && addresses.length > 0) { return Collections.singleton(email); } else { return Collections.emptyList(); } } catch (MessagingException e) { logger.error(e.getMessage(), e); } catch (ScriptException e) { logger.error(e.getMessage(), e); } return Collections.emptyList(); } }); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } } return Collections.emptyList(); }