diff --git a/pom.xml b/pom.xml index c21b6bf..13637fb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,12 @@ + 4.0.0 - plexus-components org.codehaus.plexus - 6.5 + plexus + 16 + plexus-i18n @@ -13,14 +15,14 @@ Plexus I18N Component - scm:git:git@github.com:codehaus-plexus/plexus-i18n.git - scm:git:git@github.com:codehaus-plexus/plexus-i18n.git - http://github.com/codehaus-plexus/plexus-i18n + scm:git:https://github.com/codehaus-plexus/plexus-i18n.git + ${project.scm.connection} HEAD + https://github.com/codehaus-plexus/plexus-i18n github - http://github.com/codehaus-plexus/plexus-i18n/issues + https://github.com/codehaus-plexus/plexus-i18n/issues @@ -37,10 +39,23 @@ org.codehaus.plexus plexus-container-default + 2.1.1 + + + org.codehaus.plexus + plexus-component-annotations + 2.1.1 + provided org.codehaus.plexus plexus-utils + 4.0.0 + + + org.codehaus.plexus + plexus-xml + 3.0.0 @@ -50,15 +65,17 @@ org.apache.maven.plugins maven-scm-publish-plugin - ${project.reporting.outputDirectory} + ${project.reporting.outputDirectory} + scm-publish - site-deploy + publish-scm + site-deploy diff --git a/src/main/java/org/codehaus/plexus/i18n/DefaultI18N.java b/src/main/java/org/codehaus/plexus/i18n/DefaultI18N.java index 8b3cebf..fc74e8f 100644 --- a/src/main/java/org/codehaus/plexus/i18n/DefaultI18N.java +++ b/src/main/java/org/codehaus/plexus/i18n/DefaultI18N.java @@ -16,27 +16,25 @@ * limitations under the License. */ -import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; -import org.codehaus.plexus.util.StringUtils; - +import java.lang.reflect.Field; import java.text.MessageFormat; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; -import java.lang.reflect.Field; + +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.codehaus.plexus.util.StringUtils; /** - * @plexus.component - * role="org.codehaus.plexus.i18n.I18N" + * */ -public class DefaultI18N - extends AbstractLogEnabled - implements I18N, Initializable -{ +@Component(role = I18N.class) +public class DefaultI18N extends AbstractLogEnabled implements I18N, Initializable { private static final Object[] NO_ARGS = new Object[0]; private HashMap bundles; @@ -57,34 +55,28 @@ public class DefaultI18N // Accessors // ---------------------------------------------------------------------- - public String getDefaultLanguage() - { + public String getDefaultLanguage() { return defaultLanguage; } - public String getDefaultCountry() - { + public String getDefaultCountry() { return defaultCountry; } - public String getDefaultBundleName() - { + public String getDefaultBundleName() { return defaultBundleName; } - public String[] getBundleNames() - { + public String[] getBundleNames() { return (String[]) bundleNames.clone(); } - public ResourceBundle getBundle() - { - return getBundle( getDefaultBundleName(), (Locale) null ); + public ResourceBundle getBundle() { + return getBundle(getDefaultBundleName(), (Locale) null); } - public ResourceBundle getBundle( String bundleName ) - { - return getBundle( bundleName, (Locale) null ); + public ResourceBundle getBundle(String bundleName) { + return getBundle(bundleName, (Locale) null); } /** @@ -96,9 +88,8 @@ public ResourceBundle getBundle( String bundleName ) * @param languageHeader A String with the language header. * @return A localized ResourceBundle. */ - public ResourceBundle getBundle( String bundleName, String languageHeader ) - { - return getBundle( bundleName, getLocale( languageHeader ) ); + public ResourceBundle getBundle(String bundleName, String languageHeader) { + return getBundle(bundleName, getLocale(languageHeader)); } /** @@ -111,66 +102,56 @@ public ResourceBundle getBundle( String bundleName, String languageHeader ) * indicated by the default language and country). * @return A localized ResourceBundle. */ - public ResourceBundle getBundle( String bundleName, Locale locale ) - { + public ResourceBundle getBundle(String bundleName, Locale locale) { // Assure usable inputs. - bundleName = ( bundleName == null ? getDefaultBundleName() : bundleName.trim() ); + bundleName = (bundleName == null ? getDefaultBundleName() : bundleName.trim()); // ---------------------------------------------------------------------- // A hack to make sure the properties files are always checked // ---------------------------------------------------------------------- - if ( devMode ) - { - try - { - Class klass = ResourceBundle.getBundle( bundleName ).getClass().getSuperclass(); + if (devMode) { + try { + Class klass = ResourceBundle.getBundle(bundleName).getClass().getSuperclass(); - Field field = klass.getDeclaredField( "cacheList" ); + Field field = klass.getDeclaredField("cacheList"); - field.setAccessible( true ); + field.setAccessible(true); -// SoftCache cache = (SoftCache) field.get( null ); -// -// cache.clear(); + // SoftCache cache = (SoftCache) field.get( null ); + // + // cache.clear(); - Object cache = field.get( null ); + Object cache = field.get(null); - cache.getClass().getDeclaredMethod( "clear", null ).invoke( cache, null ); + cache.getClass().getDeclaredMethod("clear", null).invoke(cache, null); - field.setAccessible( false ); - } - catch ( Exception e ) - { + field.setAccessible(false); + } catch (Exception e) { // Intentional } } - if ( locale == null ) - { - locale = getLocale( null ); + if (locale == null) { + locale = getLocale(null); } // Find/retrieve/cache bundle. ResourceBundle rb; - HashMap bundlesByLocale = (HashMap) bundles.get( bundleName ); + HashMap bundlesByLocale = (HashMap) bundles.get(bundleName); - if ( bundlesByLocale != null ) - { + if (bundlesByLocale != null) { // Cache of bundles by locale for the named bundle exists. // Check the cache for a bundle corresponding to locale. - rb = (ResourceBundle) bundlesByLocale.get( locale ); + rb = (ResourceBundle) bundlesByLocale.get(locale); - if ( rb == null ) - { + if (rb == null) { // Not yet cached. - rb = cacheBundle( bundleName, locale ); + rb = cacheBundle(bundleName, locale); } - } - else - { - rb = cacheBundle( bundleName, locale ); + } else { + rb = cacheBundle(bundleName, locale); } return rb; @@ -179,14 +160,11 @@ public ResourceBundle getBundle( String bundleName, Locale locale ) /** * @see I18N#getLocale(String) */ - public Locale getLocale( String header ) - { - if ( !StringUtils.isEmpty( header ) ) - { - I18NTokenizer tok = new I18NTokenizer( header ); - - if ( tok.hasNext() ) - { + public Locale getLocale(String header) { + if (!StringUtils.isEmpty(header)) { + I18NTokenizer tok = new I18NTokenizer(header); + + if (tok.hasNext()) { return (Locale) tok.next(); } } @@ -195,50 +173,42 @@ public Locale getLocale( String header ) return defaultLocale; } - public String getString( String key ) - { - return getString( key, null ); + public String getString(String key) { + return getString(key, null); } - public String getString( String key, Locale locale ) - { - return getString( getDefaultBundleName(), locale, key ); + public String getString(String key, Locale locale) { + return getString(getDefaultBundleName(), locale, key); } /** * @throws MissingResourceException Specified key cannot be matched. * @see I18N#getString(String, Locale, String) */ - public String getString( String bundleName, Locale locale, String key ) - { + public String getString(String bundleName, Locale locale, String key) { String value; - if ( locale == null ) - { - locale = getLocale( null ); + if (locale == null) { + locale = getLocale(null); } // Look for text in requested bundle. - ResourceBundle rb = getBundle( bundleName, locale ); + ResourceBundle rb = getBundle(bundleName, locale); - value = getStringOrNull( rb, key ); + value = getStringOrNull(rb, key); // Look for text in list of default bundles. - if ( value == null && bundleNames.length > 0 ) - { + if (value == null && bundleNames.length > 0) { String name; - for ( int i = 0; i < bundleNames.length; i++ ) - { + for (int i = 0; i < bundleNames.length; i++) { name = bundleNames[i]; - if ( !name.equals( bundleName ) ) - { - rb = getBundle( name, locale ); + if (!name.equals(bundleName)) { + rb = getBundle(name, locale); - value = getStringOrNull( rb, key ); + value = getStringOrNull(rb, key); - if ( value != null ) - { + if (value != null) { locale = rb.getLocale(); break; @@ -247,13 +217,13 @@ public String getString( String bundleName, Locale locale, String key ) } } - if ( value == null ) - { + if (value == null) { String loc = locale.toString(); - String mesg = "Noticed missing resource: " + "bundleName=" + bundleName + ", locale=" + loc + ", key=" + key; + String mesg = + "Noticed missing resource: " + "bundleName=" + bundleName + ", locale=" + loc + ", key=" + key; - getLogger().debug( mesg ); + getLogger().debug(mesg); // Just send back the key, we don't need to throw an exception. @@ -263,37 +233,26 @@ public String getString( String bundleName, Locale locale, String key ) return value; } - public String format( String key, Object arg1 ) - { - return format( defaultBundleName, defaultLocale, key, new Object[]{arg1} ); + public String format(String key, Object arg1) { + return format(defaultBundleName, defaultLocale, key, new Object[] {arg1}); } - public String format( String key, Object arg1, Object arg2 ) - { - return format( defaultBundleName, defaultLocale, key, new Object[]{arg1, arg2} ); + public String format(String key, Object arg1, Object arg2) { + return format(defaultBundleName, defaultLocale, key, new Object[] {arg1, arg2}); } /** * @see I18N#format(String, Locale, String, Object) */ - public String format( String bundleName, - Locale locale, - String key, - Object arg1 ) - { - return format( bundleName, locale, key, new Object[]{arg1} ); + public String format(String bundleName, Locale locale, String key, Object arg1) { + return format(bundleName, locale, key, new Object[] {arg1}); } /** * @see I18N#format(String, Locale, String, Object, Object) */ - public String format( String bundleName, - Locale locale, - String key, - Object arg1, - Object arg2 ) - { - return format( bundleName, locale, key, new Object[]{arg1, arg2} ); + public String format(String bundleName, Locale locale, String key, Object arg1, Object arg2) { + return format(bundleName, locale, key, new Object[] {arg1, arg2}); } /** @@ -305,18 +264,15 @@ public String format( String bundleName, * @return Localized, formatted text identified by * key. */ - public String format( String bundleName, Locale locale, String key, Object[] args ) - { - if ( locale == null ) - { + public String format(String bundleName, Locale locale, String key, Object[] args) { + if (locale == null) { // When formatting Date objects and such, MessageFormat // cannot have a null Locale. - locale = getLocale( null ); + locale = getLocale(null); } - String value = getString( bundleName, locale, key ); - if ( args == null ) - { + String value = getString(bundleName, locale, key); + if (args == null) { args = NO_ARGS; } @@ -324,28 +280,24 @@ public String format( String bundleName, Locale locale, String key, Object[] arg // this up by providing the Locale along with the string in the // constructor to MessageFormat. Until 1.4, the following workaround // is required for constructing the format with the appropriate locale: - MessageFormat messageFormat = new MessageFormat( "" ); - messageFormat.setLocale( locale ); - messageFormat.applyPattern( value ); + MessageFormat messageFormat = new MessageFormat(""); + messageFormat.setLocale(locale); + messageFormat.applyPattern(value); - return messageFormat.format( args ); + return messageFormat.format(args); } - /** * Called the first time the Service is used. */ - public void initialize() - throws InitializationException - { + public void initialize() throws InitializationException { bundles = new HashMap(); - defaultLocale = new Locale( defaultLanguage, defaultCountry ); + defaultLocale = new Locale(defaultLanguage, defaultCountry); initializeBundleNames(); - if ( "true".equals( System.getProperty( "PLEXUS_DEV_MODE" ) ) ) - { + if ("true".equals(System.getProperty("PLEXUS_DEV_MODE"))) { devMode = true; } } @@ -354,27 +306,21 @@ public void initialize() // Implementation // ---------------------------------------------------------------------- - protected void initializeBundleNames() - { - //System.err.println("cfg=" + getConfiguration()); - if ( defaultBundleName != null && defaultBundleName.length() > 0 ) - { + protected void initializeBundleNames() { + // System.err.println("cfg=" + getConfiguration()); + if (defaultBundleName != null && defaultBundleName.length() > 0) { // Using old-style single bundle name property. - if ( bundleNames == null || bundleNames.length <= 0 ) - { - bundleNames = new String[]{defaultBundleName}; - } - else - { + if (bundleNames == null || bundleNames.length <= 0) { + bundleNames = new String[] {defaultBundleName}; + } else { // Prepend "default" bundle name. String[] array = new String[bundleNames.length + 1]; array[0] = defaultBundleName; - System.arraycopy( bundleNames, 0, array, 1, bundleNames.length ); + System.arraycopy(bundleNames, 0, array, 1, bundleNames.length); bundleNames = array; } } - if ( bundleNames == null ) - { + if (bundleNames == null) { bundleNames = new String[0]; } } @@ -386,39 +332,31 @@ protected void initializeBundleNames() * * @throws MissingResourceException Bundle not found. */ - private synchronized ResourceBundle cacheBundle( String bundleName, Locale locale ) - throws MissingResourceException - { - HashMap bundlesByLocale = (HashMap) bundles.get( bundleName ); + private synchronized ResourceBundle cacheBundle(String bundleName, Locale locale) throws MissingResourceException { + HashMap bundlesByLocale = (HashMap) bundles.get(bundleName); - ResourceBundle rb = ( bundlesByLocale == null ? null : (ResourceBundle) bundlesByLocale.get( locale ) ); + ResourceBundle rb = (bundlesByLocale == null ? null : (ResourceBundle) bundlesByLocale.get(locale)); - if ( rb == null ) - { - bundlesByLocale = ( bundlesByLocale == null ? new HashMap( 3 ) : new HashMap( bundlesByLocale ) ); + if (rb == null) { + bundlesByLocale = (bundlesByLocale == null ? new HashMap(3) : new HashMap(bundlesByLocale)); - try - { - rb = ResourceBundle.getBundle( bundleName, locale ); - } - catch ( MissingResourceException e ) - { - rb = findBundleByLocale( bundleName, locale, bundlesByLocale ); + try { + rb = ResourceBundle.getBundle(bundleName, locale); + } catch (MissingResourceException e) { + rb = findBundleByLocale(bundleName, locale, bundlesByLocale); - if ( rb == null ) - { + if (rb == null) { throw (MissingResourceException) e.fillInStackTrace(); } } - if ( rb != null ) - { + if (rb != null) { // Cache bundle. - bundlesByLocale.put( rb.getLocale(), rb ); + bundlesByLocale.put(rb.getLocale(), rb); - HashMap bundlesByName = new HashMap( bundles ); + HashMap bundlesByName = new HashMap(bundles); - bundlesByName.put( bundleName, bundlesByLocale ); + bundlesByName.put(bundleName, bundlesByLocale); this.bundles = bundlesByName; } @@ -442,43 +380,30 @@ private synchronized ResourceBundle cacheBundle( String bundleName, Locale local *

