List of usage examples for java.util Locale Locale
public Locale(String language, String country)
From source file:com.nexmo.client.verify.endpoints.VerifyEndpointTest.java
@Test public void testConstructVerifyParamsNullBrand() throws Exception { try {// w ww . j a v a 2 s .c o m new VerifyRequest("4477990090090", null, "Your friend", 4, new Locale("en", "GB"), VerifyClient.LineType.MOBILE); fail("A null 'brand' argument should throw IllegalArgumentException"); } catch (IllegalArgumentException e) { // this is expected } }
From source file:com.openkm.applet.Util.java
/** * // w w w . j a v a2 s .c om */ public static Locale parseLocaleString(String localeString) { if (localeString == null) { localeString = "en-GB"; } String[] parts = localeString.split("-"); String language = (parts.length > 0 ? parts[0] : ""); String country = (parts.length > 1 ? parts[1] : ""); return (language.length() > 0 ? new Locale(language, country) : null); }
From source file:com.plexus.crtvgHorarios.view.managedBeans.LoginBean.java
public void executeLogin(ActionEvent e) throws ServletException, IOException { /*/* w ww. j a v a 2s . co m*/ * El siguiente cdigo es necesario para que el filtro de Spring-Security intercepte * la request del login ya que no funciona poner action="\j_spring_security_check" en la request del form * como se hara si fuese una pgina jsp en lugar de una xhtml de facelets. * * La ventaja es que la pgina de login no est condicionada por spring-security */ ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()).getRequestDispatcher( "/j_spring_security_check?j_username=" + username + "&j_password=" + password); dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse()); FacesContext.getCurrentInstance().responseComplete(); // Fija el locale a gl al logearse Locale locale = new Locale("gl", ""); org.omnifaces.util.Faces.setLocale(locale); /** // Aade el item "Men principal" al breadCrumb. BreadCrumbBean breadCrumBean = FacesUtils.getManagedBean("breadCrumbBean", BreadCrumbBean.class); MenuItem item = new MenuItem(); //MethodExpression methodExpression = FacesUtils.createMethodExpression("#{breadCrumbBean.goMenuPrincipal}"+"?faces-redirect=true", null, new Class<?>[0]); item.setId("menuPrincipalMenuItem"); item.setValue("Men principal"); item.setUrl("/pages/menuPrincipal.xhtml"); //item.setActionExpression(methodExpression); breadCrumBean.addItem(item); **/ // FIXME: Tras logearse se est perdiendo el locale si est est definido como gl }
From source file:com.edgenius.core.webapp.filter.LocaleFilter.java
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { // if(log.isDebugEnabled()){ // log.debug("Request URL: " + request.getRequestURI()); // }//w ww . j av a 2 s.c om //charset encoding if (!StringUtils.isEmpty(this.encoding)) request.setCharacterEncoding(encoding); else request.setCharacterEncoding(Constants.UTF8); String direction = null; Locale preferredLocale = null; TimeZone timezone = null; HttpSession session = request.getSession(false); if (getUserService() != null) { //for Install mode, it will return null User user = getUserService().getUserByName(request.getRemoteUser()); if (user != null && !user.isAnonymous()) { //locale UserSetting set = user.getSetting(); String userLang = set.getLocaleLanguage(); String userCountry = set.getLocaleCountry(); if (userLang != null && userCountry != null) { preferredLocale = new Locale(userLang, userCountry); } //text direction in HTML direction = set.getDirection(); //timezone if (set.getTimeZone() != null) timezone = TimeZone.getTimeZone(set.getTimeZone()); } } if (preferredLocale == null) { if (Global.DetectLocaleFromRequest) { Locale locale = request.getLocale(); if (locale != null) { preferredLocale = locale; } } if (preferredLocale == null) { preferredLocale = Global.getDefaultLocale(); } } if (direction == null) { direction = Global.DefaultDirection; } if (timezone == null) { if (session != null) { //try to get timezone from HttpSession, which will be intial set in SecurityControllerImpl.checkLogin() method timezone = (TimeZone) session.getAttribute(Constants.TIMEZONE); } if (timezone == null) timezone = TimeZone.getTimeZone(Global.DefaultTimeZone); } //set locale for STURTS and JSTL // set the time zone - must be set for dates to display the time zone if (session != null) { Config.set(session, Config.FMT_LOCALE, preferredLocale); session.setAttribute(Constants.DIRECTION, direction); Config.set(session, Config.FMT_TIME_ZONE, timezone); } //replace request by LocaleRequestWrapper if (!(request instanceof LocaleRequestWrapper)) { request = new LocaleRequestWrapper(request, preferredLocale); LocaleContextConfHolder.setLocale(preferredLocale); } if (chain != null) { request.setAttribute(PREFERRED_LOCALE, preferredLocale.toString()); chain.doFilter(request, response); } // Reset thread-bound LocaleContext. LocaleContextConfHolder.setLocaleContext(null); }
From source file:com.bloatit.framework.webprocessor.context.Session.java
/** * Restore session/*from w ww.ja v a 2 s . com*/ * * @param key * @param ipAddress * @param country * @param language */ protected Session(final String key, final String shortKey, final String ipAddress, final Integer memberId, String language, String country) { this.key = key; this.shortKey = shortKey; this.ipAddress = ipAddress; this.memberId = memberId; this.memberLocale = new Locale(language, country); resetExpirationTime(); }
From source file:de.cosmocode.commons.converter.LocaleCountryIsoConverter.java
@Override public Locale decode(String input) { return new Locale("", toAlpha2(input)); }
From source file:com.opensymphony.xwork2.conversion.impl.StringConverterTest.java
public void testBigDecimalToStringConversionPL() throws Exception { // given// w w w .ja v a 2s .com StringConverter converter = new StringConverter(); 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, new BigDecimal(aBitBiggerThanDouble), null); // then does not lose integer and fraction digits assertEquals(aBitBiggerThanDouble.substring(0, 309) + "," + aBitBiggerThanDouble.substring(310), value); }
From source file:de.uniwue.info6.webapp.admin.SubmissionRow.java
public String getEntryDate() { if (userEntry != null) { DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL, new Locale("de", "DE")); return df.format(userEntry.getEntryTime()); }//from ww w. j a va 2 s . c o m return "---"; }
From source file:net.rrm.ehour.config.EhourConfigJdbc.java
@Override public Locale getLanguageLocale() { String formattingLocale = this.getString(LOCALE_LANGUAGE.getDbField(), "en_US"); if (!formattingLocale.contains("-")) { return new Locale(formattingLocale, formattingLocale); } else {/* ww w.j a v a 2 s.c o m*/ return LocaleUtil.forLanguageTag(formattingLocale); } }
From source file:carstore.CarStore.java
public CarStore() { if (log.isDebugEnabled()) { log.debug("Creating main CarStore bean"); log.debug("Populating locale map"); }/*from ww w . j av a2s . c o m*/ locales = new HashMap(); locales.put("NAmerica", Locale.ENGLISH); locales.put("SAmerica", new Locale("es", "es")); locales.put("Germany", Locale.GERMAN); locales.put("France", Locale.FRENCH); }