/** Returns a <code>Locale</code> to be used as a fallback locale for further bundle searches by the <code>createBundle</code> * factory method. This method is called from the factory method every time when no resulting bundle has been found for * <code>baseFileHandler</code> and <code>locale</code>, where locale is either the parameter for <code>createBundle</code> or * the previous fallback locale returned by this method. * * <p> * This method returns the {@linkplain Locale#getDefault() default <code>Locale</code>} if the given <code>locale</code> isn't * the default one. Otherwise, <code>null</code> is returned. * * @param locale the <code>Locale</code> for which <code>createBundle</code> has been unable to find any resource bundles * (except for the base bundle) * @return a <code>Locale</code> for the fallback search, or <code>null</code> if no further fallback search is needed. * @exception NullPointerException if <code>locale</code> is <code>null</code> */ private static Locale getFallbackLocale (Locale locale) { Locale defaultLocale = Locale.getDefault(); return locale.equals(defaultLocale) ? null : defaultLocale; }
/** Returns a <code>Locale</code> to be used as a fallback locale for further bundle searches by the <code>createBundle</code> * factory method. This method is called from the factory method every time when no resulting bundle has been found for * <code>baseFileHandler</code> and <code>locale</code>, where locale is either the parameter for <code>createBundle</code> or * the previous fallback locale returned by this method. * * <p> * This method returns the {@linkplain Locale#getDefault() default <code>Locale</code>} if the given <code>locale</code> isn't * the default one. Otherwise, <code>null</code> is returned. * * @param locale the <code>Locale</code> for which <code>createBundle</code> has been unable to find any resource bundles * (except for the base bundle) * @return a <code>Locale</code> for the fallback search, or <code>null</code> if no further fallback search is needed. * @exception NullPointerException if <code>locale</code> is <code>null</code> */ private static Locale getFallbackLocale (Locale locale) { Locale defaultLocale = Locale.getDefault(); return locale.equals(defaultLocale) ? null : defaultLocale; }
/** * <p>Compare another object for equality with this object.</p> * * @param obj the object to compare to * @return <code>true</code>if equal to this instance */ @Override public boolean equals(final Object obj) { if (!(obj instanceof FastDateParser)) { return false; } final FastDateParser other = (FastDateParser) obj; return pattern.equals(other.pattern) && timeZone.equals(other.timeZone) && locale.equals(other.locale); }
/** * <p>Compares two objects for equality.</p> * * @param obj the object to compare to * @return {@code true} if equal */ @Override public boolean equals(final Object obj) { if (!(obj instanceof FastDatePrinter)) { return false; } final FastDatePrinter other = (FastDatePrinter) obj; return mPattern.equals(other.mPattern) && mTimeZone.equals(other.mTimeZone) && mLocale.equals(other.mLocale); }
@Override public boolean equals(Object obj) { return obj instanceof LangLocale && locale.equals(((LangLocale) obj).get()); }
/** * "Mutant factory" method that will return an instance that uses specified * {@code Locale}: * either {@code this} instance (if setting would not change), or newly * constructed instance with different {@code Locale} to use. */ public StdDateFormat withLocale(Locale loc) { if (loc.equals(_locale)) { return this; } return new StdDateFormat(_timezone, loc, _lenient, _tzSerializedWithColon); }
public JacksonJodaPeriodFormat withLocale(Locale locale) { if ((locale == null) || (_locale != null && _locale.equals(locale))) { return this; } return new JacksonJodaPeriodFormat(this, locale); }
public JacksonJodaDateFormat withLocale(Locale locale) { if ((locale == null) || (_locale != null && _locale.equals(locale))) { return this; } return new JacksonJodaDateFormat(this, locale); }
/** * "Mutant factory" method that will return an instance that uses specified * {@code Locale}: * either {@code this} instance (if setting would not change), or newly * constructed instance with different {@code Locale} to use. */ public StdDateFormat withLocale(Locale loc) { if (loc.equals(_locale)) { return this; } return new StdDateFormat(_timezone, loc, _lenient, _tzSerializedWithColon); }
@Override public Date parse(final String source) throws ParseException { final ParsePosition pp = new ParsePosition(0); final Date date= parse(source, pp); if (date == null) { // Add a note re supported date range if (locale.equals(JAPANESE_IMPERIAL)) { throw new ParseException( "(The " +locale + " locale does not support dates before 1868 AD)\n" + "Unparseable date: \""+source, pp.getErrorIndex()); } throw new ParseException("Unparseable date: "+source, pp.getErrorIndex()); } return date; }
private static I18NBundle loadBundleChain (FileHandle baseFileHandle, String encoding, List<Locale> candidateLocales, int candidateIndex, I18NBundle baseBundle) { Locale targetLocale = candidateLocales.get(candidateIndex); I18NBundle parent = null; if (candidateIndex != candidateLocales.size() - 1) { // Load recursively the parent having the next candidate locale parent = loadBundleChain(baseFileHandle, encoding, candidateLocales, candidateIndex + 1, baseBundle); } else if (baseBundle != null && targetLocale.equals(ROOT_LOCALE)) { return baseBundle; } // Load the bundle I18NBundle bundle = loadBundle(baseFileHandle, encoding, targetLocale); if (bundle != null) { bundle.parent = parent; return bundle; } return parent; }
private static I18NBundle loadBundleChain (FileHandle baseFileHandle, String encoding, List<Locale> candidateLocales, int candidateIndex, I18NBundle baseBundle) { Locale targetLocale = candidateLocales.get(candidateIndex); I18NBundle parent = null; if (candidateIndex != candidateLocales.size() - 1) { // Load recursively the parent having the next candidate locale parent = loadBundleChain(baseFileHandle, encoding, candidateLocales, candidateIndex + 1, baseBundle); } else if (baseBundle != null && targetLocale.equals(ROOT_LOCALE)) { return baseBundle; } // Load the bundle I18NBundle bundle = loadBundle(baseFileHandle, encoding, targetLocale); if (bundle != null) { bundle.parent = parent; return bundle; } return parent; }
public PeriodFormatter createFormatter(SerializerProvider provider) { PeriodFormatter formatter = _formatter; if (!_explicitLocale) { Locale loc = provider.getLocale(); if (loc != null && !loc.equals(_locale)) { formatter = formatter.withLocale(loc); } } return formatter; }
public DateTimeFormatter createFormatterWithLocale(SerializerProvider ctxt) { DateTimeFormatter formatter = _formatter; if (!_explicitLocale) { Locale loc = ctxt.getLocale(); if (loc != null && !loc.equals(_locale)) { formatter = formatter.withLocale(loc); } } return formatter; }
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!(RequestContextUtils.findWebApplicationContext(request) instanceof SimpleWebApplicationContext)) { throw new ServletException("Incorrect WebApplicationContext"); } if (!(RequestContextUtils.getLocaleResolver(request) instanceof AcceptHeaderLocaleResolver)) { throw new ServletException("Incorrect LocaleResolver"); } if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) { throw new ServletException("Incorrect Locale"); } return null; }
private PeriodPrinter getPrinter(Locale locale) { if (locale != null && !locale.equals(iFormatter.getLocale())) { return wordBased(locale).getPrinter(); } return iFormatter.getPrinter(); }
private PeriodParser getParser(Locale locale) { if (locale != null && !locale.equals(iFormatter.getLocale())) { return wordBased(locale).getParser(); } return iFormatter.getParser(); } }
private PeriodPrinter getPrinter(Locale locale) { if (locale != null && !locale.equals(iFormatter.getLocale())) { return wordBased(locale).getPrinter(); } return iFormatter.getPrinter(); }
private PeriodParser getParser(Locale locale) { if (locale != null && !locale.equals(iFormatter.getLocale())) { return wordBased(locale).getParser(); } return iFormatter.getParser(); } }
@Test public void defaultLocale() { Locale originalDefaultLocale = Locale.getDefault(); try { Locale newDefaultLocale = originalDefaultLocale.equals(Locale.GERMANY) ? Locale.FRANCE : Locale.GERMANY; Locale.setDefault(newDefaultLocale); // Create the request after changing the default locale. MockHttpServletRequest request = new MockHttpServletRequest(); assertFalse(newDefaultLocale.equals(request.getLocale())); assertEquals(Locale.ENGLISH, request.getLocale()); } finally { Locale.setDefault(originalDefaultLocale); } }