예제 #1
0
 /**
  * The resource is a list of objects. Gets the value(s) of the specified property of one or more
  * objects in the list. The objects in the list are identified by their index in the list (from 1
  * to n). The key used to find the asked value(s) is composed first by the list identifier, an
  * underscore separator, then by the index of the object in the list, a dot separator, and finally
  * ends with the object's property name.<br>
  * For example : <code>
  *   <ul>
  *   <li>User_1.Name=firstName</li>
  *   <li>User_2.Name=lastName</li>
  *   <li>...</li>
  *   </ul>
  * </code> If the computed key isn't defined in the bundle, then no {@link
  * MissingResourceException} exception is thrown (for compatibility reason with Silverpeas
  * versions lesser than 6).
  *
  * @param list the identifier of the list in the bundle.
  * @param property the object's property for which the value will be fetch.
  * @param max the maximum number of objects to read from 1 to n. If max is -1 then the list is
  *     iterated up to find an object whose the property is set. If max is >= 1 then the specified
  *     property of the first max objects are read (if the property isn't set for an object, it is
  *     set to an empty string).
  * @return an array of string with one property value (if max is 1) or with several values (if max
  *     = -1 or > 1). If the property of an object to read exists but isn't set, then an empty
  *     string is set in the array.
  * @throws MissingResourceException if the bundle doesn't exist.
  */
 default SilverpeasBundleList getStringList(String list, String property, int max)
     throws MissingResourceException {
   int i = 1;
   SilverpeasBundleList finalList = SilverpeasBundleList.with();
   while ((i <= max) || (max == -1)) {
     try {
       String key = list + "_" + Integer.toString(i) + "." + property;
       String s = getString(key);
       if (s == null) {
         throw new MissingResourceException(getBaseBundleName(), getClass().getName(), key);
       }
       finalList.add(s);
     } catch (MissingResourceException ex) {
       if (ex.getKey() == null || ex.getKey().trim().isEmpty()) {
         throw ex;
       }
       if (max == -1) {
         max = i;
       } else {
         finalList.add("");
       }
     }
     i++;
   }
   return finalList;
 }
예제 #2
0
  public void test_getISO3Language() {
    // Empty language code.
    assertEquals("", new Locale("", "US").getISO3Language());

    // Invalid language code.
    try {
      assertEquals("", new Locale("xx", "US").getISO3Language());
      fail();
    } catch (MissingResourceException expected) {
      assertEquals("FormatData_xx_US", expected.getClassName());
      assertEquals("ShortLanguage", expected.getKey());
    }

    // Valid language code.
    assertEquals("eng", new Locale("en", "").getISO3Language());
    assertEquals("eng", new Locale("en", "CA").getISO3Language());
    assertEquals("eng", new Locale("en", "XX").getISO3Language());
  }
예제 #3
0
  public void test_getISO3Country() {
    // Empty country code.
    assertEquals("", new Locale("en", "").getISO3Country());

    // Invalid country code.
    try {
      assertEquals("", new Locale("en", "XX").getISO3Country());
      fail();
    } catch (MissingResourceException expected) {
      assertEquals("FormatData_en_XX", expected.getClassName());
      assertEquals("ShortCountry", expected.getKey());
    }

    // Valid country code.
    assertEquals("CAN", new Locale("", "CA").getISO3Country());
    assertEquals("CAN", new Locale("en", "CA").getISO3Country());
    assertEquals("CAN", new Locale("xx", "CA").getISO3Country());
  }