1.1 --- a/openide.util/apichanges.xml Thu Jul 30 02:55:54 2009 +0400
1.2 +++ b/openide.util/apichanges.xml Thu Aug 06 02:56:03 2009 +0400
1.3 @@ -49,6 +49,22 @@
1.4 <apidef name="actions">Actions API</apidef>
1.5 </apidefs>
1.6 <changes>
1.7 + <change id="NbBundle.varargs">
1.8 + <api name="util"/>
1.9 + <summary><code>NbBundle.getMessage</code> can take arbitrarily many format arguments</summary>
1.10 + <version major="7" minor="27"/>
1.11 + <date day="5" month="8" year="2009"/>
1.12 + <author login="jglick"/>
1.13 + <compatibility addition="yes"/>
1.14 + <description>
1.15 + <p>
1.16 + <code>NbBundle.getMessage</code> now has a varargs overload that
1.17 + permits you to specify four or more format arguments without
1.18 + explicitly constructing an array.
1.19 + </p>
1.20 + </description>
1.21 + <class package="org.openide.util" name="NbBundle"/>
1.22 + </change>
1.23 <change id="EditableProperties">
1.24 <api name="util"/>
1.25 <summary>Copied API from <code>project.ant</code> for <code>EditableProperties</code>.</summary>
2.1 --- a/openide.util/nbproject/project.properties Thu Jul 30 02:55:54 2009 +0400
2.2 +++ b/openide.util/nbproject/project.properties Thu Aug 06 02:56:03 2009 +0400
2.3 @@ -42,7 +42,7 @@
2.4 module.jar.dir=lib
2.5 cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
2.6
2.7 -spec.version.base=7.26.0
2.8 +spec.version.base=7.27.0
2.9
2.10 # For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
2.11
3.1 --- a/openide.util/src/org/openide/util/NbBundle.java Thu Jul 30 02:55:54 2009 +0400
3.2 +++ b/openide.util/src/org/openide/util/NbBundle.java Thu Aug 06 02:56:03 2009 +0400
3.3 @@ -65,17 +65,19 @@
3.4 import java.util.logging.Logger;
3.5
3.6 /** Convenience class permitting easy loading of localized resources of various sorts.
3.7 -* Extends the functionality of the default Java resource support, and interacts
3.8 -* better with class loaders in a multiple-loader system.
3.9 +* Extends the functionality of {@link ResourceBundle} to handle branding, and interacts
3.10 +* better with class loaders in a module system.
3.11 * <p>Example usage:
3.12 -* <p><code><pre>
3.13 +* <pre>
3.14 * package com.mycom;
3.15 * public class Foo {
3.16 -* // Search for tag Foo_theMessage in /com/mycom/Bundle.properties:
3.17 -* private static String theMessage = {@link NbBundle#getMessage(Class, String) NbBundle.getMessage} (Foo.class, "Foo_theMessage");
3.18 -* // Might also look in /com/mycom/Bundle_de.properties, etc.
3.19 +* public String getDisplayName() {
3.20 +* return {@link #getMessage(Class,String) NbBundle.getMessage}(Foo.class, "Foo.displayName");
3.21 +* }
3.22 * }
3.23 -* </pre></code>
3.24 +* </pre>
3.25 +* will in German locale look for the key {@code Foo.displayName} in
3.26 +* {@code com/mycom/Bundle_de.properties} and then {@code com/mycom/Bundle.properties} (in that order).
3.27 */
3.28 public class NbBundle extends Object {
3.29
3.30 @@ -375,7 +377,8 @@
3.31
3.32 /** Get a resource bundle in the same package as the provided class,
3.33 * with the default locale/branding and the class' own classloader.
3.34 - * This is the usual style of invocation.
3.35 + * The usual style of invocation is {@link #getMessage(Class,String)}
3.36 + * or one of the other overloads taking message formats.
3.37 *
3.38 * @param clazz the class to take the package name from
3.39 * @return the resource bundle
3.40 @@ -621,7 +624,7 @@
3.41
3.42 /**
3.43 * Finds a localized and/or branded string in a bundle.
3.44 - * @param clazz the class to use to locate the bundle
3.45 + * @param clazz the class to use to locate the bundle (see {@link #getBundle(Class)} for details)
3.46 * @param resName name of the resource to look for
3.47 * @return the string associated with the resource
3.48 * @throws MissingResourceException if either the bundle or the string cannot be found
3.49 @@ -635,7 +638,7 @@
3.50 * Finds a localized and/or branded string in a bundle and formats the message
3.51 * by passing requested parameters.
3.52 *
3.53 - * @param clazz the class to use to locate the bundle
3.54 + * @param clazz the class to use to locate the bundle (see {@link #getBundle(Class)} for details)
3.55 * @param resName name of the resource to look for
3.56 * @param param1 the argument to use when formatting the message
3.57 * @return the string associated with the resource
3.58 @@ -651,7 +654,7 @@
3.59 * Finds a localized and/or branded string in a bundle and formats the message
3.60 * by passing requested parameters.
3.61 *
3.62 - * @param clazz the class to use to locate the bundle
3.63 + * @param clazz the class to use to locate the bundle (see {@link #getBundle(Class)} for details)
3.64 * @param resName name of the resource to look for
3.65 * @param param1 the argument to use when formatting the message
3.66 * @param param2 the second argument to use for formatting
3.67 @@ -668,7 +671,7 @@
3.68 * Finds a localized and/or branded string in a bundle and formats the message
3.69 * by passing requested parameters.
3.70 *
3.71 - * @param clazz the class to use to locate the bundle
3.72 + * @param clazz the class to use to locate the bundle (see {@link #getBundle(Class)} for details)
3.73 * @param resName name of the resource to look for
3.74 * @param param1 the argument to use when formatting the message
3.75 * @param param2 the second argument to use for formatting
3.76 @@ -686,7 +689,34 @@
3.77 * Finds a localized and/or branded string in a bundle and formats the message
3.78 * by passing requested parameters.
3.79 *
3.80 - * @param clazz the class to use to locate the bundle
3.81 + * @param clazz the class to use to locate the bundle (see {@link #getBundle(Class)} for details)
3.82 + * @param resName name of the resource to look for
3.83 + * @param param1 the argument to use when formatting the message
3.84 + * @param param2 the second argument to use for formatting
3.85 + * @param param3 the third argument to use for formatting
3.86 + * @param param4 the fourth argument to use for formatting
3.87 + * @param params fifth, sixth, ... arguments as needed
3.88 + * @return the string associated with the resource
3.89 + * @throws MissingResourceException if either the bundle or the string cannot be found
3.90 + * @see java.text.MessageFormat#format(String,Object[])
3.91 + * @since org.openide.util 7.27
3.92 + */
3.93 + public static String getMessage(Class clazz, String resName, Object param1, Object param2, Object param3, Object param4, Object... params)
3.94 + throws MissingResourceException {
3.95 + Object[] allParams = new Object[params.length + 4];
3.96 + allParams[0] = param1;
3.97 + allParams[1] = param2;
3.98 + allParams[2] = param3;
3.99 + allParams[3] = param4;
3.100 + System.arraycopy(params, 0, allParams, 4, params.length);
3.101 + return getMessage(clazz, resName, allParams);
3.102 + }
3.103 +
3.104 + /**
3.105 + * Finds a localized and/or branded string in a bundle and formats the message
3.106 + * by passing requested parameters.
3.107 + *
3.108 + * @param clazz the class to use to locate the bundle (see {@link #getBundle(Class)} for details)
3.109 * @param resName name of the resource to look for
3.110 * @param arr array of parameters to use for formatting the message
3.111 * @return the string associated with the resource
3.112 @@ -760,7 +790,7 @@
3.113 this.attrs = attrs;
3.114 }
3.115
3.116 - public String get(Object _k) {
3.117 + public @Override String get(Object _k) {
3.118 if (!(_k instanceof String)) {
3.119 return null;
3.120 }
3.121 @@ -805,7 +835,7 @@
3.122 return m.get(key);
3.123 }
3.124
3.125 - public Locale getLocale() {
3.126 + public @Override Locale getLocale() {
3.127 return locale;
3.128 }
3.129 }
3.130 @@ -830,7 +860,7 @@
3.131 this.sub2 = sub2;
3.132 }
3.133
3.134 - public Locale getLocale() {
3.135 + public @Override Locale getLocale() {
3.136 return loc;
3.137 }
3.138
3.139 @@ -1046,7 +1076,7 @@
3.140 }
3.141 }
3.142
3.143 - public InputStream getResourceAsStream(String name) {
3.144 + public @Override InputStream getResourceAsStream(String name) {
3.145 InputStream base = super.getResourceAsStream(name);
3.146
3.147 if (base == null) {
4.1 --- a/openide.util/test/unit/src/org/openide/util/NbBundleTest.java Thu Jul 30 02:55:54 2009 +0400
4.2 +++ b/openide.util/test/unit/src/org/openide/util/NbBundleTest.java Thu Aug 06 02:56:03 2009 +0400
4.3 @@ -141,13 +141,20 @@
4.4 }
4.5
4.6 public void testGetMessage() throws Exception {
4.7 - ClassLoader l = fixedLoader("org/openide/util/Bundle.properties:k1=v1\nk2=v2 {0}", "org/openide/util/Bundle_ja.properties:k1=v1 ja");
4.8 + ClassLoader l = fixedLoader(
4.9 + "org/openide/util/Bundle.properties:" +
4.10 + "k1=v1\n" +
4.11 + "k2=v2 {0}\n" +
4.12 + "k3=v3 {0} {1} {2} {3} {4}",
4.13 + "org/openide/util/Bundle_ja.properties:" +
4.14 + "k1=v1 ja");
4.15 Class<?> c = l.loadClass(Dummy.class.getName());
4.16 assertEquals(l, c.getClassLoader());
4.17 assertEquals("v1", NbBundle.getMessage(c, "k1"));
4.18 Locale.setDefault(Locale.JAPAN);
4.19 assertEquals("v1 ja", NbBundle.getMessage(c, "k1"));
4.20 assertEquals("v2 x", NbBundle.getMessage(c, "k2", "x"));
4.21 + assertEquals("v3 a b c d e", NbBundle.getMessage(c, "k3", "a", "b", "c", "d", "e"));
4.22 }
4.23
4.24 static class Dummy {}