List of usage examples for java.util Locale Locale
public Locale(String language, String country)
From source file:com.opensymphony.xwork2.conversion.impl.NumberConverterTest.java
public void testStringToBigDecimalConversionPL() throws Exception { // given/* w w w . j a v a 2s.c o m*/ NumberConverter converter = new NumberConverter(); Map<String, Object> context = new HashMap<>(); context.put(ActionContext.LOCALE, new Locale("pl", "PL")); // when a bit bigger than double String aBitBiggerThanDouble = "17976931348623157" + StringUtils.repeat('0', 291) + "1," + StringUtils.repeat('0', 324) + "49"; Object value = converter.convertValue(context, null, null, null, aBitBiggerThanDouble, BigDecimal.class); // then does not lose integer and fraction digits assertEquals( new BigDecimal(aBitBiggerThanDouble.substring(0, 309) + "." + aBitBiggerThanDouble.substring(310)), value); }
From source file:com.rasrin.locale.formatter.plugin.LocaleFormatter.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try {/* w w w.j a v a 2 s. c o m*/ if (action.equals("formatCurrency")) { if (args.length() < 3) { callbackContext.error("Expected 3 arguments."); return false; } String ilocale = args.getString(0); long amount = args.getLong(1); boolean debug = args.getBoolean(2); Locale locale = new Locale("en", "US"); if (ilocale != null && ilocale.length() <= 5) { if (ilocale.indexOf('-') > 0) { String[] parts = ilocale.split("-"); locale = new Locale(parts[0], parts[1]); } } NumberFormat formatter = NumberFormat.getCurrencyInstance(locale); String moneyString = formatter.format(amount); if (debug) { System.out.println("Called with locale: " + ilocale + " & amount: " + amount + ". Formatted string is: " + moneyString); } callbackContext.success(moneyString); return true; } else { callbackContext.error("Unsupported operation"); return false; } } catch (Exception ex) { callbackContext.error("Something went wrong: " + ex.getMessage()); return false; } }
From source file:com.norconex.jefmon.JEFMonSession.java
private void initLocale() { String cookieLocale = new CookieUtils().load(SessionLocaleUtils.COOKIE_LOCALE_KEY); Locale[] locales = getApp().getSupportedLocales(); Locale locale = null;//from w w w. j ava2 s . c o m if (StringUtils.isNotBlank(cookieLocale)) { locale = LocaleUtils.toLocale(cookieLocale); } if (!ArrayUtils.contains(locales, locale)) { locale = getLocale(); if (!ArrayUtils.contains(locales, locale) && locale.getCountry() != null) { locale = new Locale(locale.getLanguage(), locale.getCountry()); } if (!ArrayUtils.contains(locales, locale)) { locale = new Locale(locale.getLanguage()); } if (!ArrayUtils.contains(locales, locale)) { locale = locales[0]; } if (LOG.isDebugEnabled()) { LOG.debug("User initial locale is:" + locale); } } setLocale(locale); }
From source file:de.matzefratze123.heavyspleef.core.i18n.YMLControl.java
@Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { List<Locale> candidates = Lists.newArrayList(); candidates.add(locale);//from ww w. j ava2 s. co m if (!locale.getLanguage().isEmpty() && !locale.getCountry().isEmpty() && !locale.getVariant().isEmpty()) { candidates.add(new Locale(locale.getLanguage(), locale.getCountry())); candidates.add(new Locale(locale.getLanguage())); } else if (!locale.getLanguage().isEmpty() && !locale.getCountry().isEmpty()) { candidates.add(new Locale(locale.getLanguage())); } candidates.add(Locale.US); candidates.add(Locale.ROOT); return candidates; }
From source file:com.wordsbaking.cordova.tts.TTS.java
@Override public void onInit(int status) { if (status != TextToSpeech.SUCCESS) { tts = null;/* w w w. jav a2 s. c o m*/ } else { // warm up the tts engine with an empty string HashMap<String, String> ttsParams = new HashMap<String, String>(); ttsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, ""); tts.setLanguage(new Locale("en", "US")); tts.speak("", TextToSpeech.QUEUE_FLUSH, ttsParams); ttsInitialized = true; } }
From source file:ch.entwine.weblounge.common.impl.language.LanguageUtils.java
/** * Returns the language object that represents the given locale. * //w w w . ja v a 2 s .co m * @param locale * the locale * @return the language * @throws UnknownLanguageException * if there is no language for the given locale */ public static Language getLanguage(Locale locale) throws UnknownLanguageException { // Do we know this language already? Language language = systemLanguages.get(locale.getLanguage()); if (language != null) return language; // Makes sure we get the locale in the right format (might be hand crafted) Matcher matcher = ACCEPT_LANGUAGE_HEADER.matcher(locale.getLanguage()); if (matcher.matches()) { locale = new Locale(matcher.group(2), matcher.group(1)); } // Check the system locales for a match Locale systemLocale = null; try { for (Locale l : Locale.getAvailableLocales()) { if (l.getISO3Language().equals(locale.getISO3Language())) { systemLocale = l; break; } else if (l.getLanguage().equals(l.getLanguage())) { systemLocale = l; break; } } } catch (MissingResourceException e) { logger.debug("No 3 found for '{}': {}", locale, e.getMessage()); } // Is there a matching system locale? if (systemLocale != null) { language = new LanguageImpl(locale); systemLanguages.put(locale.getLanguage(), language); return language; } // Apparently not... throw new UnknownLanguageException(locale.getLanguage()); }
From source file:com.smi.travel.datalayer.view.dao.impl.TicketOrderImpl.java
@Override public TicketOrder getTicketOrder(String refno, String pnrID) { Session session = this.sessionFactory.openSession(); UtilityFunction util = new UtilityFunction(); TicketOrder ticket = new TicketOrder(); int price = 0; int priceTax = 0; int cost = 0; int costtax = 0; List<Object[]> QueryTicketInfo = session .createSQLQuery(" SELECT * FROM `ticket_order_info` where `ticket_order_info`.pnr_id = " + pnrID) .addScalar("ref_no", Hibernate.STRING).addScalar("leader_name", Hibernate.STRING) .addScalar("bill_date", Hibernate.DATE).addScalar("company_name", Hibernate.STRING) .addScalar("tel", Hibernate.STRING).addScalar("pnr", Hibernate.STRING) .addScalar("inv", Hibernate.STRING).addScalar("sell", Hibernate.STRING) .addScalar("sell_tax", Hibernate.STRING).addScalar("net", Hibernate.STRING) .addScalar("net_tax", Hibernate.STRING).addScalar("term_of_payment", Hibernate.STRING) .addScalar("remark", Hibernate.STRING).addScalar("prepare_by", Hibernate.STRING) .addScalar("issue_by", Hibernate.STRING).list(); for (Object[] B : QueryTicketInfo) { ticket.setRefno(util.ConvertString(B[0])); ticket.setLeadername(util.ConvertString(B[1])); if (B[2] != null) { ticket.setIssuedate(/*w w w.ja v a 2 s .c o m*/ new SimpleDateFormat("dd MMM yyyy", new Locale("us", "us")).format(((Date) B[2]))); } ticket.setCompanyname(util.ConvertString(B[3])); ticket.setTel(util.ConvertString(B[4])); ticket.setPnr(util.ConvertString(B[5])); ticket.setInv(util.ConvertString(B[6])); ticket.setPrice(util.ConvertString(B[7])); ticket.setPricetax(util.ConvertString(B[8])); ticket.setCost(util.ConvertString(B[9])); ticket.setCosttax(util.ConvertString(B[10])); ticket.setTermpay(util.ConvertString(B[11])); ticket.setRemark(util.ConvertString(B[12])); ticket.setPrepareby(util.ConvertString(B[13])); ticket.setIssueby(util.ConvertString(B[14])); } List<Object[]> QueryFlightList = session .createSQLQuery( "SELECT * FROM `ticket_order_flight` Where `ticket_order_flight`.pnr_id = " + pnrID) .addScalar("flight_no", Hibernate.STRING).addScalar("filght_class", Hibernate.STRING) .addScalar("depart_date", Hibernate.STRING).addScalar("from", Hibernate.STRING) .addScalar("to", Hibernate.STRING).addScalar("depart_time", Hibernate.STRING) .addScalar("arrive_time", Hibernate.STRING).addScalar("flight_status", Hibernate.STRING).list(); List flights = new ArrayList(); for (int i = 0; i < QueryFlightList.size(); i++) { Object[] flightInfo = QueryFlightList.get(i); TicketOrderFlight f = new TicketOrderFlight(); f.setFlightNo(util.ConvertString(flightInfo[0])); f.setFlightClass(util.ConvertString(flightInfo[1])); f.setDepartdate(util.ConvertString(flightInfo[2])); f.setFrom(util.ConvertString(flightInfo[3])); f.setTo(util.ConvertString(flightInfo[4])); f.setDepttime(util.ConvertString(flightInfo[5])); f.setArrvtime(util.ConvertString(flightInfo[6])); f.setStatus(util.ConvertString(flightInfo[7])); flights.add(f); } ticket.setFlightDataSource(new JRBeanCollectionDataSource(flights)); List<Object[]> QueryDescList = session .createSQLQuery("SELECT * FROM `ticket_order_desc` where `ticket_order_desc`.ref_no = " + refno) .addScalar("description", Hibernate.STRING).addScalar("net", Hibernate.STRING) .addScalar("sell", Hibernate.STRING).list(); for (int i = 0; i < QueryDescList.size(); i++) { Object[] data = QueryDescList.get(i); if (i == 0) { ticket.setDescription1(util.ConvertString(data[0])); ticket.setNet1(util.ConvertString(data[1])); ticket.setSell1(util.ConvertString(data[2])); } else if (i == 1) { ticket.setDescription2(util.ConvertString(data[0])); ticket.setNet2(util.ConvertString(data[1])); ticket.setSell2(util.ConvertString(data[2])); } } List<Object[]> QueryPassengerList = session .createSQLQuery( "SELECT * FROM `ticket_order_passenger` where `ticket_order_passenger`.pnr_id = " + pnrID) .addScalar("passenger_name", Hibernate.STRING).addScalar("ticket_no", Hibernate.STRING).list(); List passengers = new ArrayList(); for (int i = 0; i < QueryPassengerList.size(); i++) { Object[] passname = QueryPassengerList.get(i); TicketOrderPassenger p = new TicketOrderPassenger(); p.setNameAndTicket(util.ConvertString(passname[0]) + " " + util.ConvertString(passname[1])); passengers.add(p); } ticket.setPassengerNameAndTicketDataSource(new JRBeanCollectionDataSource(passengers)); session.close(); this.sessionFactory.close(); return ticket; }
From source file:com.carser.viamais.entity.Transaction.java
public void generateReceipt(final OutputStream os, final String template) throws IOException, DocumentException { reader = new PdfReader(this.getClass().getResourceAsStream("/receipts/" + template)); stamper = new PdfStamper(reader, os); form = stamper.getAcroFields();/*w w w . j a v a 2s . c om*/ brazilLocale = new Locale("pt", "BR"); formatter = NumberFormat.getCurrencyInstance(brazilLocale); // Customer data Customer customer = getCustomer(); form.setField("CUSTOMER_NAME", customer.getName().toUpperCase()); form.setField("CUSTOMER_CPF", StringUtil.formatCPF(customer.getCpf())); form.setField("CUSTOMER_RG", customer.getRg().toUpperCase()); // Addres data Address address = customer.getAddresses().get(0); StringBuilder addressDescription = new StringBuilder(); addressDescription.append(address.getStreet()); addressDescription.append(", " + address.getNumber()); if (address.getComplement() != null) { addressDescription.append(", " + address.getComplement()); } form.setField("CUSTOMER_ADDRESS", addressDescription.toString().toUpperCase()); form.setField("CUSTOMER_DISTRICT", address.getDistrict().toUpperCase()); form.setField("CUSTOMER_CEP", address.getCep()); form.setField("CUSTOMER_CITY", address.getCity().toUpperCase()); form.setField("CUSTOMER_STATE", address.getState().toUpperCase()); List<Phone> phones = customer.getPhones(); for (Phone phone : phones) { String phoneNumber = StringUtil.formatPhone(Long.valueOf(phone.getPrefix() + "" + phone.getNumber())); switch (phone.getType()) { case "Celular": form.setField("CUSTOMER_CELLPHONE", phoneNumber); break; case "Residencial": form.setField("CUSTOMER_PHONE", phoneNumber); break; case "Comercial": form.setField("CUSTOMER_COMPHONE", phoneNumber); break; default: break; } } // Car data Car car = getCar(); form.setField("CAR_MANUFACTURER", car.getModel().getManufacturer().getName().toUpperCase()); form.setField("CAR_MODEL", car.getModel().getName().toUpperCase()); form.setField("CAR_YEAR", car.getYearOfManufacture() + "/" + car.getYearOfModel()); form.setField("CAR_COLOR", car.getColor().toUpperCase()); form.setField("CAR_PLATE", car.getLicensePlate().toUpperCase()); form.setField("CAR_CHASSI", car.getChassi().toUpperCase()); form.setField("CAR_RENAVAM", car.getRenavam().toUpperCase()); // Transaction data form.setField("CAR_DEPOSIT", formatter.format(getDeposit()) + " (" + StringUtil.formatCurrency(getDeposit()) + ")"); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.LONG, brazilLocale); form.setField("CAR_VALUE", formatter.format(getPrice()) + " (" + StringUtil.formatCurrency(getPrice()) + ")"); form.setField("DATE", dateFormatter.format(new Date())); DateFormat deliveryDateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, brazilLocale); DateFormat deliveryTimeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT, brazilLocale); if (getDeliveryDate() != null) { form.setField("DELIVERY_DATE", deliveryDateFormatter.format(getDeliveryDate()) + " " + deliveryTimeFormatter.format(getDeliveryDate())); } if (getKm() != null) { form.setField("DELIVERY_KM", getKm().toString()); } }
From source file:com.sun.faces.demotest.cardemo.TestCarDemo.java
/** * <p>Load the main page. Assumptions: there are exactly four * buttons, in a certain order, to select each locale. For each * button, press it, and call doStoreFront() on the result.</p> *///from w w w. j av a2 s . co m public void testCarDemo() throws Exception { // for each of the language links run the test HtmlPage page = (HtmlPage) getInitialPage(); List buttons = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class); HtmlSubmitInput button = null; int i, j = 0; Locale[] locales = { Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH, new Locale("es", "") }; for (i = 0; i < locales.length; i++) { resources = ResourceBundle.getBundle("carstore.bundles.Resources", locales[i]); carBundles = new ResourceBundle[carBundleNames.length]; for (j = 0; j < carBundleNames.length; j++) { carBundles[j] = ResourceBundle.getBundle(carBundleNames[j], locales[i]); } button = (HtmlSubmitInput) buttons.get(i); if (log.isTraceEnabled()) { log.trace("Running test for language: " + button.asText()); } doStoreFront((HtmlPage) button.click()); } }
From source file:ejportal.webapp.filter.LocaleFilter.java
/** * This method looks for a "locale" request parameter. If it finds one, it * sets it as the preferred locale and also configures it to work with JSTL. * /* www .j a v a 2 s.c om*/ * @param request * the current request * @param response * the current response * @param chain * the chain * @throws IOException * when something goes wrong * @throws ServletException * when a communication failure happens */ @Override @SuppressWarnings("unchecked") public void doFilterInternal(HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { final String locale = request.getParameter("locale"); Locale preferredLocale = null; if (locale != null) { final int indexOfUnderscore = locale.indexOf('_'); if (indexOfUnderscore != -1) { final String language = locale.substring(0, indexOfUnderscore); final String country = locale.substring(indexOfUnderscore + 1); preferredLocale = new Locale(language, country); } else { preferredLocale = new Locale(locale); } } final HttpSession session = request.getSession(false); if (session != null) { if (preferredLocale == null) { preferredLocale = (Locale) session.getAttribute(Constants.PREFERRED_LOCALE_KEY); } else { session.setAttribute(Constants.PREFERRED_LOCALE_KEY, preferredLocale); Config.set(session, Config.FMT_LOCALE, preferredLocale); } if ((preferredLocale != null) && !(request instanceof LocaleRequestWrapper)) { request = new LocaleRequestWrapper(request, preferredLocale); LocaleContextHolder.setLocale(preferredLocale); } } final String theme = request.getParameter("theme"); // if (theme != null && request.isUserInRole(Constants.ADMIN_ROLE)) { // TOD hartkodiert if ((theme != null) && request.isUserInRole("ROLE_SYSTEMADMIN")) { final Map<String, Object> config = (Map) this.getServletContext().getAttribute(Constants.CONFIG); config.put(Constants.CSS_THEME, theme); } chain.doFilter(request, response); // Reset thread-bound LocaleContext. LocaleContextHolder.setLocaleContext(null); }