List of usage examples for java.util Locale Locale
public Locale(String language, String country)
From source file:com.smilonet.common.zk.GeneralLabelLocator.java
public URL locate(Locale locale) throws Exception { // String menu_res_filename = // (locale.getLanguage().equals(Locale.ITALIAN.getLanguage())) ? // MENU_FILE_NAME + MENU_FILE_SUFFIX // : MENU_FILE_NAME + "_" + locale.getLanguage() + MENU_FILE_SUFFIX; String menu_res_filename = ""; if (StringUtils.isEmpty(context)) { // Locale.setDefault(new Locale("en", "EN")); context = "en_EN"; }// w w w . j ava 2 s . c om if (context.equals("en_EN")) { // default property-file without locale Sessions.getCurrent().setAttribute("px_preferred_locale", new Locale("en", "EN")); menu_res_filename = MENU_FILE_NAME + MENU_FILE_SUFFIX; } else if (context.equals("de_DE")) { Sessions.getCurrent().setAttribute("px_preferred_locale", new Locale("de", "DE")); menu_res_filename = MENU_FILE_NAME + "_" + "de_DE" + MENU_FILE_SUFFIX; } // String menu_res_filename = MENU_FILE_NAME + "_" + context + // MENU_FILE_SUFFIX; // real path String menu_res_path = Sessions.getCurrent().getWebApp().getRealPath("/WEB-INF/" + menu_res_filename); // check if the file exists File fmr = new File(menu_res_path); if (!fmr.exists()) throw new Exception("..........."); // return url return fmr.toURL(); }
From source file:com.graph.pie.PieGraphData.java
public PieGraphData(String startDate, String endDate) { java.sql.Connection con = null; java.sql.PreparedStatement stmt = null; java.sql.ResultSet rs = null; try {/*from w w w .jav a2 s . c om*/ con = ControlPanelPool.getInstance().getConnection(); stmt = con.prepareStatement( "SELECT DISTINCT TOP 15 LeadOrganization.Country, COUNT(LeadOrganization.Country) as c FROM LeadOrganization, LeadRemoteAddress, leadSession WHERE leadSession.remoteAddress = LeadRemoteAddress.ip AND LeadRemoteAddress.LeadOrganization_uid = LeadOrganization.Id AND LeadRemoteAddress.prefered = 1 AND LeadOrganization.Country != '' AND leadSession.timeIn > CONVERT(date, ?) AND leadSession.timeIn < CONVERT(date, ?) GROUP BY LeadOrganization.Country HAVING COUNT(LeadOrganization.Country) > 0 ORDER BY c DESC"); stmt.setString(1, startDate); stmt.setString(2, endDate); rs = stmt.executeQuery(); languages = new HashMap<>(); while (rs.next()) { /* if (rs.getString("userAgent") != null) { String lang = new UserAgentDetector().parseUserAgent(rs.getString("userAgent")).getLocale().country.getLabel(); if (languages.containsKey(lang)) { languages.put(lang, languages.get(lang) + 1); } else { languages.put(lang, 1); } } */ Locale l = new Locale("", rs.getString("Country")); languages.put(l.getDisplayCountry(), rs.getInt("c")); } //languages.remove("Unknown"); con.close(); } catch (IOException | SQLException | PropertyVetoException ex) { Logger.getLogger(PieGraphData.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(con, stmt, rs); } }
From source file:com.wisemapping.filter.UserLocaleInterceptor.java
public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, Object object) throws Exception { final HttpSession session = request.getSession(false); User user = Utils.getUser(false);/* www . j a v a 2s . c o m*/ if (user != null && session != null) { String userLocale = user.getLocale(); final Locale sessionLocale = (Locale) session .getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME); if ((userLocale != null) && ((sessionLocale == null) || (!userLocale.equals(sessionLocale.toString())))) { Locale locale; if (userLocale.contains("_")) { final String[] spit = userLocale.split("_"); locale = new Locale(spit[0], spit[1]); } else { locale = new Locale(userLocale); } session.setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, locale); } } return true; }
From source file:com.nexmo.client.verify.endpoints.VerifyEndpointTest.java
@Test public void testConstructVerifyParams() throws Exception { VerifyRequest verifyRequest = new VerifyRequest("4477990090090", "Brand.com", "Your friend", 4, new Locale("en", "GB"), com.nexmo.client.verify.VerifyClient.LineType.MOBILE); VerifyEndpoint endpoint = new VerifyEndpoint(null); RequestBuilder request = endpoint.makeRequest(verifyRequest); List<NameValuePair> params = request.getParameters(); assertContainsParam(params, "number", "4477990090090"); assertContainsParam(params, "brand", "Brand.com"); assertContainsParam(params, "sender_id", "Your friend"); assertContainsParam(params, "code_length", "4"); assertContainsParam(params, "lg", "en-gb"); assertContainsParam(params, "require_type", "MOBILE"); }
From source file:fr.cph.stock.android.entity.EntityBuilder.java
private void buildUser() throws JSONException { user = new User(); JSONObject jsonUser = json.getJSONObject("user"); String userIdStr = jsonUser.getString("id"); user.setUserId(userIdStr);//from w w w . ja v a 2 s .com String localeStr = jsonUser.getString("locale"); String language = localeStr.split("_")[0]; String country = localeStr.split("_")[1]; Locale locale = new Locale(language, country); user.setLocale(locale); formatCurrencyZero = NumberFormat.getCurrencyInstance(user.getLocale()); formatCurrencyZero.setMaximumFractionDigits(0); formatCurrencyZero.setMinimumFractionDigits(0); formatCurrencyZero.setRoundingMode(RoundingMode.HALF_DOWN); formatCurrencyOne = NumberFormat.getCurrencyInstance(user.getLocale()); formatCurrencyOne.setMaximumFractionDigits(1); formatCurrencyOne.setMinimumFractionDigits(0); formatCurrencyOne.setRoundingMode(RoundingMode.HALF_DOWN); formatCurrencyTwo = NumberFormat.getCurrencyInstance(user.getLocale()); formatCurrencyTwo.setMaximumFractionDigits(2); formatCurrencyTwo.setMinimumFractionDigits(0); formatCurrencyTwo.setRoundingMode(RoundingMode.HALF_DOWN); formatLocaleZero = NumberFormat.getInstance(user.getLocale()); formatLocaleZero.setMaximumFractionDigits(0); formatLocaleZero.setMinimumFractionDigits(0); formatLocaleZero.setRoundingMode(RoundingMode.HALF_DOWN); formatLocaleOne = NumberFormat.getInstance(user.getLocale()); formatLocaleOne.setMaximumFractionDigits(1); formatLocaleOne.setMinimumFractionDigits(0); formatLocaleOne.setRoundingMode(RoundingMode.HALF_DOWN); formatLocaleTwo = NumberFormat.getInstance(user.getLocale()); formatLocaleTwo.setMaximumFractionDigits(2); formatLocaleTwo.setMinimumFractionDigits(0); formatLocaleTwo.setRoundingMode(RoundingMode.HALF_DOWN); String datePattern = jsonUser.getString("datePattern"); user.setDatePattern(datePattern); String datePatternWithoutHourMin = jsonUser.getString("datePatternWithoutHourMin"); user.setDatePatternWithoutHourMin(datePatternWithoutHourMin); JSONObject lastUpdateJSON = jsonUser.getJSONObject("lastUpdate"); user.setLastUpdate(extractDate(lastUpdateJSON, user.getDatePattern())); }
From source file:de.xwic.appkit.core.model.queries.resolver.hbn.HsqlQueryResolver.java
public Object resolve(Class<? extends Object> entityClass, EntityQuery entityQuery, boolean justCount) { Session session = HibernateUtil.currentSession(); HsqlQuery query = (HsqlQuery) entityQuery; PicklistEnhancedQueryString queryStr = new PicklistEnhancedQueryString(entityClass.getName(), query.getHsqlQuery(), query.getUserLanguage(), justCount); if (!justCount) { queryStr.whereBuf.append(addSortingClause(entityQuery, "obj", true, queryStr.queryBuf, entityClass)); }/*w ww . java2s . c o m*/ String theQuery = queryStr.toString(); theQuery = DateUtils.getInstance().addSQLConvert(new Locale(query.getLanguageId(), query.getUserCountry()), theQuery); log.debug(theQuery); return session.createQuery(theQuery); }
From source file:com.respam.comniq.models.ExcelExporter.java
public void createFile() throws IOException, WriteException { String path = System.getProperty("user.home") + File.separator + "comniq" + File.separator + "output"; File file = new File(path + File.separator + "movieInfo.xls"); WorkbookSettings wbSettings = new WorkbookSettings(); wbSettings.setLocale(new Locale("en", "EN")); WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings); workbook.createSheet("Movies", 0); WritableSheet excelSheet = workbook.getSheet(0); createLabel(excelSheet);/*ww w . j av a 2 s. c om*/ workbook.write(); workbook.close(); }
From source file:com.bibisco.manager.LocaleManager.java
public void saveLocale(String pStrLocale) { mLog.debug("Start saveLocale(", pStrLocale, ")"); Validate.notEmpty(pStrLocale, "locale cannot be empty"); String[] lStrLocaleSplit = pStrLocale.split("_"); if (lStrLocaleSplit.length != 2) { throw new IllegalArgumentException("Not a valid locale"); }/*from w w w.ja v a 2 s . c om*/ PropertiesManager.getInstance().updateProperty("locale", pStrLocale); mLocale = new Locale(lStrLocaleSplit[0], lStrLocaleSplit[1]); mLog.debug("End saveLocale(String)"); }
From source file:org.openmrs.contrib.metadatarepository.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 . jav a 2s . c o m*/ * @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 */ @SuppressWarnings("unchecked") public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String locale = request.getParameter("locale"); Locale preferredLocale = null; if (locale != null) { int indexOfUnderscore = locale.indexOf('_'); if (indexOfUnderscore != -1) { String language = locale.substring(0, indexOfUnderscore); String country = locale.substring(indexOfUnderscore + 1); preferredLocale = new Locale(language, country); } else { preferredLocale = new Locale(locale); } } 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); } } String theme = request.getParameter("theme"); if (theme != null && request.isUserInRole(Constants.ADMIN_ROLE)) { Map<String, Object> config = (Map) getServletContext().getAttribute(Constants.CONFIG); config.put(Constants.CSS_THEME, theme); } chain.doFilter(request, response); // Reset thread-bound LocaleContext. LocaleContextHolder.setLocaleContext(null); }
From source file:com.properned.application.ManageLocaleController.java
public void addLocale(ActionEvent event) { String text = localeTextField.getText(); if (StringUtils.isEmpty(text)) { logger.info("Locale text fied is empty, nothing locale added"); // nothing to add return;//from ww w .j a va2 s . c o m } if (text.contains("_")) { // There is a language code and a country code String[] split = text.split("\\_"); Locale locale = new Locale(split[0], split[1]); list.add(locale); logger.info("Added language/coutry locale '" + locale + "'"); } else { // there is only a language code Locale locale = new Locale(text); list.add(locale); logger.info("Added language locale '" + locale + "'"); } }