List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:org.apache.tapestry.engine.DefaultComponentMessagesSource.java
private Properties assembleProperties(IResourceLocation baseResourceLocation, Locale locale) { boolean debug = LOG.isDebugEnabled(); if (debug)//ww w . j a va2 s . c o m LOG.debug("Assembling properties for " + baseResourceLocation + " " + locale); String name = baseResourceLocation.getName(); int dotx = name.indexOf('.'); String baseName = name.substring(0, dotx); String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); Properties parent = (Properties) _cache.get(baseResourceLocation); if (parent == null) { parent = readProperties(baseResourceLocation, baseName, null, null); if (parent == null) parent = _emptyProperties; _cache.put(baseResourceLocation, parent); } Properties result = parent; if (!Tapestry.isBlank(language)) { Locale l = new Locale(language, ""); MultiKey key = buildKey(baseResourceLocation, l); result = (Properties) _cache.get(key); if (result == null) result = readProperties(baseResourceLocation, baseName, l, parent); _cache.put(key, result); parent = result; } else language = ""; if (Tapestry.isNonBlank(country)) { Locale l = new Locale(language, country); MultiKey key = buildKey(baseResourceLocation, l); result = (Properties) _cache.get(key); if (result == null) result = readProperties(baseResourceLocation, baseName, l, parent); _cache.put(key, result); parent = result; } else country = ""; if (Tapestry.isNonBlank(variant)) { Locale l = new Locale(language, country, variant); MultiKey key = buildKey(baseResourceLocation, l); result = (Properties) _cache.get(key); if (result == null) result = readProperties(baseResourceLocation, baseName, l, parent); _cache.put(key, result); } return result; }
From source file:org.parosproxy.paros.extension.option.OptionsParamView.java
public void setLocale(Locale locale) { if (locale != null) { StringBuilder sb = new StringBuilder(); sb.append(locale.getLanguage()); if (locale.getCountry().length() > 0) sb.append("_").append(locale.getCountry()); if (locale.getVariant().length() > 0) sb.append("_").append(locale.getVariant()); setLocale(sb.toString());/*from ww w . ja v a 2 s . c om*/ } }
From source file:org.rti.zcore.dar.struts.action.PatientRecordListAction.java
protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { /*if (SystemStateManager.getCurrentState() != SystemStateManager.STATUS_NORMAL) { return mapping.findForward(LOCKED_FORWARD); }*//*from w ww . j a va 2s . c o m*/ HttpSession session = request.getSession(); Locale sessionLocale = (Locale) request.getAttribute("sessionLocale"); String sessionLocaleString = null; if ((sessionLocale.getLanguage() != null) && ((sessionLocale.getCountry() != null) && (!sessionLocale.getCountry().equals("")))) { sessionLocaleString = sessionLocale.getLanguage() + "_" + sessionLocale.getCountry(); } else if (sessionLocale.getLanguage() != null) { sessionLocaleString = sessionLocale.getLanguage(); } Principal user = request.getUserPrincipal(); String username = user.getName(); Connection conn = null; BaseEncounter encounter = null; Map encMap = null; Long formId = null; SessionSubject sessionPatient = null; Long patientId = null; //Long eventId = null; String eventUuid = null; Form encounterForm = null; String formName = null; if (mapping.getParameter() != null && !mapping.getParameter().equals("")) { formName = mapping.getParameter().trim(); formId = (Long) DynaSiteObjects.getFormNameMap().get(formName); } else { if (request.getParameter("formId") != null) { formId = Long.decode(request.getParameter("formId")); } else if (request.getAttribute("formId") != null) { formId = Long.decode(request.getAttribute("formId").toString()); } //formId = request.getAttribute("id").toString(); } if (request.getParameter("patientId") != null) { patientId = Long.decode(request.getParameter("patientId")); } else if (request.getAttribute("patientId") != null) { patientId = Long.decode(request.getAttribute("patientId").toString()); } try { sessionPatient = (SessionSubject) SessionUtil.getInstance(session).getSessionPatient(); //eventId = sessionPatient.getCurrentEventId(); eventUuid = sessionPatient.getCurrentEventUuid(); } catch (SessionUtil.AttributeNotFoundException e) { log.error("Unable to get TimsSessionSubject"); } if (patientId == null) { try { patientId = sessionPatient.getId(); } catch (Exception e) { log.error("Unable to get TimsSessionSubject field"); } } // sometimes the user can click link to create a new event and then click elsewhere. if (eventUuid == null) { String forwardString = "/listEvents.do?patientId=" + patientId; ActionForward forwardForm = new ActionForward(forwardString); forwardForm.setRedirect(true); return forwardForm; } encounterForm = ((Form) DynaSiteObjects.getForms().get(formId)); try { conn = DatabaseUtils.getZEPRSConnection(username); // populate the records for this class List chartItems = new ArrayList(); String classname = StringManipulation.fixClassname(encounterForm.getName()); Class clazz = Class.forName(Constants.getDynasiteFormsPackage() + "." + classname); try { ArrayList moreItems = (ArrayList) EncountersDAO.getAllOrderBy(conn, patientId, eventUuid, "SQL_RETRIEVE_UUID" + formId, clazz, "date_visit DESC"); chartItems.addAll(moreItems); } catch (IOException e) { request.setAttribute("exception", e); return mapping.findForward("error"); } catch (ServletException e) { request.setAttribute("exception", e); return mapping.findForward("error"); } catch (SQLException e) { request.setAttribute("exception", e); return mapping.findForward("error"); } // DAR-specific: if (formName.equals("PatientCondition")) { String bmiCalc = Constants.getProperties("bmi.calculate", Constants.getAPP_PROPERTIES()); if (bmiCalc != null && bmiCalc.equals("true")) { for (int i = 0; i < chartItems.size(); i++) { PatientCondition pc = (PatientCondition) chartItems.get(i); Float weight = pc.getWeight(); Float height = pc.getHeight(); if ((weight != null) && ((height != null) && (height != 0))) { Float bmi = HealthCalcUtils.bmiCalc(weight, height); pc.setBmi_calculated(bmi); } } } } // Attach a map of encounter values that has enumerations already resolved. MessageResources messageResources = getResources(request, encounterForm.getClassname() + "Messages"); String messageKey = encounterForm.getClassname() + "Messages"; ReloadablePropertyMessageResources messages = (ReloadablePropertyMessageResources) request .getAttribute(messageKey); //ZcorePropertyMessageResources sMessages = (ZcorePropertyMessageResources) messages; HashMap messageResourcesMap = messages.getMessages(); HashMap localeMap = messages.getLocales(); if (localeMap.get(sessionLocale.toString()) == null) { messages.loadLocale(sessionLocale.toString()); } // Attach a map of encounter values that has enumerations already resolved. Form encForm = (Form) DynaSiteObjects.getForms().get(encounterForm.getId()); for (int i = 0; i < chartItems.size(); i++) { encounter = (EncounterData) chartItems.get(i); encMap = PatientRecordUtils.getEncounterMap(encForm, encounter, "fieldId"); encounter.setEncounterMap(encMap); if (messageResourcesMap != null) { encounter.setMessageResourcesMap(messageResourcesMap); } } if (chartItems.size() > 0) { request.setAttribute("chartItems", chartItems); request.setAttribute("formId", encounterForm.getId()); // loading of body onload DWRUtil.useLoadingMessage() request.setAttribute("dwr", 1); } // Process the dynamic dropdown lists. HashMap listMap = new HashMap(); Form inlineForm = null; for (Iterator iterator = encounterForm.getPageItems().iterator(); iterator.hasNext();) { PageItem pageItem = (PageItem) iterator.next(); FormField formField = pageItem.getForm_field(); String identifier = formField.getIdentifier(); if (pageItem.getInputType().equals("dropdown") || pageItem.getInputType().equals("dropdown-add-one") || pageItem.getInputType().equals("dropdown_site")) { List list = WidgetUtils.getList(conn, pageItem.getDropdownTable(), pageItem.getDropdownColumn(), pageItem.getDropdownConstraint(), pageItem.getDropdownOrderByClause(), DropdownItem.class, pageItem.getFkIdentifier()); listMap.put(pageItem.getId(), list); if (pageItem.getInputType().equals("dropdown-add-one")) { String classNameString = StringManipulation.fixClassname(pageItem.getDropdownTable()); Long inlineFormId = (Long) DynaSiteObjects.getFormNameMap().get(classNameString); inlineForm = ((Form) DynaSiteObjects.getForms().get(new Long(inlineFormId))); // Create a list of fieldnames for inline forms. ArrayList<String> inlineFields = new ArrayList<String>(); for (Iterator iterator2 = inlineForm.getPageItems().iterator(); iterator2.hasNext();) { PageItem pageItem2 = (PageItem) iterator2.next(); if (pageItem2.getForm_field().isEnabled() == true && !pageItem2.getForm_field().getType().equals("Display")) { inlineFields.add(pageItem2.getForm_field().getIdentifier()); } } request.setAttribute("inlineForm_" + identifier, inlineForm); request.setAttribute("inlineFields_" + identifier, inlineFields); // loading of body onload DWRUtil.useLoadingMessage() request.setAttribute("dwr", 1); } } } request.setAttribute("listMap", listMap); request.setAttribute("encounterForm", encounterForm); // Keep this block at the end - it sets sessionPatient to null in certain circumstances. // Set the tasklist for particular circumstances. First check if the form requires a patient or if "id" is in the reqiest. if ((encounterForm.isRequirePatient() || ((request.getParameter("id") != null)))) { // we don't need the tasklist if we're just editing a form or it's in unassigned flow Long unassigned = new Long("100"); if (request.getParameter("id") == null) { if (!encounterForm.getFlow().getId().equals(unassigned)) { // moved code for form 66 below. } } Boolean status = Boolean.valueOf(true); List activeProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status, sessionPatient); request.setAttribute("activeProblems", activeProblems); // now get inactive problems status = Boolean.valueOf(false); List inactiveProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status, sessionPatient); request.setAttribute("inactiveProblems", inactiveProblems); // Display task list if editing form 1. } else if ((encounterForm.getId().intValue() == 1) & (patientId != null)) { Boolean status = Boolean.valueOf(true); List activeProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status, sessionPatient); request.setAttribute("activeProblems", activeProblems); // now get inactive problems status = Boolean.valueOf(false); List inactiveProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status, sessionPatient); request.setAttribute("inactiveProblems", inactiveProblems); // otherwise reset sessionPatient } else { SessionUtil.getInstance(session).setSessionPatient(null); } } catch (ServletException e) { log.error(e); } finally { if (conn != null && !conn.isClosed()) { conn.close(); } } encounterForm = null; return mapping.findForward("success"); }
From source file:org.apache.cocoon.matching.LocaleMatcher.java
private boolean isValidResource(String pattern, Locale locale, Map map) { Locale testLocale;/*from w w w. j a v a 2 s. c o m*/ // Test "language, country, variant" locale if (locale.getVariant().length() > 0) { if (isValidResource(pattern, locale, locale, map)) { return true; } } // Test "language, country" locale if (locale.getCountry().length() > 0) { testLocale = new Locale(locale.getLanguage(), locale.getCountry()); if (isValidResource(pattern, locale, testLocale, map)) { return true; } } // Test "language" locale (or empty - if language is "") testLocale = new Locale(locale.getLanguage(), ""); // Use JDK1.3 constructor if (isValidResource(pattern, locale, testLocale, map)) { return true; } return false; }
From source file:com.globalsight.machineTranslation.domt.DoMTProxy.java
private String getDoMtXliff(HashMap<Integer, String> segmentsNoTag, Locale sourceLocale, Locale targetLocale) { String sourceLang = DoMTUtil.checkLang(sourceLocale.getLanguage(), sourceLocale.getCountry()); String targetLang = DoMTUtil.checkLang(targetLocale.getLanguage(), targetLocale.getCountry()); String engineName = (String) getMtParameterMap().get(MTProfileConstants.MT_DOMT_ENGINE_NAME); // "translate-xliff" is a default engine on DoMT server, it is using // "nl" and "en" as source/target language name. if (DEFAULT_ENGINE_NAME.equals(engineName)) { sourceLang = "nl"; targetLang = "en"; }//ww w .j a v a 2 s. c om StringBuffer xlf = new StringBuffer(); xlf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); xlf.append("<xliff version=\"1.2\">\r\n"); xlf.append("<file original=\"None\" source-language=\"").append(sourceLang).append("\" target-language=\"") .append(targetLang).append("\" datatype=\"multi-format\">\r\n"); xlf.append("<header>\r\n"); xlf.append(" <note from=\"PTTOOLS\">\r\n"); xlf.append(" <graphname>").append(engineName).append("</graphname>\r\n"); xlf.append(" </note>\r\n"); xlf.append("</header>\r\n"); xlf.append("<body>\r\n"); Iterator<Entry<Integer, String>> it = segmentsNoTag.entrySet().iterator(); while (it.hasNext()) { Entry<Integer, String> entry = (Entry<Integer, String>) it.next(); int id = entry.getKey(); String source = entry.getValue(); xlf.append("<trans-unit id=\"" + id + "\" translate=\"yes\">\r\n"); xlf.append("<source>").append(source).append("</source>\r\n"); xlf.append("</trans-unit>\r\n"); } xlf.append("</body>\r\n"); xlf.append("</file>\r\n"); xlf.append("</xliff>\r\n"); return xlf.toString(); }
From source file:com.parking.billing.ParkingPayment.java
/** * Replaces the language and/or country of the device into the given string. * The pattern "%lang%" will be replaced by the device's language code and * the pattern "%region%" will be replaced with the device's country code. * * @param str the string to replace the language/country within * @return a string containing the local language and region codes *///from w ww. j a v a 2s . c o m private String replaceLanguageAndRegion(String str) { // Substitute language and or region if present in string if (str.contains("%lang%") || str.contains("%region%")) { Locale locale = Locale.getDefault(); str = str.replace("%lang%", locale.getLanguage().toLowerCase()); str = str.replace("%region%", locale.getCountry().toLowerCase()); } return str; }
From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithArrayTest.java
@Test public void testConfigurationPropertiesWithLocaleArray() { ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray(); Locale localeValue = config.localeArray[0]; Locale localeValue2 = config.localeArray[1]; assertEquals(Locale.class, localeValue.getClass()); assertEquals(Locale.ENGLISH, localeValue); assertEquals("BR", localeValue2.getCountry()); assertEquals(3, config.localeArray.length); }
From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithArrayTest.java
@Test public void testConfigurationXMLWithLocaleArray() { ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray(); Locale localeValue = config.localeArray[0]; Locale localeValue2 = config.localeArray[1]; assertEquals(Locale.class, localeValue.getClass()); assertEquals(Locale.ENGLISH, localeValue); assertEquals("BR", localeValue2.getCountry()); assertEquals(3, config.localeArray.length); }
From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithListTest.java
@Test public void testConfigurationPropertiesWithLocaleList() { ConfigurationPropertiesWithList config = prepareConfigurationPropertiesWithList(); Locale localeValue = config.localeList.get(0); Locale localeValue2 = config.localeList.get(1); assertEquals(Locale.class, localeValue.getClass()); assertEquals(Locale.ENGLISH, localeValue); assertEquals("BR", localeValue2.getCountry()); assertEquals(3, config.localeList.size()); }
From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithListTest.java
@Test public void testConfigurationXMLWithLocaleList() { ConfigurationXMLWithList config = prepareConfigurationXMLWithList(); Locale localeValue = config.localeList.get(0); Locale localeValue2 = config.localeList.get(1); assertEquals(Locale.class, localeValue.getClass()); assertEquals(Locale.ENGLISH, localeValue); assertEquals("BR", localeValue2.getCountry()); assertEquals(3, config.localeList.size()); }