List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:org.examproject.tweet.controller.TweetController.java
@RequestMapping(value = "/index", method = RequestMethod.GET) public String getForm(@RequestParam(value = "locale", defaultValue = "") String locale, @CookieValue(value = "__exmphangul_request_token", defaultValue = "") String requestToken, @CookieValue(value = "__exmphangul_access_token", defaultValue = "") String oauthToken, @CookieValue(value = "__exmphangul_token_secret", defaultValue = "") String oauthTokenSecret, @CookieValue(value = "__exmphangul_user_id", defaultValue = "") String userId, @CookieValue(value = "__exmphangul_screen_name", defaultValue = "") String screenName, @CookieValue(value = "__exmphangul_response_list_mode", defaultValue = "") String responseListMode, @CookieValue(value = "__exmphangul_user_list_name", defaultValue = "") String userListName, Model model) {// www. j a v a 2s . c om LOG.debug("called."); debugOut(oauthToken, oauthTokenSecret, userId, screenName); try { // get the current local. if (locale.equals("")) { Locale loc = Locale.getDefault(); locale = loc.getLanguage(); } // create the form-object. TweetForm tweetForm = new TweetForm(); // set the cookie value to the form-object. tweetForm.setUserId(userId); tweetForm.setScreenName(screenName); tweetForm.setLocale(locale); tweetForm.setResponseListMode(responseListMode); tweetForm.setUserListName(userListName); // set the form-object to the model. model.addAttribute(tweetForm); /////////////////////////////////////////////////////////////////// // TODO: add to get the profile. if (isValidParameterOfGet(oauthToken, oauthTokenSecret, userId, screenName)) { // get the service object. TweetService service = (TweetService) context.getBean(TWEET_SERVICE_BEAN_ID, // get the authentication value object. (TweetAuthValue) context.getBean(TWEET_AUTH_VALUE_BEAN_ID, authValue.getConsumerKey(), authValue.getConsumerSecret(), oauthToken, oauthTokenSecret), // get the setting value object. (SettingParamValue) context.getBean(SETTING_PARAM_VALUE_BEAN_ID, responseListMode, userListName)); // get the dto-object and map to the model-object. ProfileDto profileDto = service.getProfile(screenName); ProfileModel profileModel = context.getBean(ProfileModel.class); mapper.map(profileDto, profileModel); // set the profile model. model.addAttribute(profileModel); } // normally, move to this view. return null; } catch (Exception e) { LOG.fatal(e.getMessage()); TweetResponse response = (TweetResponse) context.getBean(TWEET_RESPONSE_BEAN_ID, true, e.getMessage()); model.addAttribute(response); return "error"; } }
From source file:edu.ku.brc.specify.prefs.SystemPrefs.java
/** * Constructor.// w w w .j a va 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:de.mpg.escidoc.pubman.util.InternationalizationHelper.java
public InternationalizationHelper() { userLocale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale(); Iterator<Locale> supportedLocales = FacesContext.getCurrentInstance().getApplication() .getSupportedLocales();/*w ww. jav a 2s . com*/ boolean found = false; while (supportedLocales.hasNext()) { Locale supportedLocale = supportedLocales.next(); if (supportedLocale.getLanguage().equals(userLocale.getLanguage())) { found = true; break; } } if (!found) { userLocale = new Locale("en"); } if (userLocale.getLanguage().equals("de")) { selectedHelpPage = HELP_PAGE_DE; } else { selectedHelpPage = HELP_PAGE_EN; } locale = userLocale.getLanguage(); NO_ITEM_SET = new SelectItem("", getLabel("EditItem_NO_ITEM_SET")); }
From source file:de.austinpadernale.holidays.Holiday.java
public String getName(Locale locale) { String result;/*from www . j a va2 s . c om*/ if (names == null || names.isEmpty()) { result = createName(); } else if (locale == null || locale.equals(Locale.ROOT)) { HolidayName hn = null; for (HolidayName n : names) { if (n.getLanguage() == null || n.getLanguage().equals(Locale.ROOT)) { hn = n; break; } } result = holidayNameToName(hn); } else { HolidayName rn = null; HolidayName ln2 = null; HolidayName ln = null; HolidayName cn = null; for (HolidayName n : names) { Locale l = n.getLanguage(); if (l == null || l.equals(Locale.ROOT)) { if (rn == null) { rn = n; } continue; } if (equals(l.getLanguage(), locale.getLanguage()) && StringUtils.isEmpty(l.getCountry())) { if (ln == null) { ln = n; } continue; } if (equals(l.getLanguage(), locale.getLanguage()) && !StringUtils.isEmpty(l.getCountry())) { if (ln2 == null) { ln2 = n; } continue; } if (equals(l.getLanguage(), locale.getLanguage()) && equals(l.getCountry(), locale.getCountry())) { if (cn == null) { cn = n; } } } if (cn != null) { result = holidayNameToName(cn); } else if (ln != null) { result = holidayNameToName(ln); } else if (ln2 != null) { result = holidayNameToName(ln2); } else if (rn != null) { result = holidayNameToName(rn); } else { result = createName(); } } return result; }
From source file:com.playhaven.android.req.PlayHavenRequest.java
@SuppressWarnings("deprecation") protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException { try {//from w w w.j av a2s.c o m SharedPreferences pref = PlayHaven.getPreferences(context); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getString(pref, APIServer)); builder.path(context.getResources().getString(getApiPath(context))); builder.queryParam("app", getString(pref, AppPkg)); builder.queryParam("opt_out", getString(pref, OptOut, "0")); builder.queryParam("app_version", getString(pref, AppVersion)); builder.queryParam("os", getInt(pref, OSVersion, 0)); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); builder.queryParam("orientation", display.getRotation()); builder.queryParam("hardware", getString(pref, DeviceModel)); PlayHaven.ConnectionType connectionType = getConnectionType(context); builder.queryParam("connection", connectionType.ordinal()); builder.queryParam("idiom", context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK); /** * For height/width we will use getSize(Point) not getRealSize(Point) as this will allow us to automatically * account for rotation and screen decorations like the status bar. We only want to know available space. * * @playhaven.apihack for SDK_INT < 13, have to use getHeight and getWidth! */ Point size = new Point(); if (Build.VERSION.SDK_INT >= 13) { display.getSize(size); } else { size.x = display.getWidth(); size.y = display.getHeight(); } builder.queryParam("width", size.x); builder.queryParam("height", size.y); /** * SDK Version needs to be reported as a dotted numeric value * So, if it is a -SNAPSHOT build, we will replace -SNAPSHOT with the date of the build * IE: 2.0.0.20130201 * as opposed to an actual released build, which would be like 2.0.0 */ String sdkVersion = getString(pref, SDKVersion); String[] date = Version.PLUGIN_BUILD_TIME.split("[\\s]"); sdkVersion = sdkVersion.replace("-SNAPSHOT", "." + date[0].replaceAll("-", "")); builder.queryParam("sdk_version", sdkVersion); builder.queryParam("plugin", getString(pref, PluginIdentifer)); Locale locale = context.getResources().getConfiguration().locale; builder.queryParam("languages", String.format("%s,%s", locale.toString(), locale.getLanguage())); builder.queryParam("token", getString(pref, Token)); builder.queryParam("device", getString(pref, DeviceId)); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); builder.queryParam("dpi", metrics.densityDpi); String uuid = UUID.randomUUID().toString(); String nonce = base64Digest(uuid); builder.queryParam("nonce", nonce); ktsid = KontagentUtil.getSenderId(context); if (ktsid != null) builder.queryParam("sid", ktsid); addSignature(builder, pref, nonce); // Setup for signature verification String secret = getString(pref, Secret); SecretKeySpec key = new SecretKeySpec(secret.getBytes(UTF8), HMAC); sigMac = Mac.getInstance(HMAC); sigMac.init(key); sigMac.update(nonce.getBytes(UTF8)); return builder; } catch (Exception e) { throw new PlayHavenException(e); } }
From source file:org.sakaiproject.metaobj.shared.mgt.home.StructuredArtifactHome.java
protected Content i18nFilterAnnotations(Element content) throws JDOMException { Locale locale = rl.getLocale(); Map<String, Element> documentElements = new Hashtable<String, Element>(); filterElements(documentElements, content, null); filterElements(documentElements, content, locale.getLanguage()); filterElements(documentElements, content, locale.getLanguage() + "_" + locale.getCountry()); filterElements(documentElements, content, locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant()); Element returned = (Element) content.clone(); returned.removeChildren("documentation", content.getNamespace()); for (Iterator<Element> i = documentElements.values().iterator(); i.hasNext();) { returned.addContent((Content) i.next().clone()); }//from w ww. j av a 2 s. c o m return returned; }
From source file:net.kamhon.ieagle.function.language.service.impl.LanguageFrameworkServiceImpl.java
public String getText(String key, Locale locale, Object[] argsArray) { String msg = null;//from w w w .j a v a 2 s. c o m if (locale == null) { locale = systemLocale; } if (serverConfiguration.isProductionMode()) { if (!isInitLanguage) { log.info("init languages"); synchronized (dbBundles) { dbBundles.clear(); initLanguage(); isInitLanguage = true; } } if (dbBundles.containsKey(locale.getLanguage())) { Properties prop = dbBundles.get(locale.getLanguage()); msg = prop.getProperty(key); } // text not found, look on default locale if (msg == null && !locale.getLanguage().equalsIgnoreCase(systemLocale.getLanguage())) { if (dbBundles.containsKey(systemLocale.getLanguage())) { Properties prop = dbBundles.get(systemLocale.getLanguage()); msg = prop.getProperty(key); } } } // if STAGING MODE else { LanguageRes res = languageResDao.get(new LanguageResKey(locale.getLanguage(), key)); if (res != null) { msg = res.getResValue(); } else if (!locale.getLanguage().equalsIgnoreCase(systemLocale.getLanguage())) { res = languageResDao.get(new LanguageResKey(systemLocale.getLanguage(), key)); if (res != null) { msg = res.getResValue(); } } // just for development only if (msg == null) { if (!checkIfInPrefixList(key)) { log.debug("****************************************"); log.debug("key[" + key + "] can't found at db!!!!"); log.debug("***************************************"); } } } if (msg == null) { msg = getTextByResourceBundle(key, locale); } if (msg != null) { // format the code if (argsArray != null && argsArray.length > 0) { return MessageFormat.format(msg, argsArray); } return msg; } else { return key; } }
From source file:de.iew.services.impl.MessageBundleServiceImpl.java
public void loadMessageBundle(Properties messageBundle, String basename, Locale locale) { if (log.isDebugEnabled()) { log.debug("Synchronisiere MessageBundle " + basename + " fr Locale " + locale + "."); }//w ww . java 2 s. c o m MessageBundle mb; for (String messageKey : messageBundle.stringPropertyNames()) { if (log.isTraceEnabled()) { log.trace(messageKey + " -> " + messageBundle.getProperty(messageKey)); } mb = this.messageBundleDao.findByTextKeyAndLocale(messageKey, locale.getLanguage(), locale.getCountry()); if (mb == null) { TextItem textItem = new TextItem(); textItem.setLanguageCode(locale.getLanguage()); textItem.setCountryCode(locale.getCountry()); textItem.setContent(messageBundle.getProperty(messageKey)); mb = new MessageBundle(); mb.setTextKey(messageKey); mb.setBasename(basename); mb.setTextItem(textItem); this.messageBundleDao.save(mb); } } }
From source file:net.naijatek.myalumni.framework.struts.MyAlumniExtendedTilesRequestProcessor.java
/** * Ensures the user locale is identified and stored in the session as * appropriate./*from w ww . j a va 2s.c o m*/ * * @param request * The servlet request we are processing. * @param response * The servlet response we are creating. */ protected void processLocale(HttpServletRequest request, HttpServletResponse response) { // Are we configured to select the Locale automatically? if (!moduleConfig.getControllerConfig().getLocale()) { return; } // Get the Locale (if any) that is stored in the user's session HttpSession session = request.getSession(); Locale sessionLocale = (Locale) session.getAttribute(Globals.LOCALE_KEY); // Get the user's preferred Locale from the request Locale requestLocale = request.getLocale(); // If there was never a Locale in the session or it has changed, set it if (sessionLocale == null || (sessionLocale != requestLocale)) { if (logger.isDebugEnabled()) { logger.debug(" Setting user locale '" + requestLocale + "'"); } // Set the new Locale into the user's session session.setAttribute(Globals.LOCALE_KEY, requestLocale); session.setAttribute("localeKey", requestLocale.getLanguage()); // for // displaytag } }
From source file:com.doculibre.constellio.services.ConnectorManagerServicesImpl.java
private Element setConnectorConfig(ConnectorManager connectorManager, String connectorName, String connectorType, Map<String, String[]> requestParams, boolean update, Locale locale) { Document document = DocumentHelper.createDocument(); Element root = document.addElement(ServletUtil.XMLTAG_CONNECTOR_CONFIG); root.addElement(ServletUtil.QUERY_PARAM_LANG).addText(locale.getLanguage()); root.addElement(ServletUtil.XMLTAG_CONNECTOR_NAME).addText(connectorName); root.addElement(ServletUtil.XMLTAG_CONNECTOR_TYPE).addText(connectorType); root.addElement(ServletUtil.XMLTAG_UPDATE_CONNECTOR).addText(Boolean.toString(update)); for (String paramName : requestParams.keySet()) { if (!paramName.startsWith("wicket:")) { String[] paramValues = requestParams.get(paramName); for (String paramValue : paramValues) { Element paramElement = root.addElement(ServletUtil.XMLTAG_PARAMETERS); paramElement.addAttribute("name", paramName); paramElement.addAttribute("value", paramValue); }/*from w ww .j a v a2 s . co m*/ } } Element response = ConnectorManagerRequestUtils.sendPost(connectorManager, "/setConnectorConfig", document); Element statusIdElement = response.element(ServletUtil.XMLTAG_STATUSID); if (statusIdElement != null) { String statusId = statusIdElement.getTextTrim(); if (!statusId.equals("" + ConnectorMessageCode.SUCCESS)) { return response; } else { BackupServices backupServices = ConstellioSpringUtils.getBackupServices(); backupServices.backupConfig(connectorName, connectorType); return null; } } else { return null; } }