@Test public void testGetBundle() { Set<BundleName> bundles = EnumSet.of(BundleName.MODS_PAGE_TYPES); String locale = "cs"; boolean sorted = true; LocalizationResource instance = new LocalizationResource(null); SmartGwtResponse<Item> result = instance.getBundle(bundles, locale, sorted); assertNotNull(result); assertFalse(result.getData().isEmpty()); System.out.println(result.getData()); }
@GET @Produces({MediaType.APPLICATION_JSON}) public SmartGwtResponse<Item> getBundle( @QueryParam(LocalizationResourceApi.ITEM_BUNDLENAME) Set<BundleName> bundleNames, @DefaultValue("") @QueryParam(LocalizationResourceApi.GETBUNDLE_LOCALE_PARAM) String locale, @DefaultValue("true") @QueryParam(LocalizationResourceApi.GETBUNDLE_SORTED_PARAM) boolean sorted) { if (bundleNames == null || bundleNames.isEmpty()) { bundleNames = EnumSet.allOf(BundleName.class); } Locale localeObj; if (locale == null || locale.isEmpty()) { List<Locale> acceptableLanguages = httpHeaders.getAcceptableLanguages(); localeObj = acceptableLanguages.isEmpty() ? Locale.ENGLISH : acceptableLanguages.get(0); } else { localeObj = new Locale(locale); } Control control = ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES); ArrayList<Item> result = new ArrayList<Item>(); for (BundleName bundleName : bundleNames) { try { if (!BundleName.PROPERTIES.equals(bundleName.getFormat())) { continue; } result.addAll(readBundle(bundleName, localeObj, control, sorted)); } catch (MissingResourceException ex) { LOG.log(Level.WARNING, bundleNames.toString(), ex); throw RestException.plainNotFound( LocalizationResourceApi.ITEM_BUNDLENAME, bundleName.toString()); } } return new SmartGwtResponse<Item>(result); }
LocalizationResource { @GET @Produces({MediaType.APPLICATION_JSON}) public SmartGwtResponse<Item> getBundle( @QueryParam(LocalizationResourceApi.ITEM_BUNDLENAME) Set<BundleName> bundleNames, @DefaultValue("") @QueryParam(LocalizationResourceApi.GETBUNDLE_LOCALE_PARAM) String locale, @DefaultValue("true") @QueryParam(LocalizationResourceApi.GETBUNDLE_SORTED_PARAM) boolean sorted) { if (bundleNames == null || bundleNames.isEmpty()) { bundleNames = EnumSet.allOf(BundleName.class); } Locale localeObj; if (locale == null || locale.isEmpty()) { List<Locale> acceptableLanguages = httpHeaders.getAcceptableLanguages(); localeObj = acceptableLanguages.isEmpty() ? Locale.ENGLISH : acceptableLanguages.get(0); } else { localeObj = new Locale(locale); } Control control = ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES); ArrayList<Item> result = new ArrayList<Item>(); for (BundleName bundleName : bundleNames) { try { if (!BundleName.PROPERTIES.equals(bundleName.getFormat())) { continue; } result.addAll(readBundle(bundleName, localeObj, control, sorted)); } catch (MissingResourceException ex) { LOG.log(Level.WARNING, bundleNames.toString(), ex); throw RestException.plainNotFound( LocalizationResourceApi.ITEM_BUNDLENAME, bundleName.toString()); } } return new SmartGwtResponse<Item>(result); } }
LocalizationResource { @GET @Produces({MediaType.APPLICATION_JSON}) public SmartGwtResponse<Item> getBundle( @QueryParam(LocalizationResourceApi.ITEM_BUNDLENAME) Set<BundleName> bundleNames, @DefaultValue("") @QueryParam(LocalizationResourceApi.GETBUNDLE_LOCALE_PARAM) String locale, @DefaultValue("true") @QueryParam(LocalizationResourceApi.GETBUNDLE_SORTED_PARAM) boolean sorted) { if (bundleNames == null || bundleNames.isEmpty()) { bundleNames = EnumSet.allOf(BundleName.class); } Locale localeObj; if (locale == null || locale.isEmpty()) { List<Locale> acceptableLanguages = httpHeaders.getAcceptableLanguages(); localeObj = acceptableLanguages.isEmpty() ? Locale.ENGLISH : acceptableLanguages.get(0); } else { localeObj = new Locale(locale); } Control control = ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES); ArrayList<Item> result = new ArrayList<Item>(); for (BundleName bundleName : bundleNames) { try { if (!BundleName.PROPERTIES.equals(bundleName.getFormat())) { continue; } result.addAll(readBundle(bundleName, localeObj, control, sorted)); } catch (MissingResourceException ex) { LOG.log(Level.WARNING, bundleNames.toString(), ex); throw RestException.plainNotFound( LocalizationResourceApi.ITEM_BUNDLENAME, bundleName.toString()); } } return new SmartGwtResponse<Item>(result); } LocalizationResource(
            @Context HttpHeaders httpHeaders
            ); }
