List of usage examples for java.util Locale getAvailableLocales
public static Locale[] getAvailableLocales()
From source file:org.joget.apps.app.controller.ConsoleWebController.java
@SuppressWarnings({ "unused", "unchecked", "rawtypes" }) @RequestMapping(value = "/console/profile/submit", method = RequestMethod.POST) public String profileSubmit(ModelMap model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("user") User user, BindingResult result) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { User currentUser = userDao.getUser(workflowUserManager.getCurrentUsername()); if (currentUser == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return null; }/*from www. j a va 2s . c o m*/ Collection<String> errors = new ArrayList<String>(); Collection<String> passwordErrors = new ArrayList<String>(); boolean authenticated = false; if (!currentUser.getUsername().equals(user.getUsername())) { HttpSession session = request.getSession(false); if (session != null) { session.invalidate(); } } else { try { if (directoryManager.authenticate(currentUser.getUsername(), user.getOldPassword())) { authenticated = true; } } catch (Exception e) { } } UserSecurity us = DirectoryUtil.getUserSecurity(); if (!authenticated) { if (errors == null) { errors = new ArrayList<String>(); } errors.add(ResourceBundleUtil.getMessage("console.directory.user.error.label.authenticationFailed")); } else { if (us != null) { errors = us.validateUserOnProfileUpdate(user); } if (user.getPassword() != null && !user.getPassword().isEmpty() && us != null) { passwordErrors = us.validatePassword(user.getUsername(), user.getOldPassword(), user.getPassword(), user.getConfirmPassword()); } } if (!authenticated || (passwordErrors != null && !passwordErrors.isEmpty()) || (errors != null && !errors.isEmpty())) { model.addAttribute("passwordErrors", passwordErrors); model.addAttribute("errors", errors); model.addAttribute("user", user); model.addAttribute("timezones", TimeZoneUtil.getList()); String enableUserLocale = SetupManager.getSettingValue("enableUserLocale"); Map<String, String> localeStringList = new TreeMap<String, String>(); if (enableUserLocale != null && enableUserLocale.equalsIgnoreCase("true")) { String userLocale = SetupManager.getSettingValue("userLocale"); Collection<String> locales = new HashSet(); locales.addAll(Arrays.asList(userLocale.split(","))); Locale[] localeList = Locale.getAvailableLocales(); for (int x = 0; x < localeList.length; x++) { String code = localeList[x].toString(); if (locales.contains(code)) { localeStringList.put(code, code + " - " + localeList[x].getDisplayName(LocaleContextHolder.getLocale())); } } } model.addAttribute("enableUserLocale", enableUserLocale); model.addAttribute("localeStringList", localeStringList); if (us != null) { model.addAttribute("policies", us.passwordPolicies()); model.addAttribute("userProfileFooter", us.getUserProfileFooter(currentUser)); } else { model.addAttribute("policies", ""); model.addAttribute("userProfileFooter", ""); } return "console/profile"; } else if (currentUser.getUsername().equals(user.getUsername())) { currentUser.setFirstName(user.getFirstName()); currentUser.setLastName(user.getLastName()); currentUser.setEmail(user.getEmail()); currentUser.setTimeZone(user.getTimeZone()); currentUser.setLocale(user.getLocale()); UserSalt userSalt = userSaltDao.getUserSaltByUserId(currentUser.getUsername()); if (user.getPassword() != null && user.getConfirmPassword() != null && user.getPassword().length() > 0 && user.getPassword().equals(user.getConfirmPassword())) { if (us != null) { currentUser.setPassword(us.encryptPassword(user.getUsername(), user.getPassword())); } else { //currentUser.setPassword(StringUtil.md5Base16(user.getPassword())); HashSalt hashSalt = PasswordGeneratorUtil.createNewHashWithSalt(user.getPassword()); userSalt.setRandomSalt(hashSalt.getSalt()); currentUser.setPassword(hashSalt.getHash()); } currentUser.setConfirmPassword(user.getPassword()); } userDao.updateUser(currentUser); userSaltDao.updateUserSalt(userSalt); if (us != null) { us.updateUserProfilePostProcessing(currentUser); } } return "console/dialogClose"; }
From source file:com.aurel.track.dbase.InitDatabase.java
/** * Update the message of the day shown on the front page * @param site//from ww w . j a v a 2 s .c om */ private static void setMessageOfTheDay() { Locale[] availableLocales = Locale.getAvailableLocales(); // all on this system ResourceBundle messages = null; Map<String, String> languages = new HashMap<String, String>(); for (int i = 0; i < availableLocales.length; ++i) { Locale locale = availableLocales[i]; locale = new Locale(locale.getLanguage()); // just reduce the locale to the language specific one (no country) messages = ResourceBundle.getBundle("resources.UserInterface.ApplicationResources", locale); Locale theRealLoc = messages.getLocale(); // the existing locale found here String test = languages.get(theRealLoc.getLanguage()); // check if the language has already been treated if (test == null) { languages.put(theRealLoc.getLanguage(), "x"); String motdMessage = messages.getString("motd.message"); String motdTeaser = messages.getString("motd.teaser"); TMotdBean motd = MotdBL.loadMotd(theRealLoc.getLanguage()); try { if (motd == null && motdMessage != null && motdMessage.trim().length() > 0) { motd = new TMotdBean(); motd.setTheLocale(theRealLoc.getLanguage()); motd.setTheMessage(motdMessage); motd.setTeaserText(motdTeaser); MotdBL.saveMotd(motd); LOGGER.info("Created new MOTD for language " + theRealLoc.getLanguage()); } else if (motd != null && motdMessage != null && motdMessage.trim().length() > 0) { motd.setTheMessage(motdMessage + " " + motd.getTheMessage()); motd.setTeaserText(motdTeaser); MotdBL.saveMotd(motd); LOGGER.info("Updated MOTD for language " + theRealLoc.getLanguage()); } } catch (Exception e) { LOGGER.error("Error updating MOTD: " + e.getMessage()); LOGGER.debug(STACKTRACE, e); } } } }
From source file:org.apache.maven.plugin.javadoc.AbstractJavadocMojo.java
/** * Checks for the validity of the Javadoc options used by the user. * * @throws MavenReportException if error *///from w w w. j ava 2 s . c o m private void validateJavadocOptions() throws MavenReportException { // encoding if (StringUtils.isNotEmpty(getEncoding()) && !JavadocUtil.validateEncoding(getEncoding())) { throw new MavenReportException("Unsupported option <encoding/> '" + getEncoding() + "'"); } // locale if (StringUtils.isNotEmpty(this.locale)) { StringTokenizer tokenizer = new StringTokenizer(this.locale, "_"); final int maxTokens = 3; if (tokenizer.countTokens() > maxTokens) { throw new MavenReportException( "Unsupported option <locale/> '" + this.locale + "', should be language_country_variant."); } Locale localeObject = null; if (tokenizer.hasMoreTokens()) { String language = tokenizer.nextToken().toLowerCase(Locale.ENGLISH); if (!Arrays.asList(Locale.getISOLanguages()).contains(language)) { throw new MavenReportException( "Unsupported language '" + language + "' in option <locale/> '" + this.locale + "'"); } localeObject = new Locale(language); if (tokenizer.hasMoreTokens()) { String country = tokenizer.nextToken().toUpperCase(Locale.ENGLISH); if (!Arrays.asList(Locale.getISOCountries()).contains(country)) { throw new MavenReportException( "Unsupported country '" + country + "' in option <locale/> '" + this.locale + "'"); } localeObject = new Locale(language, country); if (tokenizer.hasMoreTokens()) { String variant = tokenizer.nextToken(); localeObject = new Locale(language, country, variant); } } } if (localeObject == null) { throw new MavenReportException( "Unsupported option <locale/> '" + this.locale + "', should be language_country_variant."); } this.locale = localeObject.toString(); final List<Locale> availableLocalesList = Arrays.asList(Locale.getAvailableLocales()); if (StringUtils.isNotEmpty(localeObject.getVariant()) && !availableLocalesList.contains(localeObject)) { StringBuilder sb = new StringBuilder(); sb.append("Unsupported option <locale/> with variant '").append(this.locale); sb.append("'"); localeObject = new Locale(localeObject.getLanguage(), localeObject.getCountry()); this.locale = localeObject.toString(); sb.append(", trying to use <locale/> without variant, i.e. '").append(this.locale).append("'"); if (getLog().isWarnEnabled()) { getLog().warn(sb.toString()); } } if (!availableLocalesList.contains(localeObject)) { throw new MavenReportException("Unsupported option <locale/> '" + this.locale + "'"); } } }
From source file:org.joget.apps.app.controller.ConsoleWebController.java
@RequestMapping("/console/setting/general") public String consoleSettingGeneral(ModelMap map) { Collection<Setting> settingList = setupManager.getSettingList("", null, null, null, null); Map<String, String> settingMap = new HashMap<String, String>(); for (Setting setting : settingList) { if (SetupManager.MASTER_LOGIN_PASSWORD.equals(setting.getProperty())) { settingMap.put(setting.getProperty(), SetupManager.SECURE_VALUE); } else {//from ww w . ja v a 2 s .c om settingMap.put(setting.getProperty(), setting.getValue()); } } String masterLoginUsername = SetupManager.getSettingValue("masterLoginUsername"); String masterLoginPassword = SetupManager.getSettingValue("masterLoginPassword"); if ((masterLoginUsername != null && masterLoginUsername.trim().length() > 0) && (masterLoginPassword != null && masterLoginPassword.length() > 0)) { //decryt masterLoginPassword masterLoginPassword = SecurityUtil.decrypt(masterLoginPassword); User master = new User(); master.setUsername(masterLoginUsername.trim()); master.setPassword(StringUtil.md5Base16(masterLoginPassword)); settingMap.put(SetupManager.MASTER_LOGIN_HASH, master.getLoginHash().toUpperCase()); } Locale[] localeList = Locale.getAvailableLocales(); Map<String, String> localeStringList = new TreeMap<String, String>(); for (int x = 0; x < localeList.length; x++) { localeStringList.put(localeList[x].toString(), localeList[x].toString() + " - " + localeList[x].getDisplayName(LocaleContextHolder.getLocale())); } map.addAttribute("serverTZ", TimeZoneUtil.getServerTimeZoneID()); map.addAttribute("timezones", TimeZoneUtil.getList()); map.addAttribute("localeList", localeStringList); map.addAttribute("settingMap", settingMap); // additional UserSecurity settings UserSecurity us = DirectoryUtil.getUserSecurity(); map.addAttribute("userSecurity", us); return "console/setting/general"; }
From source file:org.joget.apps.app.controller.ConsoleWebController.java
protected String[] getSortedLocalList() { Locale[] localeList = Locale.getAvailableLocales(); String[] localeStringList = new String[localeList.length]; for (int i = 0; i < localeList.length; i++) { localeStringList[i] = localeList[i].toString(); }//w w w. jav a 2 s. com Arrays.sort(localeStringList); return localeStringList; }
From source file:com.clark.func.Functions.java
/** * Initializes the availableLocaleList. It is separate from * availableLocaleList() to avoid the synchronized block affecting normal * use, yet synchronized and lazy loading to avoid a static block affecting * other methods in this class.// w w w.j a v a 2s.c om */ private static synchronized void initAvailableLocaleList() { if (cAvailableLocaleList == null) { List<Locale> list = Arrays.asList(Locale.getAvailableLocales()); cAvailableLocaleList = Collections.unmodifiableList(list); } }