List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:com.livinglogic.ul4.FunctionFormat.java
public static String call(Date obj, String formatString, Locale locale) { if (locale == null) locale = Locale.ENGLISH;//from w w w . j a v a 2s .co m Calendar calendar = new GregorianCalendar(); calendar.setTime((Date) obj); StringBuilder buffer = new StringBuilder(); boolean escapeCharacterFound = false; int formatStringLength = formatString.length(); for (int i = 0; i < formatStringLength; i++) { char c = formatString.charAt(i); if (escapeCharacterFound) { switch (c) { case 'a': buffer.append(new SimpleDateFormat("EE", locale).format(obj)); break; case 'A': buffer.append(new SimpleDateFormat("EEEE", locale).format(obj)); break; case 'b': buffer.append(new SimpleDateFormat("MMM", locale).format(obj)); break; case 'B': buffer.append(new SimpleDateFormat("MMMM", locale).format(obj)); break; case 'c': { String format = cFormats.get(locale.getLanguage()); if (format == null) format = cFormats.get("en"); buffer.append(call(obj, format, locale)); break; } case 'd': buffer.append(twodigits.format(calendar.get(Calendar.DAY_OF_MONTH))); break; case 'f': buffer.append(sixdigits.format(calendar.get(Calendar.MILLISECOND) * 1000)); break; case 'H': buffer.append(twodigits.format(calendar.get(Calendar.HOUR_OF_DAY))); break; case 'I': buffer.append(twodigits.format(((calendar.get(Calendar.HOUR_OF_DAY) - 1) % 12) + 1)); break; case 'j': buffer.append(threedigits.format(calendar.get(Calendar.DAY_OF_YEAR))); break; case 'm': buffer.append(twodigits.format(calendar.get(Calendar.MONTH) + 1)); break; case 'M': buffer.append(twodigits.format(calendar.get(Calendar.MINUTE))); break; case 'p': buffer.append(new SimpleDateFormat("aa", locale).format(obj)); break; case 'S': buffer.append(twodigits.format(calendar.get(Calendar.SECOND))); break; case 'U': buffer.append(twodigits.format(BoundDateMethodWeek.call(obj, 6))); break; case 'w': buffer.append(weekdayFormats.get(calendar.get(Calendar.DAY_OF_WEEK))); break; case 'W': buffer.append(twodigits.format(BoundDateMethodWeek.call(obj, 0))); break; case 'x': { String format = xFormats.get(locale.getLanguage()); if (format == null) format = xFormats.get("en"); buffer.append(call(obj, format, locale)); break; } case 'X': { String format = XFormats.get(locale.getLanguage()); if (format == null) format = XFormats.get("en"); buffer.append(call(obj, format, locale)); break; } case 'y': buffer.append(twodigits.format(calendar.get(Calendar.YEAR) % 100)); break; case 'Y': buffer.append(fourdigits.format(calendar.get(Calendar.YEAR))); break; default: buffer.append(c); break; } escapeCharacterFound = false; } else { if (c == '%') escapeCharacterFound = true; else buffer.append(c); } } if (escapeCharacterFound) buffer.append('%'); return buffer.toString(); }
From source file:com.example.mynsocial.BluetoothChat.java
NdefMessage create_RTD_TEXT_NdefMessage(String inputText) { Log.e(TAG, "+++ create_RTD +++"); Locale locale = new Locale("en", "US"); byte[] langBytes = locale.getLanguage().getBytes(Charset.forName("US-ASCII")); boolean encodeInUtf8 = false; Charset utfEncoding = encodeInUtf8 ? Charset.forName("UTF-8") : Charset.forName("UTF-16"); int utfBit = encodeInUtf8 ? 0 : (1 << 7); byte status = (byte) (utfBit + langBytes.length); byte[] textBytes = inputText.getBytes(utfEncoding); byte[] data = new byte[1 + langBytes.length + textBytes.length]; data[0] = (byte) status; System.arraycopy(langBytes, 0, data, 1, langBytes.length); System.arraycopy(textBytes, 0, data, 1 + langBytes.length, textBytes.length); NdefRecord textRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data); NdefMessage message = new NdefMessage(new NdefRecord[] { textRecord }); return message; }
From source file:org.ng200.openolympus.controller.task.TaskViewController.java
@RequestMapping(method = RequestMethod.GET) public String showTaskView(@PathVariable(value = "task") final Task task, final Model model, final Locale locale, final SolutionDto solutionDto, final Principal principal) { Assertions.resourceExists(task);//from w w w . j a v a2 s . co m this.assertSuperuserOrTaskAllowed(principal, task); model.addAttribute("taskDescriptionUUID", task.getDescriptionFile()); model.addAttribute("taskDescriptionURI", MessageFormat.format(TaskViewController.TASK_DESCRIPTION_PATH_TEMPLATE, task.getDescriptionFile())); model.addAttribute("localisedDescriptionFragment", "taskDescription_" + locale.getLanguage()); model.addAttribute("task", task); return "tasks/task"; }
From source file:de.fau.amos4.model.Employee.java
public Map<String, String> getFields() { Map<String, String> allFields = new LinkedHashMap<String, String>(); Locale locale = LocaleContextHolder.getLocale(); DateFormat format = DateFormat.getDateInstance(DateFormat.LONG, locale); DateFormat df;/*from ww w . j av a 2 s.c o m*/ if (locale.getLanguage().equals("de")) { df = new SimpleDateFormat("dd.MM.yyyy"); } else { df = new SimpleDateFormat("dd/MM/yyyy"); } allFields.put(AppContext.getApplicationContext().getMessage("employee.id", null, locale), Long.toString(getId())); allFields.put(AppContext.getApplicationContext().getMessage("client.companyName", null, locale), getClient().getCompanyName()); allFields.put(AppContext.getApplicationContext().getMessage("employee.personnelNumber", null, locale), Long.toString(getPersonnelNumber())); allFields.put(AppContext.getApplicationContext().getMessage("employee.firstName", null, locale), getFirstName()); allFields.put(AppContext.getApplicationContext().getMessage("employee.familyName", null, locale), getFamilyName()); allFields.put(AppContext.getApplicationContext().getMessage("employee.maidenName", null, locale), getMaidenName()); allFields.put(AppContext.getApplicationContext().getMessage("employee.birthDate", null, locale), format.format(getBirthDate())); allFields.put(AppContext.getApplicationContext().getMessage("employee.placeOfBirth", null, locale), getPlaceOfBirth()); allFields.put(AppContext.getApplicationContext().getMessage("employee.countryOfBirth", null, locale), getCountryOfBirth()); allFields.put(AppContext.getApplicationContext().getMessage("employee.street", null, locale), getStreet()); allFields.put(AppContext.getApplicationContext().getMessage("employee.houseNumber", null, locale), getHouseNumber()); allFields.put(AppContext.getApplicationContext().getMessage("employee.additionToAddress", null, locale), getAdditionToAddress()); allFields.put(AppContext.getApplicationContext().getMessage("employee.city", null, locale), getCity()); allFields.put(AppContext.getApplicationContext().getMessage("employee.zipCode", null, locale), getZipCode()); allFields.put(AppContext.getApplicationContext().getMessage("employee.sex", null, locale), getSex().toString()); allFields.put(AppContext.getApplicationContext().getMessage("employee.maritalStatus", null, locale), getMaritalStatus().toString()); allFields.put(AppContext.getApplicationContext().getMessage("employee.disabled", null, locale), getDisabled().toString()); allFields.put(AppContext.getApplicationContext().getMessage("employee.citizenship", null, locale), getCitizenship()); allFields.put(AppContext.getApplicationContext().getMessage("employee.socialInsuranceNumber", null, locale), getSocialInsuranceNumber()); allFields.put( AppContext.getApplicationContext().getMessage("employee.employerSocialSavingsNumber", null, locale), getEmployerSocialSavingsNumber()); allFields.put(AppContext.getApplicationContext().getMessage("employee.iban", null, locale), getIban()); allFields.put(AppContext.getApplicationContext().getMessage("employee.bic", null, locale), getBic()); allFields.put(AppContext.getApplicationContext().getMessage("employee.employment", null, locale), getEmployment()); allFields.put(AppContext.getApplicationContext().getMessage("employee.temporaryEmployment", null, locale), getTemporaryEmployment()); //allFields.put( AppContext.getApplicationContext().getMessage("employee.token", null, locale), getToken()); return allFields; }
From source file:org.kuali.mobility.push.controllers.PushController.java
/** * A method to get predefined PushMessages. Pulled from Database by Locale attribute. * Stock Push Messages are inserted during the PushBootListener bootstrapping. * * @param locale/*from w w w . ja va 2 s. c om*/ * @return Map<String, String> of push Messages. */ public Map<String, String> getPushMessages(Locale locale) { List<PushMessage> pms = pushMessageService.findAllPushMessagesByLanguage(locale.getLanguage()); Map<String, String> pushMessages = new LinkedHashMap<String, String>(); Iterator<PushMessage> it = pms.iterator(); while (it.hasNext()) { PushMessage pm = it.next(); pushMessages.put(pm.getTitle(), pm.getMessage()); } return pushMessages; }
From source file:com.github.mrstampy.gameboot.usersession.processor.UserMessageProcessorTest.java
private User languageCodeTest(User user, UserMessage m) throws Exception { assertNotEquals(LANGUAGE_CODE, user.getLanguageCode()); m.setLanguageCode(LANGUAGE_CODE);/*from w w w . j a v a 2s .com*/ m.setSystemId(SYSTEM_ID); // set by the system user = updateCheck(processor.process(m)); assertEquals(LANGUAGE_CODE, user.getLanguageCode()); assertEquals(1, registry.size()); Locale locale = registry.get(SYSTEM_ID); assertEquals(LANGUAGE_CODE, locale.getLanguage()); m.setLanguageCode(null); return user; }
From source file:com.github.mrstampy.gameboot.usersession.processor.UserMessageProcessorTest.java
private User countryCodeTest(User user, UserMessage m) throws Exception { assertNotEquals(COUNTRY_CODE, user.getCountryCode()); m.setCountryCode(COUNTRY_CODE);//from w ww. j av a 2s . c o m m.setSystemId(SYSTEM_ID); // set by the system user = updateCheck(processor.process(m)); assertEquals(COUNTRY_CODE, user.getCountryCode()); assertEquals(1, registry.size()); Locale locale = registry.get(SYSTEM_ID); assertEquals(LANGUAGE_CODE, locale.getLanguage()); assertEquals(COUNTRY_CODE, locale.getCountry()); m.setCountryCode(null); return user; }
From source file:com.octo.captcha.engine.bufferedengine.BufferedEngineContainer.java
/** * Helper for locale//from w w w . j a va 2 s.co m */ private Locale resolveLocale(Locale locale) { if (!config.isServeOnlyConfiguredLocales()) { return locale; } else { if (this.config.getLocaleRatio().containsKey(locale)) { return locale; //try to resolve by language } else if (this.config.getLocaleRatio().containsKey(locale.getLanguage())) { return new Locale(locale.getLanguage()); } else { return config.getDefaultLocale(); } } }
From source file:de.ingrid.portal.portlets.ContactPortlet.java
public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, IOException { List<FileItem> items = null; File uploadFile = null;// w ww .j a va 2s . c o m boolean uploadEnable = PortalConfig.getInstance().getBoolean(PortalConfig.PORTAL_CONTACT_UPLOAD_ENABLE, Boolean.FALSE); int uploadSize = PortalConfig.getInstance().getInt(PortalConfig.PORTAL_CONTACT_UPLOAD_SIZE, 10); RequestContext requestContext = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV); HttpServletRequest servletRequest = requestContext.getRequest(); if (ServletFileUpload.isMultipartContent(servletRequest)) { DiskFileItemFactory factory = new DiskFileItemFactory(); // Set factory constraints factory.setSizeThreshold(uploadSize * 1000 * 1000); File file = new File("."); factory.setRepository(file); ServletFileUpload.isMultipartContent(servletRequest); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Set overall request size constraint upload.setSizeMax(uploadSize * 1000 * 1000); // Parse the request try { items = upload.parseRequest(servletRequest); } catch (FileUploadException e) { // TODO Auto-generated catch block } } if (items != null) { // check form input if (request.getParameter(PARAMV_ACTION_DB_DO_REFRESH) != null) { ContactForm cf = (ContactForm) Utils.getActionForm(request, ContactForm.SESSION_KEY, ContactForm.class); cf.populate(items); String urlViewParam = "?" + Utils.toURLParam(Settings.PARAM_ACTION, Settings.MSGV_TRUE); actionResponse.sendRedirect(actionResponse.encodeURL(Settings.PAGE_CONTACT + urlViewParam)); return; } else { Boolean isResponseCorrect = false; ContactForm cf = (ContactForm) Utils.getActionForm(request, ContactForm.SESSION_KEY, ContactForm.class); cf.populate(items); if (!cf.validate()) { // add URL parameter indicating that portlet action was called // before render request String urlViewParam = "?" + Utils.toURLParam(Settings.PARAM_ACTION, Settings.MSGV_TRUE); actionResponse.sendRedirect(actionResponse.encodeURL(Settings.PAGE_CONTACT + urlViewParam)); return; } //remenber that we need an id to validate! String sessionId = request.getPortletSession().getId(); //retrieve the response boolean enableCaptcha = PortalConfig.getInstance().getBoolean("portal.contact.enable.captcha", Boolean.TRUE); if (enableCaptcha) { String response = request.getParameter("jcaptcha"); for (FileItem item : items) { if (item.getFieldName() != null) { if (item.getFieldName().equals("jcaptcha")) { response = item.getString(); break; } } } // Call the Service method try { isResponseCorrect = CaptchaServiceSingleton.getInstance().validateResponseForID(sessionId, response); } catch (CaptchaServiceException e) { //should not happen, may be thrown if the id is not valid } } if (isResponseCorrect || !enableCaptcha) { try { IngridResourceBundle messages = new IngridResourceBundle( getPortletConfig().getResourceBundle(request.getLocale()), request.getLocale()); HashMap mailData = new HashMap(); mailData.put("user.name.given", cf.getInput(ContactForm.FIELD_FIRSTNAME)); mailData.put("user.name.family", cf.getInput(ContactForm.FIELD_LASTNAME)); mailData.put("user.employer", cf.getInput(ContactForm.FIELD_COMPANY)); mailData.put("user.business-info.telecom.telephone", cf.getInput(ContactForm.FIELD_PHONE)); mailData.put("user.business-info.online.email", cf.getInput(ContactForm.FIELD_EMAIL)); mailData.put("user.area.of.profession", messages.getString("contact.report.email.area.of.profession." + cf.getInput(ContactForm.FIELD_ACTIVITY))); mailData.put("user.interest.in.enviroment.info", messages.getString("contact.report.email.interest.in.enviroment.info." + cf.getInput(ContactForm.FIELD_INTEREST))); if (cf.hasInput(ContactForm.FIELD_NEWSLETTER)) { Session session = HibernateUtil.currentSession(); Transaction tx = null; try { mailData.put("user.subscribed.to.newsletter", "yes"); // check for email address in newsletter list tx = session.beginTransaction(); List newsletterDataList = session.createCriteria(IngridNewsletterData.class) .add(Restrictions.eq("emailAddress", cf.getInput(ContactForm.FIELD_EMAIL))) .list(); tx.commit(); // register for newsletter if not already registered if (newsletterDataList.isEmpty()) { IngridNewsletterData data = new IngridNewsletterData(); data.setFirstName(cf.getInput(ContactForm.FIELD_FIRSTNAME)); data.setLastName(cf.getInput(ContactForm.FIELD_LASTNAME)); data.setEmailAddress(cf.getInput(ContactForm.FIELD_EMAIL)); data.setDateCreated(new Date()); tx = session.beginTransaction(); session.save(data); tx.commit(); } } catch (Throwable t) { if (tx != null) { tx.rollback(); } throw new PortletException(t.getMessage()); } finally { HibernateUtil.closeSession(); } } else { mailData.put("user.subscribed.to.newsletter", "no"); } mailData.put("message.body", cf.getInput(ContactForm.FIELD_MESSAGE)); Locale locale = request.getLocale(); String language = locale.getLanguage(); String localizedTemplatePath = EMAIL_TEMPLATE; int period = localizedTemplatePath.lastIndexOf("."); if (period > 0) { String fixedTempl = localizedTemplatePath.substring(0, period) + "_" + language + "." + localizedTemplatePath.substring(period + 1); if (new File(getPortletContext().getRealPath(fixedTempl)).exists()) { localizedTemplatePath = fixedTempl; } } String emailSubject = messages.getString("contact.report.email.subject"); if (PortalConfig.getInstance().getBoolean("email.contact.subject.add.topic", Boolean.FALSE)) { if (cf.getInput(ContactForm.FIELD_ACTIVITY) != null && !cf.getInput(ContactForm.FIELD_ACTIVITY).equals("none")) { emailSubject = emailSubject + " - " + messages.getString("contact.report.email.area.of.profession." + cf.getInput(ContactForm.FIELD_ACTIVITY)); } } String from = cf.getInput(ContactForm.FIELD_EMAIL); String to = PortalConfig.getInstance().getString(PortalConfig.EMAIL_CONTACT_FORM_RECEIVER, "foo@bar.com"); String text = Utils.mergeTemplate(getPortletConfig(), mailData, "map", localizedTemplatePath); if (uploadEnable) { if (uploadEnable) { for (FileItem item : items) { if (item.getFieldName() != null) { if (item.getFieldName().equals("upload")) { uploadFile = new File(sessionId + "_" + item.getName()); // read this file into InputStream InputStream inputStream = item.getInputStream(); // write the inputStream to a FileOutputStream OutputStream out = new FileOutputStream(uploadFile); int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { out.write(bytes, 0, read); } inputStream.close(); out.flush(); out.close(); break; } } } } Utils.sendEmail(from, emailSubject, new String[] { to }, text, null, uploadFile); } else { Utils.sendEmail(from, emailSubject, new String[] { to }, text, null); } } catch (Throwable t) { cf.setError("", "Error sending mail from contact form."); log.error("Error sending mail from contact form.", t); } // temporarily show same page with content String urlViewParam = "?" + Utils.toURLParam(Settings.PARAM_ACTION, PARAMV_ACTION_SUCCESS); actionResponse.sendRedirect(actionResponse.encodeURL(Settings.PAGE_CONTACT + urlViewParam)); } else { cf.setErrorCaptcha(); String urlViewParam = "?" + Utils.toURLParam(Settings.PARAM_ACTION, Settings.MSGV_TRUE); actionResponse.sendRedirect(actionResponse.encodeURL(Settings.PAGE_CONTACT + urlViewParam)); return; } } } else { ContactForm cf = (ContactForm) Utils.getActionForm(request, ContactForm.SESSION_KEY, ContactForm.class); cf.setErrorUpload(); String urlViewParam = "?" + Utils.toURLParam(Settings.PARAM_ACTION, Settings.MSGV_TRUE); actionResponse.sendRedirect(actionResponse.encodeURL(Settings.PAGE_CONTACT + urlViewParam)); return; } }
From source file:com.m2a.struts.M2AFormBase.java
public String getLocaleLanguage() { Locale locale = getSessionLocale(); if (null == locale) { locale = Locale.getDefault(); }/*w w w .j a v a 2 s. c o m*/ return locale.getLanguage(); }