List of usage examples for java.util Locale getDisplayName
public final String getDisplayName()
From source file:org.diorite.cfg.messages.MessageLoader.java
private Locale getLocale(final String str) { final Locale locale = Locale.forLanguageTag(str); if (locale.getDisplayName().isEmpty()) { return new Locale(str); }/* w w w . j a va 2 s . c o m*/ return locale; }
From source file:org.tolven.restful.AccountResourcesV0.java
/** * Create a new Tolven account/* w w w .j a v a 2 s .c o m*/ * Parameters include attributes of account object. * Parameters can also include account properties. * The initialUser must be specified. This user will have the account adminitrator permission * and will be the user capable of "inviting" other users to the account. * The response status code will be "created" if the account was created. * The location url will contain the account id. */ @Path("create") @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Deprecated public Response createAccount(@FormParam("accountType") String accountTypeName, @FormParam("initialUser") String initialUserString, @FormParam("title") String title, @FormParam("timezone") String timezone, @FormParam("locale") String localeName, @DefaultValue("html") @FormParam("emailFormat") String emailFormat, @DefaultValue("true") @FormParam("enableBackButton") String enableBackButton, @DefaultValue("false") @FormParam("disableAutoRefresh") String disableAutoRefresh, @DefaultValue("false") @FormParam("manualMetadataUpdate") String manualMetadataUpdate, @FormParam("property") String property, @Context SecurityContext sc, MultivaluedMap<String, String> formParams) { AccountType accountType = accountBean.findAccountTypebyKnownType(accountTypeName); if (accountType == null) { return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN) .entity("Account Type not provided").build(); } if (!accountType.isCreatable()) { return Response.status(Status.FORBIDDEN).type(MediaType.TEXT_PLAIN) .entity("Account Type is not creatable").build(); } if (initialUserString == null) { return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("Missing Initial User") .build(); } TolvenUser initialUser = activationBean.findUser(initialUserString); if (initialUser == null) { return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("Invalid Initial User") .build(); } Account account = null; try { account = accountBean.createAccount2(title, timezone, accountType); } catch (Exception e) { return Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.TEXT_PLAIN) .entity(ExceptionFormatter.toSimpleString(e, "\\n")).build(); } account.setAccountType(accountType); account.setEmailFormat(emailFormat); if (localeName != null) { Locale[] availableLocales = Locale.getAvailableLocales(); Locale foundLocale = null; for (Locale locale : availableLocales) { if (localeName.equalsIgnoreCase(locale.getDisplayName())) { foundLocale = locale; break; } } account.setLocale(foundLocale.getDisplayName()); } account.setEnableBackButton(enableBackButton.equalsIgnoreCase("true")); account.setDisableAutoRefresh(disableAutoRefresh.equalsIgnoreCase("true")); account.setManualMetadataUpdate(manualMetadataUpdate.equalsIgnoreCase("true")); // Add the initial user to the account TolvenSessionWrapper sessionWrapper = TolvenSessionWrapperFactory.getInstance(); PublicKey userPublicKey = sessionWrapper.getUserPublicKey(); accountBean.addAccountUser(account, initialUser, new Date(), true, userPublicKey); menuBean.updateMenuStructure(account); URI uri = null; try { uri = new URI(URLEncoder.encode(Long.toString(account.getId()), "UTF-8")); } catch (Exception e) { return Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.TEXT_PLAIN) .entity(ExceptionFormatter.toSimpleString(e, "\\n")).build(); } return Response.created(uri).type(MediaType.TEXT_PLAIN).entity(String.valueOf(account.getId())).build(); }
From source file:com.aurel.track.screen.dashboard.bl.design.DashboardScreenDesignBL.java
public void checkAndCreateClientDefaultCockpit() { TDashboardScreenBean screen = null;//from ww w. j a va 2 s . co m try { screen = (TDashboardScreenBean) DashboardScreenDesignBL.getInstance() .tryToLoadScreen(CLIENT_COCKPIT_TEMPLATE_ID); LOGGER.debug("Client default cockpit already exists."); } catch (Exception ex) { LOGGER.debug("Couldn't find client default cockpit, we are now going to create one."); } if (screen == null) { Connection cono = null; Statement ostmt = null; Locale locale = Locale.getDefault(); LOGGER.debug("Using default locale:" + locale.getDisplayName()); String templateName = "Client user default template"; String description = "This template is assigned automatically to newly created client users"; String templateLabel = "Client user default template"; try { cono = InitDatabase.getConnection(); ostmt = cono.createStatement(); cono.setAutoCommit(false); String createClientDefaultTemplate = "INSERT INTO TDASHBOARDSCREEN (OBJECTID, NAME, LABEL, DESCRIPTION)" + "VALUES (" + CLIENT_COCKPIT_TEMPLATE_ID + ",'" + templateName + "', '" + templateLabel + "', '" + description + "')"; ostmt.executeUpdate(createClientDefaultTemplate); cono.commit(); cono.setAutoCommit(true); LOGGER.debug("Client user default cockpit screen has been created with ID: " + CLIENT_COCKPIT_TEMPLATE_ID); createClientDefaultCockpit(); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } finally { if (ostmt != null) { try { ostmt.close(); } catch (SQLException e) { LOGGER.warn(ExceptionUtils.getStackTrace(e)); } } try { if (cono != null) { cono.close(); } } catch (Exception e) { LOGGER.info("Closing the connection failed with " + e.getMessage()); LOGGER.warn(ExceptionUtils.getStackTrace(e)); } } } }
From source file:org.itracker.core.resources.ITrackerResources.java
public static String getLocaleFullDN(Locale locale, Locale displayLocale) { if (null == locale) { locale = new Locale(""); }/*from w w w. j av a 2 s . c om*/ String fullName = StringUtils.trimToNull(getLocaleNativeName(locale)); if (null == displayLocale || locale.getLanguage().equals(displayLocale.getLanguage())) { return fullName; } if (StringUtils.equals(fullName, String.valueOf(locale))) { fullName = getLocaleDN(locale, displayLocale); return fullName; } else { String localizedName = StringUtils.trimToNull(getLocaleDN(locale, displayLocale)); if (null != fullName && !StringUtils.equals(fullName, localizedName)) { return fullName.trim() + " (" + localizedName.trim() + ")"; } else if (null != localizedName) { return localizedName.trim(); } else if (null != fullName) { return fullName.trim(); } } return locale.getDisplayName() + (!locale.equals(displayLocale) ? " (" + locale.getDisplayLanguage(locale) + ")" : ""); }
From source file:net.rrm.ehour.ui.admin.config.MainConfigBackingBean.java
@SuppressWarnings("UnusedDeclaration") public List<Locale> getAvailableLanguages() { Locale[] locales = Locale.getAvailableLocales(); Map<String, Locale> localeMap = new HashMap<>(); // remove all variants for (Locale locale : locales) { if (isTranslationsOnly() && !ArrayUtils.contains(config.getAvailableTranslations(), locale.getLanguage())) { continue; }//from w w w . j av a2 s .c om if (localeMap.containsKey(locale.getLanguage()) && locale.getDisplayName().indexOf('(') != -1) { continue; } localeMap.put(locale.getLanguage(), locale); } SortedSet<Locale> localeSet = new TreeSet<>(new LocaleComparator(LocaleComparator.CompareType.LANGUAGE)); for (Locale locale : localeMap.values()) { localeSet.add(locale); } return new ArrayList<>(localeSet); }
From source file:edu.ku.brc.specify.prefs.SystemPrefs.java
/** * Constructor./* w ww . j ava 2 s . co m*/ */ public SystemPrefs() { createForm("Preferences", "System"); JButton clearCache = form.getCompById("clearcache"); clearCache.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { clearCache(); } }); ValBrowseBtnPanel browse = form.getCompById("7"); if (browse != null) { oldSplashPath = localPrefs.get(SPECIFY_BG_IMG_PATH, null); browse.setValue(oldSplashPath, null); } final ValComboBox localeCBX = form.getCompById("5"); localeCBX.getComboBox().setRenderer(new LocaleRenderer()); localeCBX.setEnabled(false); SwingWorker workerThread = new SwingWorker() { protected int inx = -1; @Override public Object construct() { Vector<Locale> locales = new Vector<Locale>(); Collections.addAll(locales, Locale.getAvailableLocales()); Collections.sort(locales, new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { return o1.getDisplayName().compareTo(o2.getDisplayName()); } }); int i = 0; String language = AppPreferences.getLocalPrefs().get("locale.lang", Locale.getDefault().getLanguage()); String country = AppPreferences.getLocalPrefs().get("locale.country", Locale.getDefault().getCountry()); String variant = AppPreferences.getLocalPrefs().get("locale.var", Locale.getDefault().getVariant()); Locale prefLocale = new Locale(language, country, variant); int justLangIndex = -1; Locale cachedLocale = Locale.getDefault(); for (Locale l : locales) { try { Locale.setDefault(l); ResourceBundle rb = ResourceBundle.getBundle("resources", l); boolean isOK = (l.getLanguage().equals("en") && StringUtils.isEmpty(l.getCountry())) || (l.getLanguage().equals("pt") && l.getCountry().equals("PT")); if (isOK && rb.getKeys().hasMoreElements()) { if (l.getLanguage().equals(prefLocale.getLanguage())) { justLangIndex = i; } if (l.equals(prefLocale)) { inx = i; } localeCBX.getComboBox().addItem(l); i++; } } catch (MissingResourceException ex) { } } if (inx == -1 && justLangIndex > -1) { inx = justLangIndex; } Locale.setDefault(cachedLocale); return null; } @Override public void finished() { UIValidator.setIgnoreAllValidation("SystemPrefs", true); localeCBX.setEnabled(true); localeCBX.getComboBox().setSelectedIndex(inx); JTextField loadingLabel = form.getCompById("6"); if (loadingLabel != null) { loadingLabel.setText(UIRegistry.getResourceString("LOCALE_RESTART_REQUIRED")); } UIValidator.setIgnoreAllValidation("SystemPrefs", false); } }; // start the background task workerThread.start(); ValCheckBox chk = form.getCompById("2"); chk.setValue(localPrefs.getBoolean(VERSION_CHECK, true), "true"); chk = form.getCompById("3"); chk.setValue(remotePrefs.getBoolean(SEND_STATS, true), "true"); chk = form.getCompById("9"); chk.setValue(remotePrefs.getBoolean(SEND_ISA_STATS, true), "true"); chk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class); if (collection != null) { String isaNumber = collection.getIsaNumber(); if (StringUtils.isNotEmpty(isaNumber) && !((JCheckBox) e.getSource()).isSelected()) { UIRegistry.showLocalizedMsg("ISA_STATS_WARNING"); } } } }); // Not sure why the form isn't picking up the pref automatically /* remove if worldwind is broken*/ValCheckBox useWWChk = form.getCompById(USE_WORLDWIND); /* remove if worldwind is broken*/ValCheckBox hasOGLChk = form.getCompById(SYSTEM_HasOpenGL); /* remove if worldwind is broken*/useWWChk.setValue(localPrefs.getBoolean(USE_WORLDWIND, false), null); /* remove if worldwind is broken*/hasOGLChk.setValue(localPrefs.getBoolean(SYSTEM_HasOpenGL, false), null); /* remove if worldwind is broken*/hasOGLChk.setEnabled(false); //ValCheckBox askCollChk = form.getCompById(ALWAYS_ASK_COLL); //askCollChk.setValue(localPrefs.getBoolean(ALWAYS_ASK_COLL, false), null); }
From source file:edu.ku.brc.af.core.SchemaI18NService.java
/** * @param includeSepLocale// w w w . j a v a2 s . c om * @return */ public Vector<Locale> getStdLocaleList(final boolean includeSepLocale) { /*for (Locale l : locales) { System.out.println(String.format("%s - %s, %s, %s", l.getDisplayName(), l.getLanguage(), l.getCountry(), l.getVariant())); }*/ Vector<Locale> freqLocales = new Vector<Locale>(); int i = 0; while (i < priorityLocales.length) { String lang = priorityLocales[i++]; String ctry = priorityLocales[i++]; String vari = priorityLocales[i++]; Locale l = getLocaleByLangCountry(lang, ctry, vari); if (l != null) { freqLocales.add(l); } } HashSet<String> freqSet = new HashSet<String>(); for (Locale l : freqLocales) { freqSet.add(l.getDisplayName()); } Vector<Locale> stdLocaleList = new Vector<Locale>(); for (Locale l : locales) { if (!freqSet.contains(l.getDisplayName())) { stdLocaleList.add(l); } } if (includeSepLocale) { stdLocaleList.insertElementAt(new Locale("-", "-", "-"), 0); } for (i = freqLocales.size() - 1; i > -1; i--) { stdLocaleList.insertElementAt(freqLocales.get(i), 0); } return stdLocaleList; }
From source file:com.aurel.track.user.ResetPasswordAction.java
/** *In case of changing password succeeded, the user will be logged in *automatically and redirected to default page. * @return/*w w w.j av a2 s . c om*/ */ public String reset() { TPersonBean personBean = PersonBL.loadByForgotPasswordToken(ctk); if (personBean != null && personBean.getTokenExpDate().getTime() > new Date().getTime()) { personBean.setDisabled(false); personBean.setTokenExpDate(null); personBean.setTokenPasswd(null); personBean.setForgotPasswordKey(null); personBean.setPasswdEncrypted(passwd); PersonBL.save(personBean); String forwardUrl = ""; HttpServletRequest request = ServletActionContext.getRequest(); HttpSession httpSession = request.getSession(); Locale locale = getLocale(); if (locale == null) { locale = Locale.getDefault(); LOGGER.debug("Requested locale is null. Using default:" + locale.getDisplayName()); } else { LOGGER.debug("Requested locale " + locale.getDisplayName()); } TMotdBean motd = MotdBL.loadMotd(locale.getLanguage()); String redirectMapEntry = ""; ArrayList<LabelValueBean> errors = new ArrayList<LabelValueBean>(); StringBuilder sb = LoginBL.createLoginResponseJSON(personBean.getLoginName(), passwd, null, false, false, request, errors, httpSession, forwardUrl, motd, false, locale, null, redirectMapEntry); return LoginBL.writeJSONResponse(sb); // The redirect is done by the client JavaScript } layoutCls = "com.trackplus.layout.ResetPasswordExpiredLayout"; pageTitle = "logon.register.expired.title"; return "expired"; }
From source file:com.m2a.struts.M2AFormBase.java
/** * Display the user's locale setting or the default locale. *//*from w ww . ja va 2 s. c om*/ public String getLocaleDisplay() { Locale locale = getSessionLocale(); if (null == locale) locale = Locale.getDefault(); return locale.getDisplayName(); }
From source file:org.apache.tapestry.engine.DefaultTemplateSource.java
/** * Search for the template corresponding to the resource and the locale. * This may be in the template map already, or may involve reading and * parsing the template.//from w w w . j a v a 2s . c o m * * @return the template, or null if not found. * **/ private ComponentTemplate findStandardTemplate(IRequestCycle cycle, IResourceLocation location, IComponent component, String templateBaseName, Locale locale) { if (LOG.isDebugEnabled()) LOG.debug("Searching for localized version of template for " + location + " in locale " + locale.getDisplayName()); IResourceLocation baseTemplateLocation = location.getRelativeLocation(templateBaseName); IResourceLocation localizedTemplateLocation = baseTemplateLocation.getLocalization(locale); if (localizedTemplateLocation == null) return null; return getOrParseTemplate(cycle, localizedTemplateLocation, component); }