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:com.vmware.identity.SsoController.java
/** * Handle SAML AuthnRequest, UNP entry form *///w w w.j a v a2s . c o m @RequestMapping(value = "/SAML2/SSO/{tenant:.*}", method = RequestMethod.GET, params = Shared.PASSWORD_ENTRY) public String ssoPasswordEntry(Locale locale, @PathVariable(value = "tenant") String tenant, Model model, HttpServletRequest request, HttpServletResponse response) throws IOException { logger.info("Welcome to SP-initiated AuthnRequest handler, PASSWORD entry form! " + "The client locale is " + locale.toString() + ", tenant is " + tenant); try { // fix for PR 964366, check the cookie first if (Shared.hasSessionCookie(request, this.getSessionManager(), tenant)) { sso(locale, tenant, model, request, response); return null; } model.addAttribute("tenant", tenant); model.addAttribute("protocol", "websso"); setupAuthenticationModel(model, locale, tenant, request, null); } catch (Exception e) { logger.error("Found exception while populating model object ", e); sendError(locale, response, e.getLocalizedMessage()); return null; } return "unpentry"; }
From source file:org.openmrs.web.controller.concept.ConceptProposalFormControllerTest.java
/** * @see ConceptProposalFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *//*from w w w.j a va2s.com*/ @Test @Verifies(value = "should work properly for country locales", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)") public void onSubmit_shouldWorkProperlyForCountryLocales() throws Exception { executeDataSet("org/openmrs/api/include/ConceptServiceTest-proposals.xml"); ConceptService cs = Context.getConceptService(); final Integer conceptproposalId = 5; ConceptProposal cp = cs.getConceptProposal(conceptproposalId); Concept conceptToMap = cs.getConcept(4); Locale locale = new Locale("en", "GB"); Assert.assertFalse(conceptToMap.hasName(cp.getOriginalText(), locale)); ConceptProposalFormController controller = (ConceptProposalFormController) applicationContext .getBean("conceptProposalForm"); controller.setApplicationContext(applicationContext); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(new MockHttpSession(null)); request.setMethod("POST"); request.addParameter("conceptProposalId", conceptproposalId.toString()); request.addParameter("finalText", cp.getOriginalText()); request.addParameter("conceptId", conceptToMap.getConceptId().toString()); request.addParameter("conceptNamelocale", locale.toString()); request.addParameter("action", ""); request.addParameter("actionToTake", "saveAsSynonym"); HttpServletResponse response = new MockHttpServletResponse(); ModelAndView mav = controller.handleRequest(request, response); assertNotNull(mav); assertTrue(mav.getModel().isEmpty()); Assert.assertEquals(cp.getOriginalText(), cp.getFinalText()); Assert.assertTrue(conceptToMap.hasName(cp.getOriginalText(), locale)); }
From source file:org.alfresco.repo.search.impl.lucene.LuceneQueryParser.java
protected void addLocaleSpecificUntokenisedTextRangeFunction(String expandedFieldName, String lower, String upper, boolean includeLower, boolean includeUpper, LuceneFunction luceneFunction, BooleanQuery booleanQuery, MLAnalysisMode mlAnalysisMode, Locale locale, IndexTokenisationMode tokenisationMode) { if (locale.toString().length() == 0) { return;/*from ww w.j a va2 s .c o m*/ } String textFieldName = expandedFieldName; if (tokenisationMode == IndexTokenisationMode.BOTH) { textFieldName = textFieldName + "." + locale + FIELD_SORT_SUFFIX; } String lowerTermText = lower; if (locale.toString().length() > 0) { lowerTermText = "{" + locale + "}" + lower; } String upperTermText = upper; if (locale.toString().length() > 0) { upperTermText = "{" + locale + "}" + upper; } Query subQuery = buildRangeFunctionQuery(textFieldName, lowerTermText, upperTermText, includeLower, includeUpper, luceneFunction); booleanQuery.add(subQuery, Occur.SHOULD); if (booleanQuery.getClauses().length == 0) { booleanQuery.add(createNoMatchQuery(), Occur.SHOULD); } }
From source file:org.moqui.impl.context.L10nFacadeImpl.java
@Override public String localize(String original, Locale locale) { if (original == null) return ""; int originalLength = original.length(); if (originalLength == 0) return ""; if (originalLength > 255) { throw new IllegalArgumentException( "Original String cannot be more than 255 characters long, passed in string was " + originalLength + " characters long"); }//from w ww. j a v a2 s . co m if (locale == null) locale = getLocale(); String localeString = locale.toString(); String cacheKey = original.concat("::").concat(localeString); String lmsg = eci.getL10nMessageCache().get(cacheKey); if (lmsg != null) return lmsg; String defaultValue = original; int localeUnderscoreIndex = localeString.indexOf('_'); EntityFind find = eci.getEntity().find("moqui.basic.LocalizedMessage").condition("original", original) .condition("locale", localeString).useCache(true); EntityValue localizedMessage = find.one(); if (localizedMessage == null && localeUnderscoreIndex > 0) localizedMessage = find.condition("locale", localeString.substring(0, localeUnderscoreIndex)).one(); if (localizedMessage == null) localizedMessage = find.condition("locale", "default").one(); // if original has a hash and we still don't have a localizedMessage then use what precedes the hash and try again if (localizedMessage == null) { int indexOfCloseCurly = original.lastIndexOf('}'); int indexOfHash = original.lastIndexOf("##"); if (indexOfHash > 0 && indexOfHash > indexOfCloseCurly) { defaultValue = original.substring(0, indexOfHash); EntityFind findHash = eci.getEntity().find("moqui.basic.LocalizedMessage") .condition("original", defaultValue).condition("locale", localeString).useCache(true); localizedMessage = findHash.one(); if (localizedMessage == null && localeUnderscoreIndex > 0) localizedMessage = findHash .condition("locale", localeString.substring(0, localeUnderscoreIndex)).one(); if (localizedMessage == null) localizedMessage = findHash.condition("locale", "default").one(); } } String result = localizedMessage != null ? localizedMessage.getString("localized") : defaultValue; eci.getL10nMessageCache().put(cacheKey, result); return result; }
From source file:org.apache.tapestry.ApplicationServlet.java
/** * Invoked from the {@link IEngine engine}, just prior to starting to * render a response, when the locale has changed. The servlet writes a * {@link Cookie} so that, on subsequent request cycles, an engine localized * to the selected locale is chosen./*from ww w . j a v a 2s .c o m*/ * * <p>At this time, the cookie is <em>not</em> persistent. That may * change in subsequent releases. * * @since 1.0.1 **/ public void writeLocaleCookie(Locale locale, IEngine engine, RequestContext cycle) { if (LOG.isDebugEnabled()) LOG.debug("Writing locale cookie " + locale); Cookie cookie = new Cookie(LOCALE_COOKIE_NAME, locale.toString()); cookie.setPath(engine.getServletPath()); cycle.addCookie(cookie); }
From source file:org.openmrs.web.dwr.DWRConceptService.java
/** * Returns a map of results with the values as count of matches and a partial list of the * matching concepts (depending on values of start and length parameters) while the keys are are * 'count' and 'objectList' respectively, if the length parameter is not specified, then all * matches will be returned from the start index if specified. * /* w ww. ja v a2s . c o m*/ * @param phrase concept name or conceptId * @param includeRetired boolean if false, will exclude retired concepts * @param includeClassNames List of ConceptClasses to restrict to * @param excludeClassNames List of ConceptClasses to leave out of results * @param includeDatatypeNames List of ConceptDatatypes to restrict to * @param excludeDatatypeNames List of ConceptDatatypes to leave out of results * @param start the beginning index * @param length the number of matching concepts to return * @param getMatchCount Specifies if the count of matches should be included in the returned map * @return a map of results * @throws APIException * @since 1.8 */ public Map<String, Object> findCountAndConcepts(String phrase, boolean includeRetired, List<String> includeClassNames, List<String> excludeClassNames, List<String> includeDatatypeNames, List<String> excludeDatatypeNames, Integer start, Integer length, boolean getMatchCount) throws APIException { //Map to return Map<String, Object> resultsMap = new HashMap<String, Object>(); List<Object> objectList = new ArrayList<Object>(); // get the list of locales to search on List<Locale> searchLocales = Context.getAdministrationService().getSearchLocales(); // debugging output if (log.isDebugEnabled()) { StringBuffer searchLocalesString = new StringBuffer(); for (Locale loc : searchLocales) { searchLocalesString.append(loc.toString() + " "); } log.debug("searching locales: " + searchLocalesString); } if (includeClassNames == null) { includeClassNames = new ArrayList<String>(); } if (excludeClassNames == null) { excludeClassNames = new ArrayList<String>(); } if (includeDatatypeNames == null) { includeDatatypeNames = new ArrayList<String>(); } if (excludeDatatypeNames == null) { excludeDatatypeNames = new ArrayList<String>(); } try { ConceptService cs = Context.getConceptService(); if (!StringUtils.isBlank(phrase)) { // turn classnames into class objects List<ConceptClass> includeClasses = new ArrayList<ConceptClass>(); for (String name : includeClassNames) { if (!"".equals(name)) { includeClasses.add(cs.getConceptClassByName(name)); } } // turn classnames into class objects List<ConceptClass> excludeClasses = new ArrayList<ConceptClass>(); for (String name : excludeClassNames) { if (!"".equals(name)) { excludeClasses.add(cs.getConceptClassByName(name)); } } // turn classnames into class objects List<ConceptDatatype> includeDatatypes = new ArrayList<ConceptDatatype>(); for (String name : includeDatatypeNames) { if (!"".equals(name)) { includeDatatypes.add(cs.getConceptDatatypeByName(name)); } } // turn classnames into class objects List<ConceptDatatype> excludeDatatypes = new ArrayList<ConceptDatatype>(); for (String name : excludeDatatypeNames) { if (!"".equals(name)) { excludeDatatypes.add(cs.getConceptDatatypeByName(name)); } } int matchCount = 0; if (getMatchCount) { //get the count of matches matchCount += cs.getCountOfConcepts(phrase, searchLocales, includeRetired, includeClasses, excludeClasses, includeDatatypes, excludeDatatypes, null); if (phrase.matches("\\d+")) { // user searched on a number. Insert concept with // corresponding conceptId Concept c = cs.getConcept(Integer.valueOf(phrase)); if (c != null && (!c.isRetired() || includeRetired)) { matchCount++; } } //if (includeDrugs) // matchCount += cs.getCountOfDrugs(phrase, null, false, includeRetired); } //if we have any matches or this isn't the first ajax call when the caller //requests for the count if (matchCount > 0 || !getMatchCount) { objectList.addAll(findBatchOfConcepts(phrase, includeRetired, includeClassNames, excludeClassNames, includeDatatypeNames, excludeDatatypeNames, start, length)); } resultsMap.put("count", matchCount); resultsMap.put("objectList", objectList); } else { resultsMap.put("count", 0); objectList.add(Context.getMessageSourceService().getMessage("searchWidget.noMatchesFound")); } } catch (Exception e) { log.error("Error while searching for concepts", e); objectList.clear(); objectList.add( Context.getMessageSourceService().getMessage("Concept.search.error") + " - " + e.getMessage()); resultsMap.put("count", 0); resultsMap.put("objectList", objectList); } return resultsMap; }
From source file:com.liferay.portlet.journal.util.JournalConverterImpl.java
@Override public String getDDMXSD(String journalXSD) throws Exception { Document document = SAXReaderUtil.read(journalXSD); Element rootElement = document.getRootElement(); Locale defaultLocale = LocaleUtil.getSiteDefault(); rootElement.addAttribute("available-locales", defaultLocale.toString()); rootElement.addAttribute("default-locale", defaultLocale.toString()); List<Element> dynamicElementElements = rootElement.elements("dynamic-element"); for (Element dynamicElementElement : dynamicElementElements) { updateJournalXSDDynamicElement(dynamicElementElement); }/* w w w .ja v a2 s . c om*/ return DDMXMLUtil.formatXML(document); }
From source file:net.sf.logsaw.dialect.websphere.WebsphereDialect.java
private DateFormat getDateFormat(Locale loc) throws CoreException { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, loc); if (!(df instanceof SimpleDateFormat)) { return null; }/*ww w . j a v a 2 s .c om*/ try { // Always use US locale for date format symbols return new SimpleDateFormat(((SimpleDateFormat) df).toPattern() + " " + TIME_FORMAT, //$NON-NLS-1$ DateFormatSymbols.getInstance(Locale.US)); } catch (RuntimeException e) { // Could also be ClassCastException throw new CoreException(new Status(IStatus.ERROR, WebsphereDialectPlugin.PLUGIN_ID, NLS.bind(Messages.WebsphereDialect_error_dateFormatNotSupported, loc.toString()))); } }
From source file:org.alfresco.repo.search.impl.lucene.LuceneQueryParser.java
private void addLocaleSpecificUntokenisedMLOrTextAttribute(String sourceField, String queryText, SubQuery subQueryBuilder, AnalysisMode analysisMode, LuceneFunction luceneFunction, BooleanQuery booleanQuery, MLAnalysisMode mlAnalysisMode, Locale locale, String actualField) throws ParseException { String termText = queryText;// w w w . j ava2 s. c o m if (locale.toString().length() > 0) { termText = "{" + locale + "}" + queryText; } Query subQuery = subQueryBuilder.getQuery(actualField, termText, analysisMode, luceneFunction); booleanQuery.add(subQuery, Occur.SHOULD); if (booleanQuery.getClauses().length == 0) { booleanQuery.add(createNoMatchQuery(), Occur.SHOULD); } }
From source file:org.jahia.services.workflow.jbpm.custom.email.JBPMMailProducer.java
public Collection<Message> produce(final WorkItem workItem) { if (!ServicesRegistry.getInstance().getMailService().isEnabled()) { return Collections.emptyList(); }/*from w w w. j a v a 2 s . com*/ final Map<String, Object> vars = workItem.getParameters(); Locale locale = (Locale) vars.get("locale"); String templateKey = (String) vars.get("templateKey"); MailTemplate template = null; if (templateKey != null) { if (locale != null) { template = (mailTemplateRegistry.getTemplate(templateKey + "." + locale.toString())); if (template == null) { template = (mailTemplateRegistry.getTemplate(templateKey + "." + locale.getLanguage())); } } if (template == null) { template = mailTemplateRegistry.getTemplate(templateKey); } } if (template != null) { final MailTemplate usedTemplate = template; try { return JCRTemplate.getInstance().doExecuteWithSystemSessionAsUser(null, Constants.EDIT_WORKSPACE, locale, new JCRCallback<Collection<Message>>() { public Collection<Message> doInJCR(JCRSessionWrapper session) throws RepositoryException { try { scriptEngine = ScriptEngineUtils.getInstance() .getEngineByName(usedTemplate.getLanguage()); bindings = null; Message email = instantiateEmail(); fillFrom(usedTemplate, email, workItem, session); fillRecipients(usedTemplate, email, workItem, session); fillSubject(usedTemplate, email, workItem, session); fillContent(usedTemplate, email, workItem, session); Address[] addresses = email.getRecipients(Message.RecipientType.TO); if (addresses != null && addresses.length > 0) { return Collections.singleton(email); } else { addresses = email.getRecipients(Message.RecipientType.BCC); if (addresses != null && addresses.length > 0) { return Collections.singleton(email); } addresses = email.getRecipients(Message.RecipientType.CC); if (addresses != null && addresses.length > 0) { return Collections.singleton(email); } return Collections.emptyList(); } } catch (Exception e) { logger.error("Cannot produce mail", e); } return Collections.emptyList(); } }); } catch (RepositoryException e) { logger.error("Cannot produce mail", e); } } return Collections.emptyList(); }