Java Code Examples for java.util.Locale#getDefault()

The following examples show how to use java.util.Locale#getDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemoryConstraintTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadingLastPage() throws LoginException {
    AuthenticationManager lw = AppBeans.get(AuthenticationManager.NAME);
    Credentials credentials = new LoginPasswordCredentials("constraintUser3", PASSWORD, Locale.getDefault());
    UserSession userSession = lw.login(credentials).getSession();
    assertNotNull(userSession);

    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        DataManager dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        LoadContext loadContext = new LoadContext(User.class).setView(View.LOCAL);
        loadContext.setQuery(new LoadContext.Query("select u from sec$User u where (u.login like 'user%' or u.login like 'constraintUser%') order by u.login desc"));
        loadContext.getQuery().setMaxResults(30);
        loadContext.getQuery().setFirstResult(30);
        List<User> resultList = dataManager.loadList(loadContext);
        assertEquals(8, resultList.size());
        assertEquals("user133",resultList.get(0).getLogin());
        assertEquals("user132",resultList.get(1).getLogin());
        assertEquals("user131",resultList.get(2).getLogin());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
 
Example 2
Source File: InMemoryConstraintTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstraintByAttributeNotInView() throws LoginException {
    AuthenticationManager lw = AppBeans.get(AuthenticationManager.NAME);
    Credentials credentials = new LoginPasswordCredentials("constraintUser4", PASSWORD, Locale.getDefault());
    UserSession userSession = lw.login(credentials).getSession();
    assertNotNull(userSession);

    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        DataManager dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        LoadContext loadContext = new LoadContext(User.class).setView(View.MINIMAL);
        loadContext.setQuery(new LoadContext.Query("select u from sec$User u where u.login = 'constraintUser4' order by u.login desc"));
        loadContext.getQuery().setMaxResults(30);
        loadContext.getQuery().setFirstResult(0);
        List<User> resultList = dataManager.loadList(loadContext);
        assertEquals(1, resultList.size());
        assertEquals("constraintUser4",resultList.get(0).getLogin());

    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
 
Example 3
Source File: MainPagerAdapter.java    From onpc with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CharSequence getPageTitle(int position)
{
    Locale l = Locale.getDefault();
    switch (position)
    {
    case 0:
        return context.getString(R.string.title_monitor).toUpperCase(l);
    case 1:
        return context.getString(R.string.title_media).toUpperCase(l);
    case 2:
        return context.getString(R.string.title_device).toUpperCase(l);
    case 3:
        return context.getString(R.string.title_remote_control).toUpperCase(l);
    case 4:
        return context.getString(R.string.title_remote_interface).toUpperCase(l);
    }
    return null;
}
 
Example 4
Source File: TransactionDetailsActivity.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void setDateAndTime() {
    Date date = new Date(transaction.getTime() * 1000);
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
    etDate.setText(dateFormat.format(date));
    etTime.setText(timeFormat.format(date));
}
 
Example 5
Source File: Time_9_DateTimeZone_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets the short name of this datetime zone suitable for display using
 * the specified locale.
 * <p>
 * If the name is not available for the locale, then this method returns a
 * string in the format <code>[+-]hh:mm</code>.
 * 
 * @param instant  milliseconds from 1970-01-01T00:00:00Z to get the name for
 * @param locale  the locale to get the name for
 * @return the human-readable short name in the specified locale
 */
public String getShortName(long instant, Locale locale) {
    if (locale == null) {
        locale = Locale.getDefault();
    }
    String nameKey = getNameKey(instant);
    if (nameKey == null) {
        return iID;
    }
    String name = cNameProvider.getShortName(locale, iID, nameKey);
    if (name != null) {
        return name;
    }
    return printOffset(getOffset(instant));
}
 
Example 6
Source File: StringComparator.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
private Collator getDefaultCollator()
{
  if (defaultCollator == null) {
    Locale locale = ConfigXml.getInstance().getDefaultLocale();
    if (locale == null) {
      locale = Locale.getDefault();
    }
    defaultCollator = Collator.getInstance(locale);
  }
  return defaultCollator;
}
 
Example 7
Source File: TimeZoneTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @add test {@link java.util.TimeZone#getDisplayName(boolean, int)}
 */
public void test_getDisplayName_ZI() {
    TimeZone defaultZone = TimeZone.getDefault();
    Locale defaultLocale = Locale.getDefault();
    String actualName = defaultZone.getDisplayName(false, TimeZone.LONG);
    String expectedName = defaultZone.getDisplayName(false, TimeZone.LONG,
            defaultLocale);
    assertEquals(
            "getDisplayName(daylight,style) did not return the default locale suitable name",
            expectedName, actualName);
}
 
Example 8
Source File: VendorUtils.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
static String clean(String macAddress) {
    if (macAddress == null) {
        return StringUtils.EMPTY;
    }
    String result = macAddress.replace(SEPARATOR, "");
    Locale locale = Locale.getDefault();
    return result.substring(0, Math.min(result.length(), MAX_SIZE)).toUpperCase(locale);
}
 
Example 9
Source File: SystemUtils.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static String getSystemInfo() {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
    String time = dateFormat.format(date);
    StringBuilder sb = new StringBuilder();
    sb.append("_______  systemInfo  ").append(time).append(" ______________");
    sb.append("\nID                 :").append(Build.ID);
    sb.append("\nBRAND              :").append(Build.BRAND);
    sb.append("\nMODEL              :").append(Build.MODEL);
    sb.append("\nRELEASE            :").append(Build.VERSION.RELEASE);
    sb.append("\nSDK                :").append(Build.VERSION.SDK);

    sb.append("\n_______ OTHER _______");
    sb.append("\nBOARD              :").append(Build.BOARD);
    sb.append("\nPRODUCT            :").append(Build.PRODUCT);
    sb.append("\nDEVICE             :").append(Build.DEVICE);
    sb.append("\nFINGERPRINT        :").append(Build.FINGERPRINT);
    sb.append("\nHOST               :").append(Build.HOST);
    sb.append("\nTAGS               :").append(Build.TAGS);
    sb.append("\nTYPE               :").append(Build.TYPE);
    sb.append("\nTIME               :").append(Build.TIME);
    sb.append("\nINCREMENTAL        :").append(Build.VERSION.INCREMENTAL);

    sb.append("\n_______ CUPCAKE-3 _______");
    sb.append("\nDISPLAY            :").append(Build.DISPLAY);

    sb.append("\n_______ DONUT-4 _______");
    sb.append("\nSDK_INT            :").append(Build.VERSION.SDK_INT);
    sb.append("\nMANUFACTURER       :").append(Build.MANUFACTURER);
    sb.append("\nBOOTLOADER         :").append(Build.BOOTLOADER);
    sb.append("\nCPU_ABI            :").append(Build.CPU_ABI);
    sb.append("\nCPU_ABI2           :").append(Build.CPU_ABI2);
    sb.append("\nHARDWARE           :").append(Build.HARDWARE);
    sb.append("\nUNKNOWN            :").append(Build.UNKNOWN);
    sb.append("\nCODENAME           :").append(Build.VERSION.CODENAME);

    sb.append("\n_______ GINGERBREAD-9 _______");
    sb.append("\nSERIAL             :").append(Build.SERIAL);
    return sb.toString();
}
 
Example 10
Source File: I18nProviderTest.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void nestedMessageTagTest() {
	Locale systemLocale = Locale.getDefault();
	try {
		Locale.setDefault(Locale.ENGLISH);
		
		MessageTag validationTime = MessageTag.VT_VALIDATION_TIME;
		MessageTag messageTag = MessageTag.CERT_QUALIFICATION_AT_TIME.setArgs(validationTime);
	
		final I18nProvider i18nProvider = new I18nProvider(Locale.ENGLISH);
		String message = i18nProvider.getMessage(messageTag);
		assertNotNull(message);
		assertEquals("Certificate Qualification at validation time", message);
		
		final I18nProvider i18nFrenchProvider = new I18nProvider(Locale.FRENCH);
		message = i18nFrenchProvider.getMessage(messageTag);
		assertNotNull(message);
		assertEquals("Qualification du certificat au moment de la validation", message);

		final I18nProvider i18nGermanProvider = new I18nProvider(Locale.GERMAN);
		message = i18nGermanProvider.getMessage(messageTag);
		assertNotNull(message);
		assertEquals("Certificate Qualification at validation time", message);
	} finally {
		Locale.setDefault(systemLocale); // restore default
	}
}
 
Example 11
Source File: Arja_0071_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * <p>Gets a date/time formatter instance using the specified style,
 * time zone and locale.</p>
 * 
 * @param dateStyle  date style: FULL, LONG, MEDIUM, or SHORT
 * @param timeStyle  time style: FULL, LONG, MEDIUM, or SHORT
 * @param timeZone  optional time zone, overrides time zone of
 *  formatted date
 * @param locale  optional locale, overrides system locale
 * @return a localized standard date/time formatter
 * @throws IllegalArgumentException if the Locale has no date/time
 *  pattern defined
 */
public static synchronized FastDateFormat getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone,
        Locale locale) {

    Object key = new Pair(new Integer(dateStyle), new Integer(timeStyle));
    if (timeZone != null) {
        key = new Pair(key, timeZone);
    }
    if (locale != null) {
        key = new Pair(key, locale);
    }

    FastDateFormat format = (FastDateFormat) cDateTimeInstanceCache.get(key);
    if (format == null) {
        if (locale == null) {
            locale = Locale.getDefault();
        }
        try {
            SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance(dateStyle, timeStyle,
                    locale);
            String pattern = formatter.toPattern();
            format = getInstance(pattern, timeZone, locale);
            if (pattern == null) {
            	  throw new IllegalArgumentException("The pattern must not be null");
            	}

        } catch (ClassCastException ex) {
            throw new IllegalArgumentException("No date time pattern for locale: " + locale);
        }
    }
    return format;
}
 
Example 12
Source File: I18nLocaleResolver.java    From Milkomeda with MIT License 5 votes vote down vote up
@Override
public Locale resolveLocale(HttpServletRequest request) {
    // 是否有固定的设置
    Locale defaultLocale = getDefaultLocale();
    if (defaultLocale != null) {
        return defaultLocale;
    }

    // 设置本地语言
    return Locale.getDefault();
}
 
Example 13
Source File: elixir1_one_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * <p>Gets a date formatter instance using the specified style, time
 * zone and locale.</p>
 * 
 * @param style  date style: FULL, LONG, MEDIUM, or SHORT
 * @param timeZone  optional time zone, overrides time zone of
 *  formatted date
 * @param locale  optional locale, overrides system locale
 * @return a localized standard date formatter
 * @throws IllegalArgumentException if the Locale has no date
 *  pattern defined
 */
public static synchronized FastDateFormat getDateInstance(int style, TimeZone timeZone, Locale locale) {
    Object key = Integer.valueOf(style);
    if (timeZone != null) {
        key = new Pair(key, timeZone);
    }

    if (locale == null) {
        locale = Locale.getDefault();
    }

    key = new Pair(key, locale);

    FastDateFormat format = cDateInstanceCache.get(key);
    if (format == null) {
        try {
            SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateInstance(style, locale);
            String pattern = formatter.toPattern();
            format = getInstance(pattern, timeZone, locale);
            cDateInstanceCache.put(key, format);
            
        } catch (ClassCastException ex) {
            throw new IllegalArgumentException("No date pattern for locale: " + locale);
        }
    }
    return format;
}
 
Example 14
Source File: TestDateTime_Properties.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    zone = DateTimeZone.getDefault();
    locale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    Locale.setDefault(Locale.UK);
}
 
Example 15
Source File: SettingsMessages.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates a new instance.
 */
private SettingsMessages() {
  super( Locale.getDefault(), "org.pentaho.reporting.designer.core.settings.messages.messages",//NON-NLS
    ObjectUtilities.getClassLoader( SettingsMessages.class ) );
}
 
Example 16
Source File: CalendarPane.java    From microba with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Constructor.
 */
public CalendarPane() {
	this(null, 0, Locale.getDefault(), TimeZone.getDefault());
}
 
Example 17
Source File: TestPeriodFormat.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
protected void setUp() throws Exception {
    originalLocale = Locale.getDefault();
    Locale.setDefault(DE);
}
 
Example 18
Source File: DefaultLocaleSettings.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Locale getLocale() {
  return Locale.getDefault();
}
 
Example 19
Source File: BasicTimelineFilter.java    From twitter-kit-android with Apache License 2.0 4 votes vote down vote up
public BasicTimelineFilter(FilterValues filterValues) {
    this(filterValues, Locale.getDefault());
}
 
Example 20
Source File: TextRecord.java    From effective_android_sample with Apache License 2.0 4 votes vote down vote up
public TextRecord(String text) {
	this(text, UTF8, Locale.getDefault());
}