Since we're really just guessing at possible bundles to use, * we don't ever throw MissingResourceException.

*/ - private ResourceBundle findBundleByLocale( String bundleName, - Locale locale, - Map bundlesByLocale ) - { + private ResourceBundle findBundleByLocale(String bundleName, Locale locale, Map bundlesByLocale) { ResourceBundle rb = null; - if ( !StringUtils.isNotEmpty( locale.getCountry() ) && - defaultLanguage.equals( locale.getLanguage() ) ) - { + if (!StringUtils.isNotEmpty(locale.getCountry()) && defaultLanguage.equals(locale.getLanguage())) { /* category.debug("Requested language '" + locale.getLanguage() + "' matches default: Attempting to guess bundle " + "using default country '" + defaultCountry + '\''); */ - Locale withDefaultCountry = new Locale( locale.getLanguage(), - defaultCountry ); - rb = (ResourceBundle) bundlesByLocale.get( withDefaultCountry ); - if ( rb == null ) - { - rb = getBundleIgnoreException( bundleName, withDefaultCountry ); + Locale withDefaultCountry = new Locale(locale.getLanguage(), defaultCountry); + rb = (ResourceBundle) bundlesByLocale.get(withDefaultCountry); + if (rb == null) { + rb = getBundleIgnoreException(bundleName, withDefaultCountry); } - } - else if ( !StringUtils.isNotEmpty( locale.getLanguage() ) && - defaultCountry.equals( locale.getCountry() ) ) - { - Locale withDefaultLanguage = new Locale( defaultLanguage, - locale.getCountry() ); - rb = (ResourceBundle) bundlesByLocale.get( withDefaultLanguage ); - if ( rb == null ) - { - rb = getBundleIgnoreException( bundleName, withDefaultLanguage ); + } else if (!StringUtils.isNotEmpty(locale.getLanguage()) && defaultCountry.equals(locale.getCountry())) { + Locale withDefaultLanguage = new Locale(defaultLanguage, locale.getCountry()); + rb = (ResourceBundle) bundlesByLocale.get(withDefaultLanguage); + if (rb == null) { + rb = getBundleIgnoreException(bundleName, withDefaultLanguage); } } - if ( rb == null && !defaultLocale.equals( locale ) ) - { - rb = getBundleIgnoreException( bundleName, defaultLocale ); + if (rb == null && !defaultLocale.equals(locale)) { + rb = getBundleIgnoreException(bundleName, defaultLocale); } return rb; @@ -490,38 +415,27 @@ else if ( !StringUtils.isNotEmpty( locale.getLanguage() ) && * returning null instead of throwing * MissingResourceException. */ - private ResourceBundle getBundleIgnoreException( String bundleName, Locale locale ) - { - try - { - return ResourceBundle.getBundle( bundleName, locale ); - } - catch ( MissingResourceException ignored ) - { + private ResourceBundle getBundleIgnoreException(String bundleName, Locale locale) { + try { + return ResourceBundle.getBundle(bundleName, locale); + } catch (MissingResourceException ignored) { return null; } } - /** * Gets localized text from a bundle if it's there. Otherwise, * returns null (ignoring a possible * MissingResourceException). */ - protected final String getStringOrNull( ResourceBundle rb, String key ) - { - if ( rb != null ) - { - try - { - return rb.getString( key ); - } - catch ( MissingResourceException ignored ) - { + protected final String getStringOrNull(ResourceBundle rb, String key) { + if (rb != null) { + try { + return rb.getString(key); + } catch (MissingResourceException ignored) { // intentional } } return null; } - } diff --git a/src/main/java/org/codehaus/plexus/i18n/I18N.java b/src/main/java/org/codehaus/plexus/i18n/I18N.java index c92db9e..e9c5db7 100644 --- a/src/main/java/org/codehaus/plexus/i18n/I18N.java +++ b/src/main/java/org/codehaus/plexus/i18n/I18N.java @@ -19,8 +19,7 @@ import java.util.Locale; import java.util.ResourceBundle; -public interface I18N -{ +public interface I18N { public static String ROLE = I18N.class.getName(); String ACCEPT_LANGUAGE = "Accept-Language"; @@ -35,27 +34,27 @@ public interface I18N ResourceBundle getBundle(); - ResourceBundle getBundle( String bundleName ); + ResourceBundle getBundle(String bundleName); - ResourceBundle getBundle( String bundleName, String languageHeader ); + ResourceBundle getBundle(String bundleName, String languageHeader); - ResourceBundle getBundle( String bundleName, Locale locale ); + ResourceBundle getBundle(String bundleName, Locale locale); - Locale getLocale( String languageHeader ); + Locale getLocale(String languageHeader); - String getString( String key ); + String getString(String key); - String getString( String key, Locale locale ); + String getString(String key, Locale locale); - String getString( String bundleName, Locale locale, String key ); + String getString(String bundleName, Locale locale, String key); - String format( String key, Object arg1 ); + String format(String key, Object arg1); - String format( String key, Object arg1, Object arg2 ); + String format(String key, Object arg1, Object arg2); - String format( String bundleName, Locale locale, String key, Object arg1 ); + String format(String bundleName, Locale locale, String key, Object arg1); - String format( String bundleName, Locale locale, String key, Object arg1, Object arg2 ); + String format(String bundleName, Locale locale, String key, Object arg1, Object arg2); - String format( String bundleName, Locale locale, String key, Object[] args ); + String format(String bundleName, Locale locale, String key, Object[] args); } diff --git a/src/main/java/org/codehaus/plexus/i18n/I18NTokenizer.java b/src/main/java/org/codehaus/plexus/i18n/I18NTokenizer.java index 7344cfa..0a7a06a 100644 --- a/src/main/java/org/codehaus/plexus/i18n/I18NTokenizer.java +++ b/src/main/java/org/codehaus/plexus/i18n/I18NTokenizer.java @@ -30,11 +30,9 @@ * @author Daniel Rall * @version $Id: I18NTokenizer.java 6675 2007-07-20 23:05:53Z olamy $ * - * @todo Move this class out of here as its purely web related. + * TODO Move this class out of here as its purely web related. */ -public class I18NTokenizer - implements Iterator -{ +public class I18NTokenizer implements Iterator { /** * Separates elements of the Accept-Language HTTP * header. @@ -63,30 +61,22 @@ public class I18NTokenizer * @param header The Accept-Language header * (i.e. en, es;q=0.8, zh-TW;q=0.1). */ - public I18NTokenizer(String header) - { + public I18NTokenizer(String header) { StringTokenizer tok = new StringTokenizer(header, LOCALE_SEPARATOR); - while (tok.hasMoreTokens()) - { + while (tok.hasMoreTokens()) { AcceptLanguage acceptLang = new AcceptLanguage(); String element = tok.nextToken().trim(); int index; // Record and cut off any quality value that comes after a // semi-colon. - if ( (index = element.indexOf(QUALITY_SEPARATOR)) != -1 ) - { + if ((index = element.indexOf(QUALITY_SEPARATOR)) != -1) { String q = element.substring(index); element = element.substring(0, index); - if ( (index = q.indexOf('=')) != -1 ) - { - try - { - acceptLang.quality = - Float.valueOf(q.substring(index + 1)); - } - catch (NumberFormatException useDefault) - { + if ((index = q.indexOf('=')) != -1) { + try { + acceptLang.quality = Float.valueOf(q.substring(index + 1)); + } catch (NumberFormatException useDefault) { } } } @@ -95,15 +85,11 @@ public I18NTokenizer(String header) // Create a Locale from the language. A dash may separate the // language from the country. - if ( (index = element.indexOf('-')) == -1 ) - { + if ((index = element.indexOf('-')) == -1) { // No dash means no country. acceptLang.locale = new Locale(element, ""); - } - else - { - acceptLang.locale = new Locale(element.substring(0, index), - element.substring(index + 1)); + } else { + acceptLang.locale = new Locale(element.substring(0, index), element.substring(index + 1)); } locales.add(acceptLang); @@ -116,8 +102,7 @@ public I18NTokenizer(String header) /** * @return Whether there are more locales. */ - public boolean hasNext() - { + public boolean hasNext() { return !locales.isEmpty(); } @@ -128,10 +113,8 @@ public boolean hasNext() * @return The next highest-rated Locale. * @throws NoSuchElementException No more locales. */ - public Object next() - { - if (locales.isEmpty()) - { + public Object next() { + if (locales.isEmpty()) { throw new NoSuchElementException(); } return ((AcceptLanguage) locales.remove(0)).locale; @@ -140,18 +123,15 @@ public Object next() /** * Not implemented. */ - public final void remove() - { - throw new UnsupportedOperationException(getClass().getName() + - " does not support remove()"); + public final void remove() { + throw new UnsupportedOperationException(getClass().getName() + " does not support remove()"); } /** * Struct representing an element of the HTTP * Accept-Language header. */ - private class AcceptLanguage implements Comparable - { + private class AcceptLanguage implements Comparable { /** * The language and country. */ @@ -163,9 +143,8 @@ private class AcceptLanguage implements Comparable */ Float quality = DEFAULT_QUALITY; - public final int compareTo(Object acceptLang) - { - return quality.compareTo( ((AcceptLanguage) acceptLang).quality ); + public final int compareTo(Object acceptLang) { + return quality.compareTo(((AcceptLanguage) acceptLang).quality); } } } diff --git a/src/test/java/org/codehaus/plexus/i18n/BarBundle.java b/src/test/java/org/codehaus/plexus/i18n/BarBundle.java index 02ed022..f8840bd 100644 --- a/src/test/java/org/codehaus/plexus/i18n/BarBundle.java +++ b/src/test/java/org/codehaus/plexus/i18n/BarBundle.java @@ -21,19 +21,15 @@ /** * A default resource bundle for use in testing. */ -public class BarBundle - extends ListResourceBundle -{ - private static final Object[][] CONTENTS = - { - { "key1", "[] value1" }, - { "key2", "[] value2" }, - { "key3", "[] value3" }, - { "key4", "[] value4" } +public class BarBundle extends ListResourceBundle { + private static final Object[][] CONTENTS = { + {"key1", "[] value1"}, + {"key2", "[] value2"}, + {"key3", "[] value3"}, + {"key4", "[] value4"} }; - - protected Object[][] getContents() - { + + protected Object[][] getContents() { return CONTENTS; } } diff --git a/src/test/java/org/codehaus/plexus/i18n/BarBundle_en_US.java b/src/test/java/org/codehaus/plexus/i18n/BarBundle_en_US.java index 44958a9..895afd1 100644 --- a/src/test/java/org/codehaus/plexus/i18n/BarBundle_en_US.java +++ b/src/test/java/org/codehaus/plexus/i18n/BarBundle_en_US.java @@ -21,19 +21,15 @@ /** * An english resource bundle for use in testing. */ -public class BarBundle_en_US - extends ListResourceBundle -{ - private static final Object[][] CONTENTS = - { - { "key1", "[en_US] value1" }, - { "key2", "[en_US] value2" }, - { "key3", "[en_US] value3" }, - { "key4", "[en_US] value4" } +public class BarBundle_en_US extends ListResourceBundle { + private static final Object[][] CONTENTS = { + {"key1", "[en_US] value1"}, + {"key2", "[en_US] value2"}, + {"key3", "[en_US] value3"}, + {"key4", "[en_US] value4"} }; - - protected Object[][] getContents() - { + + protected Object[][] getContents() { return CONTENTS; } } diff --git a/src/test/java/org/codehaus/plexus/i18n/BarBundle_ko_KR.java b/src/test/java/org/codehaus/plexus/i18n/BarBundle_ko_KR.java index bb26656..7edc9c2 100644 --- a/src/test/java/org/codehaus/plexus/i18n/BarBundle_ko_KR.java +++ b/src/test/java/org/codehaus/plexus/i18n/BarBundle_ko_KR.java @@ -21,18 +21,15 @@ /** * A dummied up Korean resource bundle for use in testing. */ -public class BarBundle_ko_KR extends ListResourceBundle -{ - private static final Object[][] CONTENTS = - { - { "key1", "[ko] value1" }, - { "key2", "[ko] value2" }, - { "key3", "[ko] value3" }, - { "key4", "[ko] value4" } +public class BarBundle_ko_KR extends ListResourceBundle { + private static final Object[][] CONTENTS = { + {"key1", "[ko] value1"}, + {"key2", "[ko] value2"}, + {"key3", "[ko] value3"}, + {"key4", "[ko] value4"} }; - - protected Object[][] getContents() - { + + protected Object[][] getContents() { return CONTENTS; } } diff --git a/src/test/java/org/codehaus/plexus/i18n/DefaultI18NTest.java b/src/test/java/org/codehaus/plexus/i18n/DefaultI18NTest.java index 64ac101..964faef 100644 --- a/src/test/java/org/codehaus/plexus/i18n/DefaultI18NTest.java +++ b/src/test/java/org/codehaus/plexus/i18n/DefaultI18NTest.java @@ -54,10 +54,10 @@ * . */ -import org.codehaus.plexus.PlexusTestCase; - import java.util.Locale; +import org.codehaus.plexus.PlexusTestCase; + /** * Tests the API of the * {@link org.codehaus.plexus.i18n.I18N}. @@ -66,90 +66,83 @@ * @author Daniel Rall * @author Jason van Zyl */ -public class DefaultI18NTest - extends PlexusTestCase -{ +public class DefaultI18NTest extends PlexusTestCase { private I18N i18n; - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); /* Set an unsupported locale to default to ensure we do not get unexpected matches */ - Locale.setDefault( new Locale( "jp" ) ); + Locale.setDefault(new Locale("jp")); - i18n = (I18N) lookup( I18N.ROLE ); + i18n = (I18N) lookup(I18N.ROLE); } - public void testLocalization() - { - String s0 = i18n.getString( null, null, "key1" ); + public void testLocalization() { + String s0 = i18n.getString(null, null, "key1"); - assertEquals( "Unable to retrieve localized text for locale: default", s0, "[] value1" ); + assertEquals("Unable to retrieve localized text for locale: default", s0, "[] value1"); - String s1 = i18n.getString( null, new Locale( "en", "US" ), "key2" ); + String s1 = i18n.getString(null, new Locale("en", "US"), "key2"); - assertEquals( "Unable to retrieve localized text for locale: en-US", s1, "[en_US] value2" ); + assertEquals("Unable to retrieve localized text for locale: en-US", s1, "[en_US] value2"); - String s2 = i18n.getString( "org.codehaus.plexus.i18n.BarBundle", new Locale( "ko", "KR" ), "key3" ); + String s2 = i18n.getString("org.codehaus.plexus.i18n.BarBundle", new Locale("ko", "KR"), "key3"); - assertEquals( "Unable to retrieve localized text for locale: ko-KR", s2, "[ko] value3" ); + assertEquals("Unable to retrieve localized text for locale: ko-KR", s2, "[ko] value3"); - String s3 = i18n.getString( "org.codehaus.plexus.i18n.BarBundle", new Locale( "ja" ), "key1" ); + String s3 = i18n.getString("org.codehaus.plexus.i18n.BarBundle", new Locale("ja"), "key1"); - assertEquals( "Unable to fall back from non-existant locale: jp", "[] value1", s3 ); + assertEquals("Unable to fall back from non-existant locale: jp", "[] value1", s3); - String s4 = i18n.getString( "org.codehaus.plexus.i18n.FooBundle", new Locale( "fr" ), "key3" ); + String s4 = i18n.getString("org.codehaus.plexus.i18n.FooBundle", new Locale("fr"), "key3"); - assertEquals( "Unable to retrieve localized text for locale: fr", s4, "[fr] value3" ); + assertEquals("Unable to retrieve localized text for locale: fr", s4, "[fr] value3"); - String s5 = i18n.getString( "org.codehaus.plexus.i18n.FooBundle", new Locale( "fr", "FR" ), "key3" ); + String s5 = i18n.getString("org.codehaus.plexus.i18n.FooBundle", new Locale("fr", "FR"), "key3"); - assertEquals( "Unable to retrieve localized text for locale: fr-FR", s5, "[fr] value3" ); + assertEquals("Unable to retrieve localized text for locale: fr-FR", s5, "[fr] value3"); - String s6 = i18n.getString( "org.codehaus.plexus.i18n.i18n", null, "key1" ); + String s6 = i18n.getString("org.codehaus.plexus.i18n.i18n", null, "key1"); - assertEquals( "Unable to retrieve localized properties for locale: default", "[] value1", s6 ); + assertEquals("Unable to retrieve localized properties for locale: default", "[] value1", s6); Locale old = Locale.getDefault(); Locale.setDefault(Locale.FRENCH); - try - { - String s7 = i18n.getString( "org.codehaus.plexus.i18n.i18n", Locale.ENGLISH, "key1" ); + try { + String s7 = i18n.getString("org.codehaus.plexus.i18n.i18n", Locale.ENGLISH, "key1"); - assertEquals( "Not picking up new default locale: fr", "[fr] value1", s7 ); + assertEquals("Not picking up new default locale: fr", "[fr] value1", s7); - String s8 = i18n.getString( "org.codehaus.plexus.i18n.i18n", Locale.ITALIAN, "key1" ); + String s8 = i18n.getString("org.codehaus.plexus.i18n.i18n", Locale.ITALIAN, "key1"); - assertEquals( "Unable to retrieve localized properties for locale: it", "[it] value1", s8 ); + assertEquals("Unable to retrieve localized properties for locale: it", "[it] value1", s8); } finally { Locale.setDefault(old); } } - public void testLocalizedMessagesWithFormatting() - { + public void testLocalizedMessagesWithFormatting() { // Format methods - String s6 = i18n.format( "org.codehaus.plexus.i18n.i18n", null, "thanks.message", "jason" ); + String s6 = i18n.format("org.codehaus.plexus.i18n.i18n", null, "thanks.message", "jason"); - assertEquals( s6, "Thanks jason!" ); + assertEquals(s6, "Thanks jason!"); - String s7 = i18n.format( "org.codehaus.plexus.i18n.i18n", null, "thanks.message1", "jason", "van zyl" ); + String s7 = i18n.format("org.codehaus.plexus.i18n.i18n", null, "thanks.message1", "jason", "van zyl"); - assertEquals( s7, "Thanks jason van zyl!" ); + assertEquals(s7, "Thanks jason van zyl!"); - String s8 = i18n.format( "org.codehaus.plexus.i18n.i18n", null, "thanks.message2", new Object[]{ "jason", "van zyl" } ); + String s8 = i18n.format( + "org.codehaus.plexus.i18n.i18n", null, "thanks.message2", new Object[] {"jason", "van zyl"}); - assertEquals( s8, "Thanks jason van zyl!" ); + assertEquals(s8, "Thanks jason van zyl!"); } - public void testLocalizedMessagesWithNonStandardLocale() - { - String s0 = i18n.getString( "name", new Locale( "xx" ) ); + public void testLocalizedMessagesWithNonStandardLocale() { + String s0 = i18n.getString("name", new Locale("xx")); - assertEquals( "plexus", s0 ); + assertEquals("plexus", s0); } } diff --git a/src/test/java/org/codehaus/plexus/i18n/FooBundle_en.java b/src/test/java/org/codehaus/plexus/i18n/FooBundle_en.java index 342fc05..2b7280c 100644 --- a/src/test/java/org/codehaus/plexus/i18n/FooBundle_en.java +++ b/src/test/java/org/codehaus/plexus/i18n/FooBundle_en.java @@ -21,18 +21,15 @@ /** * An english resource bundle for use in testing. */ -public class FooBundle_en extends ListResourceBundle -{ - private static final Object[][] CONTENTS = - { - { "key1", "[en] value1" }, - { "key2", "[en] value2" }, - { "key3", "[en] value3" }, - { "key4", "[en] value4" } +public class FooBundle_en extends ListResourceBundle { + private static final Object[][] CONTENTS = { + {"key1", "[en] value1"}, + {"key2", "[en] value2"}, + {"key3", "[en] value3"}, + {"key4", "[en] value4"} }; - - protected Object[][] getContents() - { + + protected Object[][] getContents() { return CONTENTS; } } diff --git a/src/test/java/org/codehaus/plexus/i18n/FooBundle_fr.java b/src/test/java/org/codehaus/plexus/i18n/FooBundle_fr.java index 292f17c..d5b1c83 100644 --- a/src/test/java/org/codehaus/plexus/i18n/FooBundle_fr.java +++ b/src/test/java/org/codehaus/plexus/i18n/FooBundle_fr.java @@ -21,18 +21,15 @@ /** * A dummied up French resource bundle for use in testing. */ -public class FooBundle_fr extends ListResourceBundle -{ - private static final Object[][] CONTENTS = - { - { "key1", "[fr] value1" }, - { "key2", "[fr] value2" }, - { "key3", "[fr] value3" }, - { "key4", "[fr] value4" } +public class FooBundle_fr extends ListResourceBundle { + private static final Object[][] CONTENTS = { + {"key1", "[fr] value1"}, + {"key2", "[fr] value2"}, + {"key3", "[fr] value3"}, + {"key4", "[fr] value4"} }; - - protected Object[][] getContents() - { + + protected Object[][] getContents() { return CONTENTS; } } diff --git a/src/test/java/org/codehaus/plexus/i18n/I18NTokenizerTest.java b/src/test/java/org/codehaus/plexus/i18n/I18NTokenizerTest.java index 07ecb4f..016a4b1 100644 --- a/src/test/java/org/codehaus/plexus/i18n/I18NTokenizerTest.java +++ b/src/test/java/org/codehaus/plexus/i18n/I18NTokenizerTest.java @@ -67,38 +67,27 @@ * @author Jason van Zyl * @version $Id: I18NTokenizerTest.java 831 2004-06-16 17:01:12Z jvanzyl $ */ -public class I18NTokenizerTest - extends TestCase -{ +public class I18NTokenizerTest extends TestCase { private static final String HEADER = "en, es;q=0.8, zh-TW;q=0.1"; - public I18NTokenizerTest( String name ) - { - super( name ); + public I18NTokenizerTest(String name) { + super(name); } - public static Test suite() - { - return new TestSuite( I18NTokenizerTest.class ); + public static Test suite() { + return new TestSuite(I18NTokenizerTest.class); } - public void testLocaleTokenizer() - { - try - { - I18NTokenizer tok = new I18NTokenizer( HEADER ); + public void testLocaleTokenizer() { + try { + I18NTokenizer tok = new I18NTokenizer(HEADER); Locale locale = (Locale) tok.next(); - assertEquals( "Either wrong language or order parsing: " + locale, - locale.getLanguage(), "en" ); + assertEquals("Either wrong language or order parsing: " + locale, locale.getLanguage(), "en"); locale = (Locale) tok.next(); - assertEquals( "Either wrong language or order parsing: " + locale, - locale.getLanguage(), "es" ); + assertEquals("Either wrong language or order parsing: " + locale, locale.getLanguage(), "es"); locale = (Locale) tok.next(); - assertEquals( "Either wrong country or order parsing: " + locale, - locale.getCountry(), "TW" ); - } - catch ( Exception e ) - { + assertEquals("Either wrong country or order parsing: " + locale, locale.getCountry(), "TW"); + } catch (Exception e) { e.printStackTrace(); fail(); }