LocalizationResource { @GET @Produces({MediaType.APPLICATION_JSON}) public SmartGwtResponse<Item> getBundle( @QueryParam(LocalizationResourceApi.ITEM_BUNDLENAME) Set<BundleName> bundleNames, @DefaultValue("") @QueryParam(LocalizationResourceApi.GETBUNDLE_LOCALE_PARAM) String locale, @DefaultValue("true") @QueryParam(LocalizationResourceApi.GETBUNDLE_SORTED_PARAM) boolean sorted) { if (bundleNames == null || bundleNames.isEmpty()) { bundleNames = EnumSet.allOf(BundleName.class); } Locale localeObj; if (locale == null || locale.isEmpty()) { List<Locale> acceptableLanguages = httpHeaders.getAcceptableLanguages(); localeObj = acceptableLanguages.isEmpty() ? Locale.ENGLISH : acceptableLanguages.get(0); } else { localeObj = new Locale(locale); } Control control = ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES); ArrayList<Item> result = new ArrayList<Item>(); for (BundleName bundleName : bundleNames) { try { if (!BundleName.PROPERTIES.equals(bundleName.getFormat())) { continue; } result.addAll(readBundle(bundleName, localeObj, control, sorted)); } catch (MissingResourceException ex) { LOG.log(Level.WARNING, bundleNames.toString(), ex); throw RestException.plainNotFound( LocalizationResourceApi.ITEM_BUNDLENAME, bundleName.toString()); } } return new SmartGwtResponse<Item>(result); } LocalizationResource(
            @Context HttpHeaders httpHeaders
            ); @GET @Produces({MediaType.APPLICATION_JSON}) SmartGwtResponse<Item> getBundle(
            @QueryParam(LocalizationResourceApi.ITEM_BUNDLENAME) Set<BundleName> bundleNames,
            @DefaultValue("")
            @QueryParam(LocalizationResourceApi.GETBUNDLE_LOCALE_PARAM) String locale,
            @DefaultValue("true")
            @QueryParam(LocalizationResourceApi.GETBUNDLE_SORTED_PARAM) boolean sorted); }
LocalizationResource { @GET @Produces({MediaType.APPLICATION_JSON}) public SmartGwtResponse<Item> getBundle( @QueryParam(LocalizationResourceApi.ITEM_BUNDLENAME) Set<BundleName> bundleNames, @DefaultValue("") @QueryParam(LocalizationResourceApi.GETBUNDLE_LOCALE_PARAM) String locale, @DefaultValue("true") @QueryParam(LocalizationResourceApi.GETBUNDLE_SORTED_PARAM) boolean sorted) { if (bundleNames == null || bundleNames.isEmpty()) { bundleNames = EnumSet.allOf(BundleName.class); } Locale localeObj; if (locale == null || locale.isEmpty()) { List<Locale> acceptableLanguages = httpHeaders.getAcceptableLanguages(); localeObj = acceptableLanguages.isEmpty() ? Locale.ENGLISH : acceptableLanguages.get(0); } else { localeObj = new Locale(locale); } Control control = ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES); ArrayList<Item> result = new ArrayList<Item>(); for (BundleName bundleName : bundleNames) { try { if (!BundleName.PROPERTIES.equals(bundleName.getFormat())) { continue; } result.addAll(readBundle(bundleName, localeObj, control, sorted)); } catch (MissingResourceException ex) { LOG.log(Level.WARNING, bundleNames.toString(), ex); throw RestException.plainNotFound( LocalizationResourceApi.ITEM_BUNDLENAME, bundleName.toString()); } } return new SmartGwtResponse<Item>(result); } LocalizationResource(
            @Context HttpHeaders httpHeaders
            ); @GET @Produces({MediaType.APPLICATION_JSON}) SmartGwtResponse<Item> getBundle(
            @QueryParam(LocalizationResourceApi.ITEM_BUNDLENAME) Set<BundleName> bundleNames,
            @DefaultValue("")
            @QueryParam(LocalizationResourceApi.GETBUNDLE_LOCALE_PARAM) String locale,
            @DefaultValue("true")
            @QueryParam(LocalizationResourceApi.GETBUNDLE_SORTED_PARAM) boolean sorted);  }