public Map<String, Object> asMap() { try { XContentBuilder builder = jsonBuilder() .startObject() .field("rivername", name) .field("settings", settings) .field("locale", LocaleUtil.fromLocale(locale)) .field("job", job) .field("sql", sql) .field("autocommit", autocommit) .field("fetchsize", fetchSize) .field("maxrows", maxRows) .field("retries", retries) .field("maxretrywait", maxretrywait) .field("resultsetconcurrency", resultSetConcurrency) .field("resultsettype", resultSetType) .field("rounding", rounding) .field("scale", scale) .field("columnCreatedAt", columnCreatedAt) .field("columnUpdatedAt", columnUpdatedAt) .field("columnDeletedAt", columnDeletedAt) .field("columnEscape", columnEscape) .field("ignoreNull", ignoreNull) .field("allowConcurrency", allowConcurrency) .endObject(); return XContentHelper.convertToMap(builder.bytes(), true).v2(); } catch (IOException e) { // should really not happen return new HashMap<String, Object>(); } }
@Test public void should_serialize_valid_locale() { Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { String languageTag = LocaleUtil.toLanguageTag(locale); assertEquals( locale.getLanguage() + (StringUtils.isNotBlank(locale.getCountry()) ? ("-" + locale.getCountry()) : ""), languageTag); } }
public static String convertStreamToString(final InputStream is, final String language) throws IOException { final String encodingForLanguage = LocaleUtil.getEncodingForLanguage(language); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final byte[] buffer = new byte[1024]; int bufferUsed; while ((bufferUsed = is.read(buffer)) > 0) { bout.write(buffer, 0, bufferUsed); } final byte[] byteArray = bout.toByteArray(); final String string = new String(byteArray, encodingForLanguage); return string; }
@Test public void should_ignore_euro_and_return_default() { assertEquals(new Locale("nl", "nl"), LocaleUtil.currencyForLanguageTag("euro")); }
@Test public void should_default_to_nl_when_locale_not_set() { assertEquals(new Locale("nl", "nl"), LocaleUtil.forLanguageTag("")); }
@Test public void should_deserialize_locale2() { assertEquals(new Locale("nl", "BE"), LocaleUtil.forLanguageTag("nl-BE")); }
@Test public void should_deserialize_locale() { assertEquals(Locale.US, LocaleUtil.forLanguageTag("en-US")); }
@Test public void should_deserialize_locale_with_just_languageTag() { assertEquals(new Locale("en"), LocaleUtil.forLanguageTag("en")); }
@Test public void should_serialize_locale_with_just_languageTag() { assertEquals("en", LocaleUtil.toLanguageTag(new Locale("en"))); }
@Test public void should_serialize_valid_predefined_locale() { String languageTag = LocaleUtil.toLanguageTag(Locale.US); assertEquals("en-US", languageTag); }
public RiverContext setLocale(String languageTag) { this.locale = LocaleUtil.toLocale(languageTag); Locale.setDefault(locale); // for JDBC drivers internals return this; }
public static void main(String[] args) throws Exception { info("Set Application Info"); ApplicationInfo.init(); printOut(ApplicationInfo.getHeaderInfo()); info("Initialize Arguments"); Arguments.init(args); info("Initialize Logger"); if (Arguments.isBatch()) LoggerUtil.initFlatLogger(); else LoggerUtil.initLogger(); info("Initialize Locale"); LocaleUtil.initLocale(); Util.initScriptStyle(); info("Loading modules"); List<Module> modules = Modules.loadSuiteModules(); if (modules.isEmpty()) { if (Arguments.isBatch()) { modules = Modules.loadBatchModules(null); info("Starting modules"); Injector injector = Guice.createInjector(modules); info("Go to Batch"); Batch batch = injector.getInstance(Batch.class); info("Launch Batch"); batch.run(); } else { modules = Modules.loadApplicationModules(null); info("Starting modules"); Injector injector = Guice.createInjector(modules); info("Loading LookAndFeel"); ILookAndFeel laf = injector.getInstance(ILookAndFeel.class); laf.init(); info("Check License"); ApplicationLauncher launcher = injector.getInstance(ApplicationLauncher.class); launcher.checkLicense(); info("Loading Application"); Application application = injector.getInstance(Application.class); UiUtil.renameUIThread(); info("Layout Application"); SwingUtilities.invokeLater(application); } } else { info("Starting modules"); Injector injector = Guice.createInjector(modules); info("Loading LookAndFeel"); ILookAndFeel laf = injector.getInstance(ILookAndFeel.class); laf.init(); info("Loading Suite"); Suite suite = injector.getInstance(Suite.class); if (Arguments.isBatch()) { info("Go to Batch"); suite.batch(); } else { info("Start Suite"); UiUtil.installExceptionHandler(); UiUtil.renameUIThread(); suite.launch(); } } }