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:fr.hoteia.qalingo.core.i18n.message.impl.CoreMessageSourceImpl.java
public String getMessage(final String code, final Object args[], final Locale locale) throws NoSuchMessageException { try {//w w w . ja v a 2 s . c o m return messageSource.getMessage(code, args, locale); } catch (Exception e) { LOG.error("This message key doesn't exist: " + code + ", for this locale: " + locale.toString()); if (BooleanUtils.negate(locale.toString().equalsIgnoreCase(Constants.DEFAULT_LOCALE_CODE))) { return getMessage(code, args, new Locale(Constants.DEFAULT_LOCALE_CODE)); } } return null; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ViewLabelsServlet.java
private HashMap<String, String> buildLocaleMap(Locale locale, Locale currentLocale) throws FileNotFoundException { HashMap<String, String> map = new HashMap<String, String>(); //Replacing the underscore with a hyphen because that is what is represented in the actual literals map.put("code", locale.toString().replace("_", "-")); map.put("label", locale.getDisplayName(currentLocale)); return map;//from w w w . j a va 2s . c o m }
From source file:com.jaspersoft.jasperserver.war.control.JSCommonController.java
protected void setupLoginPage(HttpServletRequest req) { Cookie[] cookies = req.getCookies(); String locale = null;//w ww . j a v a 2 s . co m String preferredTz = null; if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(JasperServerConstImpl.getUserLocaleSessionAttr())) locale = cookie.getValue(); if (cookie.getName().equals(JasperServerConstImpl.getUserTimezoneSessionAttr())) preferredTz = cookie.getValue(); } } Locale displayLocale = req.getLocale(); String preferredLocale; if (locale == null || locale.length() == 0) { preferredLocale = displayLocale.toString(); } else { preferredLocale = locale; } if (preferredTz == null) { preferredTz = timezones.getDefaultTimeZoneID(); } req.setAttribute("preferredLocale", preferredLocale); req.setAttribute("userLocales", locales.getUserLocales(displayLocale)); req.setAttribute("preferredTimezone", preferredTz); req.setAttribute("userTimezones", timezones.getTimeZones(displayLocale)); try { if (Integer.parseInt(passwordExpirationInDays) > 0) { allowUserPasswordChange = "true"; } } catch (NumberFormatException e) { // if the value is NaN, then assume it's non postive. // not overwrite allowUserPasswordChange } req.setAttribute("allowUserPasswordChange", allowUserPasswordChange); req.setAttribute("passwordExpirationInDays", passwordExpirationInDays); req.setAttribute("passwordPattern", userAuthService.getAllowedPasswordPattern().replace("\\", "\\\\")); req.setAttribute("autoCompleteLoginForm", autoCompleteLoginForm); req.setAttribute(IS_DEVELOPMENT_ENVIRONMENT_TYPE, false); req.setAttribute(USERS_EXCEEDED, false); req.setAttribute(BAN_USER, false); req.setAttribute("isEncryptionOn", SecurityConfiguration.isEncryptionOn()); }
From source file:com.aurel.track.lucene.search.listFields.LocalizedListSearcher.java
/** * Gets the lucene query for explicit lookup field * @param analyzer// www . j a va 2 s . com * @param fieldName * @param fieldValue * @param fieldID * @param locale * @return */ @Override protected Query getExplicitFieldQuery(Analyzer analyzer, String fieldName, String fieldValue, Integer fieldID, Locale locale) { QueryParser queryParser = new QueryParser(getLabelFieldName(), analyzer); //search for both localized and not localized value String queryString = "(" + getLabelFieldName() + LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + fieldValue + " OR " + locale.toString() + LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + fieldValue + " OR " + LuceneUtil.LIST_INDEX_FIELDS_LOCALIZED.DEFAULT_LOCALIZED + LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + fieldValue + ") AND " + LuceneUtil.LIST_INDEX_FIELDS_LOCALIZED.TYPE + LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + getEntityType(fieldID); Query query = null; try { query = queryParser.parse(queryString); } catch (ParseException e) { LOGGER.error("Parsing the query string for fieldName " + fieldName + " and fieldValue '" + fieldValue + "' failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return query; }
From source file:org.obiba.onyx.quartz.editor.questionnaire.QuestionnairePanel.java
public QuestionnairePanel(String id, final IModel<Questionnaire> model, boolean newQuestionnaire) { super(id, model); final Questionnaire questionnaire = model.getObject(); add(CSSPackageResource.getHeaderContribution(QuestionnairePanel.class, "QuestionnairePanel.css")); feedbackPanel = new FeedbackPanel("content"); feedbackWindow = new FeedbackWindow("feedback"); feedbackWindow.setOutputMarkupId(true); add(feedbackWindow);//ww w .j a v a 2 s . c o m Form<Questionnaire> form = new Form<Questionnaire>("form", model); add(form); TextField<String> name = new TextField<String>("name", new PropertyModel<String>(form.getModel(), "name")); name.setLabel(new ResourceModel("Name")); name.setEnabled(newQuestionnaire); name.add(new RequiredFormFieldBehavior()); name.add(new PatternValidator(QuartzEditorPanel.ELEMENT_NAME_PATTERN)); name.add(new AbstractValidator<String>() { @Override protected void onValidate(final IValidatable<String> validatable) { boolean isNewName = Iterables.all(questionnaireBundleManager.bundles(), new Predicate<QuestionnaireBundle>() { @Override public boolean apply(QuestionnaireBundle input) { return !input.getName().equals(validatable.getValue()); } }); if (!isNewName && !validatable.getValue().equals(questionnaire.getName())) { error(validatable, "NameAlreadyExist"); } } }); form.add(name).add(new SimpleFormComponentLabel("nameLabel", name)) .add(new HelpTooltipPanel("nameHelp", new ResourceModel("Name.Tooltip"))); TextField<String> version = new TextField<String>("version", new PropertyModel<String>(form.getModel(), "version")); version.setLabel(new ResourceModel("Version")); version.add(new RequiredFormFieldBehavior()); form.add(version).add(new SimpleFormComponentLabel("versionLabel", version)); CheckBox commentable = new CheckBox("commentable", new PropertyModel<Boolean>(questionnaire, "commentable")); commentable.setLabel(new ResourceModel("Commentable")); form.add(commentable); form.add(new SimpleFormComponentLabel("commentableLabel", commentable)); form.add(new HelpTooltipPanel("commentableHelp", new ResourceModel("Commentable.Tooltip"))); QuestionnaireFinder.getInstance(questionnaire).buildQuestionnaireCache(); guessUIType(questionnaire); RadioGroup<String> uiType = new RadioGroup<String>("uiType", new PropertyModel<String>(form.getModel(), "uiType")); uiType.setLabel(new ResourceModel("UIType")); uiType.setRequired(true); form.add(uiType); Radio<String> standardUiType = new Radio<String>("standard", new Model<String>(Questionnaire.STANDARD_UI)); standardUiType.setLabel(new ResourceModel("UIType.standard")); uiType.add(standardUiType).add(new SimpleFormComponentLabel("standardLabel", standardUiType)); Radio<String> simplifiedUiType = new Radio<String>("simplified", new Model<String>(Questionnaire.SIMPLIFIED_UI)); simplifiedUiType.setLabel(new ResourceModel("UIType.simplified")); uiType.add(simplifiedUiType).add(new SimpleFormComponentLabel("simplifiedLabel", simplifiedUiType)); form.add(new HelpTooltipPanel("uiHelp", new ResourceModel("UIType.Tooltip"))); form.add(new HelpTooltipPanel("labelsHelp", new ResourceModel("LanguagesProperties.Tooltip"))); Map<String, IModel<String>> labelsTooltips = new HashMap<String, IModel<String>>(); labelsTooltips.put("label", new ResourceModel("Questionnaire.Tooltip.label")); labelsTooltips.put("description", new ResourceModel("Questionnaire.Tooltip.description")); labelsTooltips.put("labelNext", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelPrevious", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelStart", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelFinish", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelInterrupt", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelResume", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelCancel", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); localePropertiesModel = new Model<LocaleProperties>( newQuestionnaire ? LocaleProperties.createForNewQuestionnaire(questionnaire) : localePropertiesUtils.load(questionnaire, questionnaire)); final LabelsPanel labelsPanel = new LabelsPanel("labels", localePropertiesModel, model, feedbackPanel, feedbackWindow, labelsTooltips, null); form.add(labelsPanel); final Locale userLocale = Session.get().getLocale(); IChoiceRenderer<Locale> renderer = new IChoiceRenderer<Locale>() { @Override public String getIdValue(Locale locale, int index) { return locale.toString(); } @Override public Object getDisplayValue(Locale locale) { return locale.getDisplayLanguage(userLocale); } }; IModel<List<Locale>> localeChoices = new LoadableDetachableModel<List<Locale>>() { @Override protected List<Locale> load() { List<Locale> locales = new ArrayList<Locale>(); for (String language : Locale.getISOLanguages()) { locales.add(new Locale(language)); } Collections.sort(locales, new Comparator<Locale>() { @Override public int compare(Locale locale1, Locale locale2) { return locale1.getDisplayLanguage(userLocale) .compareTo(locale2.getDisplayLanguage(userLocale)); } }); return locales; } }; Palette<Locale> localesPalette = new Palette<Locale>("languages", new PropertyModel<List<Locale>>(model.getObject(), "locales"), localeChoices, renderer, 5, false) { @Override protected Recorder<Locale> newRecorderComponent() { Recorder<Locale> recorder = super.newRecorderComponent(); recorder.setLabel(new ResourceModel("Languages")); recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { LocaleProperties localeProperties = localePropertiesModel.getObject(); Collection<Locale> selectedLocales = getModelCollection(); @SuppressWarnings("unchecked") Collection<Locale> removedLocales = CollectionUtils.subtract(localeProperties.getLocales(), selectedLocales); for (Locale locale : removedLocales) { localeProperties.removeLocale(questionnaire, locale); } for (Locale locale : selectedLocales) { if (!localeProperties.getLocales().contains(locale)) { localeProperties.addLocale(questionnaire, locale); } } labelsPanel.onModelChange(target); } }); return recorder; } }; form.add(localesPalette); form.add(new SaveCancelPanel("saveCancel", form) { @Override protected void onSave(AjaxRequestTarget target, Form<?> form1) { try { if (questionnaire.getLocales().isEmpty()) { error(new StringResourceModel("LanguagesRequired", QuestionnairePanel.this, null) .getString()); feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); return; } prepareSave(target, questionnaire); questionnairePersistenceUtils.persist(questionnaire, localePropertiesModel.getObject()); QuestionnairePanel.this.onSave(target, questionnaire); } catch (Exception e) { log.error("Cannot persist questionnaire", e); error("Cannot persist questionnaire: " + e.getMessage()); feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); } } @Override protected void onCancel(AjaxRequestTarget target, @SuppressWarnings("hiding") Form<?> form) { QuestionnairePanel.this.onCancel(target); } @Override protected void onError(AjaxRequestTarget target, @SuppressWarnings("hiding") Form<?> form) { feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); } }); }
From source file:org.hyperic.hq.ui.taglib.display.MetricDecorator.java
public String decorate(Object obj) throws Exception { try {// w ww.j a v a 2s . c o m // if the metric value is empty, converting to a Double // will give a value of 0.0. this makes it impossible for // us to distinguish further down the line whether the // metric was actually collected with a value of 0.0 or // whether it was not collected at all. therefore, we'll // let m be null if the metric was not collected, and // we'll check for null later when handling the not-avail // case. // PR: 7588 Double m = null; if (obj != null) { String mval = obj.toString(); if (mval != null && !mval.equals("")) { m = new Double(mval); } } String u = getUnit(); String dk = getDefaultKey(); Locale l = TagUtils.getInstance().getUserLocale(context, locale); StringBuffer buf = new StringBuffer(); if ((m == null || Double.isNaN(m.doubleValue()) || Double.isInfinite(m.doubleValue())) && dk != null) { buf.append(TagUtils.getInstance().message(context, bundle, l.toString(), dk)); } else if (u.equals("ms")) { // we don't care about scaling and such. we just want // to show every metric in seconds with millisecond // resolution String formatted = UnitsFormat.format( new UnitNumber(m.doubleValue(), UnitsConstants.UNIT_DURATION, UnitsConstants.SCALE_MILLI)) .toString(); buf.append(formatted); } else { FormattedNumber f = UnitsConvert.convert(m.doubleValue(), u, l); buf.append(f.getValue()); if (f.getTag() != null && f.getTag().length() > 0) { buf.append(" ").append(f.getTag()); } } return buf.toString(); } catch (NumberFormatException npe) { log.error(npe); throw new JspTagException(npe); } catch (Exception e) { log.error(e); throw new JspException(e); } }
From source file:org.jboss.dashboard.displayer.AbstractDataDisplayerXMLFormat.java
protected void formatRange(RangeConfiguration config, PrintWriter out, int indent) { printIndent(out, indent);/*from www .ja v a 2 s . c o m*/ out.print("<propertyid>"); out.print(StringEscapeUtils.escapeXml(config.getPropertyId())); out.println("</propertyid>"); // Range properties. Map<Locale, String> rangeDescriptions = config.getNameI18nMap(); if (rangeDescriptions != null) { for (Locale rangeKey : rangeDescriptions.keySet()) { printIndent(out, indent); out.print("<name language"); out.print("=\"" + StringEscapeUtils.escapeXml(rangeKey.toString()) + "\">"); out.print(StringEscapeUtils.escapeXml(rangeDescriptions.get(rangeKey))); out.println("</name>"); } } String scalarFunctionCode = config.getScalarFunctionCode(); if (scalarFunctionCode != null) { printIndent(out, indent); out.print("<scalarfunction>"); out.print(StringEscapeUtils.escapeXml(String.valueOf(scalarFunctionCode))); out.println("</scalarfunction>"); } // Unit Map<Locale, String> unitDescriptions = config.getUnitI18nMap(); if (unitDescriptions != null) { for (Locale unitKey : unitDescriptions.keySet()) { printIndent(out, indent); out.print("<unit language"); out.print("=\"" + StringEscapeUtils.escapeXml(unitKey.toString()) + "\">"); out.print(StringEscapeUtils.escapeXml(unitDescriptions.get(unitKey))); out.println("</unit>"); } } }
From source file:org.apereo.portal.layout.dlm.FragmentActivator.java
private net.sf.ehcache.Element getUserView(String ownerId, Locale locale) { return userViews.get(new Tuple<String, String>(ownerId, locale.toString())); }
From source file:org.b3log.solo.processor.console.AdminConsole.java
/** * Shows administrator preference function with the specified context. * //from ww w .j av a 2 s. c om * @param request the specified request * @param context the specified context */ @RequestProcessing(value = "/admin-preference.do", method = HTTPRequestMethod.GET) public void showAdminPreferenceFunction(final HttpServletRequest request, final HTTPRequestContext context) { final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer(); context.setRenderer(renderer); final String templateName = "admin-preference.ftl"; renderer.setTemplateName(templateName); final Locale locale = Latkes.getLocale(); final Map<String, String> langs = langPropsService.getAll(locale); final Map<String, Object> dataModel = renderer.getDataModel(); dataModel.putAll(langs); dataModel.put(Preference.LOCALE_STRING, locale.toString()); JSONObject preference = null; try { preference = preferenceQueryService.getPreference(); } catch (final ServiceException e) { LOGGER.log(Level.SEVERE, "Loads preference failed", e); } final StringBuilder timeZoneIdOptions = new StringBuilder(); final String[] availableIDs = TimeZone.getAvailableIDs(); for (int i = 0; i < availableIDs.length; i++) { final String id = availableIDs[i]; String option; if (id.equals(preference.optString(Preference.TIME_ZONE_ID))) { option = "<option value=\"" + id + "\" selected=\"true\">" + id + "</option>"; } else { option = "<option value=\"" + id + "\">" + id + "</option>"; } timeZoneIdOptions.append(option); } dataModel.put("timeZoneIdOptions", timeZoneIdOptions.toString()); fireFreeMarkerActionEvent(templateName, dataModel); }
From source file:org.chromium.ChromeI18n.java
private String getReplacement(String match) { // get the message from __MSG_messagename__ String messageName = match.substring(6, match.length() - 2).toLowerCase(Locale.ENGLISH); if (messageName.startsWith("@@")) { Locale locale = Locale.getDefault(); if ("@@extension_id".equals(messageName)) { return "{appId}"; } else if ("@@ui_locale".equals(messageName)) { return locale.toString(); } else if ("@@bidi_dir".equals(messageName)) { return isRtlLocale(locale) ? "rtl" : "ltr"; } else if ("@@bidi_reversed_dir".equals(messageName)) { return isRtlLocale(locale) ? "ltr" : "rtl"; } else if ("@@bidi_start_edge".equals(messageName)) { return isRtlLocale(locale) ? "right" : "left"; } else if ("@@bidi_end_edge".equals(messageName)) { return isRtlLocale(locale) ? "left" : "right"; }/*from w w w . j a va 2 s . c om*/ } // Look for replacement in messages.json files List<String> localeChain = getLocalesToUse(); JSONObject messageObject = getMessageFromMessageJson(messageName, localeChain); if (messageObject != null) { String ret = messageObject.optString("message"); if (ret != null) { return ret; } } // Didn't find a match, just return string as is return match; }