Author: julien(a)jboss.com
Date: 2008-01-09 19:22:06 -0500 (Wed, 09 Jan 2008)
New Revision: 9470
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/AbstractLocaleFormat.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/BundleName.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/CachingLocaleFormat.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/DefaultLocaleFormat.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/LocaleFormat.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/MapResourceBundle.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/ResourceBundleManager.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameIteratorTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocaleFormatTestCase.java
Log:
improvements of i18n stuff
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/AbstractLocaleFormat.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/AbstractLocaleFormat.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/AbstractLocaleFormat.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -25,10 +25,10 @@
import org.jboss.portal.common.io.UndeclaredIOException;
import org.jboss.portal.common.util.ConversionException;
import org.jboss.portal.common.util.NullConversionException;
+import org.jboss.portal.common.text.CharBuffer;
+import org.jboss.portal.common.text.CharWriter;
import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
import java.util.Locale;
/**
@@ -56,7 +56,7 @@
return internalToString(locale);
}
- public void write(Locale locale, Writer writer) throws IOException,
ConversionException
+ public void write(Locale locale, CharWriter writer) throws IOException,
ConversionException
{
if (locale == null)
{
@@ -75,9 +75,9 @@
{
try
{
- StringWriter writer = new StringWriter();
- internalWrite(locale, writer);
- return writer.toString();
+ CharBuffer buffer = new CharBuffer();
+ internalWrite(locale, buffer);
+ return buffer.asString();
}
catch (IOException e)
{
@@ -85,6 +85,6 @@
}
}
- protected abstract void internalWrite(Locale locale, Writer writer) throws
IOException, ConversionException;
+ protected abstract void internalWrite(Locale locale, CharWriter writer) throws
IOException, ConversionException;
}
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/BundleName.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/BundleName.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/BundleName.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -22,8 +22,12 @@
******************************************************************************/
package org.jboss.portal.common.i18n;
+import org.jboss.portal.common.text.CharBuffer;
+import org.jboss.portal.common.util.ConversionException;
+
import java.util.Locale;
import java.util.NoSuchElementException;
+import java.io.IOException;
/**
* The immutable name of a bundle.
@@ -68,92 +72,113 @@
throw new IllegalArgumentException();
}
this.baseName = baseName;
- this.language = language;
- this.country = country;
- this.variant = variant;
+ this.locale = new Locale(language, country, variant);
}
/** . */
private final String baseName;
- /** Lower-case two-letter codes as defined by ISO-639. */
- private final String language;
-
- /** Upper-case two-letter codes as defined by ISO-3166. */
- private final String country;
-
/** . */
- private final String variant;
+ private final Locale locale;
public String getBaseName()
{
return baseName;
}
+ public Locale getLocale()
+ {
+ return locale;
+ }
+
public String getLanguage()
{
- return language;
+ return locale.getLanguage();
}
public String getCountry()
{
- return country;
+ return locale.getCountry();
}
public String getVariant()
{
- return variant;
+ return locale.getVariant();
}
- public static class Iterator implements java.util.Iterator
+ public String toString()
{
+ if (locale.getLanguage().length() == 0 && locale.getCountry().length() ==
0)
+ {
+ return baseName;
+ }
+ else
+ {
+ CharBuffer buffer = new CharBuffer(baseName.length() + 15);
+ buffer.append(baseName);
- /** . */
- private final String language;
+ //
+ buffer.append('_');
- /** . */
- private final String country;
+ //
+ try
+ {
+ LocaleFormat.DEFAULT.write(locale, buffer);
+ }
+ catch (IOException e)
+ {
+ throw new AssertionError(e);
+ }
+ catch (ConversionException e)
+ {
+ throw new AssertionError(e);
+ }
- /** . */
- private final String variant;
+ //
+ return buffer.asString();
+ }
+ }
+ public static class Iterator implements java.util.Iterator<BundleName>
+ {
+
/** . */
- private String name;
+ private BundleName name;
/** . */
private int status;
public Iterator(String baseName, Locale locale)
{
- language = locale.getLanguage();
- country = locale.getCountry();
- variant = locale.getVariant();
+ String language = locale.getLanguage();
+ String country = locale.getCountry();
+ String variant = locale.getVariant();
status = 8 + (language.length() > 0 ? 4 : 0) + (country.length() > 0 ? 2 :
0) + (variant.length() > 0 ? 1 : 0);
switch (status & 0x7)
{
case 0:
- name = baseName;
+ name = new BundleName(baseName);
break;
case 1:
- name = baseName + "___" + variant;
+ name = new BundleName(baseName, "", "", variant);
break;
case 2:
- name = baseName + "__" + country;
+ name = new BundleName(baseName, "", variant, "");
break;
case 3:
- name = baseName + "__" + country + "_" + variant;
+ name = new BundleName(baseName, "", country, variant);
break;
case 4:
- name = baseName + "_" + language;
+ name = new BundleName(baseName, language, "", "");
break;
case 5:
- name = baseName + "_" + language + "__" + variant;
+ name = new BundleName(baseName, language, "", variant);
break;
case 6:
- name = baseName + "_" + language + "_" + country;
+ name = new BundleName(baseName, language, country, "");
break;
case 7:
- name = baseName + "_" + language + "_" + country +
"_" + variant;
+ name = new BundleName(baseName, language, country, variant);
break;
default:
throw new AssertionError("Should not be here");
@@ -165,7 +190,7 @@
return status != 0;
}
- public Object next()
+ public BundleName next()
{
if (status >= 8)
{
@@ -178,31 +203,31 @@
case 0:
throw new NoSuchElementException();
case 1:
- name = name.substring(0, name.length() - 3 - variant.length());
+ name = new BundleName(name.getBaseName());
status = 0;
break;
case 2:
- name = name.substring(0, name.length() - 2 - country.length());
+ name = new BundleName(name.getBaseName());
status = 0;
break;
case 3:
- name = name.substring(0, name.length() - 1 - variant.length());
+ name = new BundleName(name.getBaseName(), "",
name.getCountry());
status = 2;
break;
case 4:
- name = name.substring(0, name.length() - 1 - language.length());
+ name = new BundleName(name.getBaseName());
status = 0;
break;
case 5:
- name = name.substring(0, name.length() - 2 - variant.length());
+ name = new BundleName(name.getBaseName(), name.getLanguage());
status = 4;
break;
case 6:
- name = name.substring(0, name.length() - 1 - country.length());
+ name = new BundleName(name.getBaseName(), name.getLanguage());
status = 4;
break;
case 7:
- name = name.substring(0, name.length() - 1 - variant.length());
+ name = new BundleName(name.getBaseName(), name.getLanguage(),
name.getCountry());
status = 6;
break;
default:
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/CachingLocaleFormat.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/CachingLocaleFormat.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/CachingLocaleFormat.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -24,9 +24,9 @@
import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
import org.jboss.portal.common.util.ConversionException;
+import org.jboss.portal.common.text.CharWriter;
import java.io.IOException;
-import java.io.Writer;
import java.util.Locale;
/**
@@ -98,7 +98,7 @@
return string;
}
- public void write(Locale locale, Writer writer) throws IOException,
ConversionException
+ public void write(Locale locale, CharWriter writer) throws IOException,
ConversionException
{
delegate.write(locale, writer);
}
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -59,7 +59,7 @@
//
for (BundleName.Iterator iterator = new BundleName.Iterator(baseName, locale);
iterator.hasNext();)
{
- String name = (String)iterator.next();
+ BundleName name = iterator.next();
// We don't want to process the base name only with the specified locale
// in order to respect the sequence of candidate bundle names
@@ -69,7 +69,7 @@
}
//
- ResourceBundle bundle = lookup(name);
+ ResourceBundle bundle = lookup(name.toString());
if (bundle != null)
{
return bundle;
@@ -79,10 +79,10 @@
// Try default locale
for (BundleName.Iterator iterator = new BundleName.Iterator(baseName,
Locale.getDefault()); iterator.hasNext();)
{
- String name = (String)iterator.next();
+ BundleName name = iterator.next();
//
- ResourceBundle bundle = lookup(name);
+ ResourceBundle bundle = lookup(name.toString());
if (bundle != null)
{
return bundle;
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/DefaultLocaleFormat.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/DefaultLocaleFormat.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/DefaultLocaleFormat.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -23,9 +23,9 @@
package org.jboss.portal.common.i18n;
import org.jboss.portal.common.util.FormatConversionException;
+import org.jboss.portal.common.text.CharWriter;
import java.io.IOException;
-import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
@@ -113,8 +113,8 @@
return factory.createLocale(value.substring(0, p2), b, a);
}
- protected void internalWrite(Locale locale, Writer writer) throws IOException
+ protected void internalWrite(Locale locale, CharWriter writer) throws IOException
{
- writer.write(locale.toString());
+ writer.append(locale.toString());
}
}
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/LocaleFormat.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/LocaleFormat.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/LocaleFormat.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -23,9 +23,9 @@
package org.jboss.portal.common.i18n;
import org.jboss.portal.common.util.ConversionException;
+import org.jboss.portal.common.text.CharWriter;
import java.io.IOException;
-import java.io.Writer;
import java.util.Locale;
/**
@@ -51,6 +51,6 @@
String toString(Locale locale) throws ConversionException;
- void write(Locale locale, Writer writer) throws IOException, ConversionException;
+ void write(Locale locale, CharWriter writer) throws IOException, ConversionException;
}
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/MapResourceBundle.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/MapResourceBundle.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/MapResourceBundle.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -37,11 +37,11 @@
public class MapResourceBundle extends ResourceBundle
{
- protected Map content;
+ protected Map<String, Object> content;
- public MapResourceBundle(Map content)
+ public MapResourceBundle(Map<String, Object> content)
{
- this.content = new HashMap(content);
+ this.content = new HashMap<String, Object>(content);
}
protected Object handleGetObject(String key)
@@ -53,7 +53,7 @@
return content.get(key);
}
- public Enumeration getKeys()
+ public Enumeration<String> getKeys()
{
return Collections.enumeration(content.keySet());
}
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -23,9 +23,9 @@
package org.jboss.portal.common.i18n;
import org.jboss.portal.common.util.FormatConversionException;
+import org.jboss.portal.common.text.CharWriter;
import java.io.IOException;
-import java.io.Writer;
import java.util.Arrays;
import java.util.Locale;
import java.util.regex.Matcher;
@@ -83,22 +83,23 @@
* English, "en-GB" for British English, etc.
*
* @param locale the locale which language tag is wanted
+ * @param writer
* @return a <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC
3066</a>-compatible language tag.
* @throws IllegalArgumentException if the given locale is not valid
* @since 2.4
*/
- protected void internalWrite(Locale locale, Writer writer) throws IOException
+ protected void internalWrite(Locale locale, CharWriter writer) throws IOException
{
String country = locale.getCountry(); // country will be empty if no country was
specified in the locale
- writer.write(locale.getLanguage());
+ writer.append(locale.getLanguage());
if (country.length() == 2)
{
- writer.write(RFC3066_SEPARATOR);
- writer.write(country);
+ writer.append(RFC3066_SEPARATOR);
+ writer.append(country);
}
else
{
- writer.write(country);
+ writer.append(country);
}
}
}
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/ResourceBundleManager.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/ResourceBundleManager.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/i18n/ResourceBundleManager.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -25,15 +25,16 @@
import org.apache.log4j.Logger;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
/**
- * <p>Manage a set of resource bundles. Obtaining bundles is done using a
ResourceBundleFactory object. A bundle
- * obtained successfully is cached in order to avoid the potential expensive cost of
bundle retrieval.</p>
+ * <p>Manage a set of resource bundles. Obtention of bundles is delegated to a
ResourceBundleFactory. A bundle
+ * obtained successfully is cached in order to avoid the potential expensive cost of the
bundle retrieval.</p>
* <p/>
* <p>The manager can also be used to build LocalizedString object from the loaded
bundles.</p>
*
@@ -45,16 +46,16 @@
{
/** . */
- private Logger log = Logger.getLogger(getClass());
+ private final Logger log = Logger.getLogger(getClass());
/** . */
- private volatile Map localeBundles;
+ private final ConcurrentMap<Locale, BundleRef> localeBundles;
/** . */
- private ResourceBundle defaultBundle;
+ private final ResourceBundle defaultBundle;
/** . */
- private ResourceBundleFactory resourceBundleFactory;
+ private final ResourceBundleFactory resourceBundleFactory;
/**
* @param defaultBundle the default bundle returned when no bundle has been
obtained for the locale
@@ -67,7 +68,7 @@
{
throw new IllegalArgumentException("Need a resource bundle factory");
}
- this.localeBundles = new HashMap();
+ this.localeBundles = new ConcurrentHashMap<Locale, BundleRef>();
this.defaultBundle = defaultBundle;
this.resourceBundleFactory = resourceBundleFactory;
}
@@ -93,28 +94,40 @@
{
throw new IllegalArgumentException("No null default value accepted");
}
- Map m = new HashMap();
- for (Iterator j = localeBundles.entrySet().iterator(); j.hasNext();)
+
+ //
+ Map<Locale, String> m = new HashMap<Locale, String>();
+ for (Map.Entry<Locale, BundleRef> entry : localeBundles.entrySet())
{
- Map.Entry entry = (Map.Entry)j.next();
try
{
- Locale locale = (Locale)entry.getKey();
- ResourceBundle bundle = (ResourceBundle)entry.getValue();
- String localizedDisplayName = bundle.getString(key);
- m.put(locale, localizedDisplayName);
+ Locale locale = entry.getKey();
+ ResourceBundle container = entry.getValue().bundle;
+
+ //
+ if (container != null)
+ {
+ String localizedDisplayName = container.getString(key);
+ m.put(locale, localizedDisplayName);
+ }
}
catch (MissingResourceException ignore)
{
}
}
+
+ // Always need default value
if (!m.containsKey(Locale.ENGLISH))
{
m.put(Locale.ENGLISH, defaultValue);
}
+
+ //
return new LocalizedString(m, Locale.ENGLISH);
}
+
+
/**
* Return a bundle for the given locale. If the complete locale (language + country +
variant) does not exist then it
* falls back to (language + country) or (language) or the default file.
@@ -122,6 +135,8 @@
* When the resource bundle object is found and was not in the global map, it put it
in that map with a copy on
* write.
*
+ * @param locale the locale we want a bundle for
+ * @return a bundle for the locale or null if not suitable bundle is found.
* @throws IllegalArgumentException if the locale is null
*/
public ResourceBundle getResourceBundle(Locale locale) throws
IllegalArgumentException
@@ -133,20 +148,20 @@
}
// Try to get the bundle if the map
- ResourceBundle bundle = (ResourceBundle)localeBundles.get(locale);
- if (bundle != null)
+ BundleRef ref = localeBundles.get(locale);
+ if (ref != null)
{
- return bundle;
+ return ref.bundle;
}
//
log.debug("Want to load bundle for locale " + locale);
- bundle = resourceBundleFactory.getBundle(locale);
+ ResourceBundle bundle = resourceBundleFactory.getBundle(locale);
//
if (bundle != null)
{
- log.debug("Obtained bundle " + bundle + " for locale " +
locale);
+ log.debug("Obtained bundle " + bundle + " with locale " +
bundle.getLocale() + " for locale " + locale);
}
else
{
@@ -154,11 +169,24 @@
}
// Cache the bundle
- Map copy = new HashMap(localeBundles);
- copy.put(locale, bundle);
- localeBundles = copy;
+ localeBundles.put(locale, new BundleRef(bundle));
//
return bundle;
}
+
+ /**
+ * Keeps track of what we loaded, even null.
+ */
+ private static class BundleRef
+ {
+
+ /** . */
+ final ResourceBundle bundle;
+
+ private BundleRef(ResourceBundle bundle)
+ {
+ this.bundle = bundle;
+ }
+ }
}
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameIteratorTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameIteratorTestCase.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/BundleNameIteratorTestCase.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -45,13 +45,13 @@
Locale l = new Locale("a", "b", "c");
BundleName.Iterator iterator = new BundleName.Iterator("base", l);
assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "_" + B + "_" + C,
iterator.next());
+ assertEquals("base_" + A + "_" + B + "_" + C,
iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "_" + B, iterator.next());
+ assertEquals("base_" + A + "_" + B,
iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
+ assertEquals("base_" + A, iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
+ assertEquals("base", iterator.next().toString());
assertFalse(iterator.hasNext());
try
{
@@ -68,11 +68,11 @@
Locale l = new Locale("a", "b");
BundleName.Iterator iterator = new BundleName.Iterator("base", l);
assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "_" + B, iterator.next());
+ assertEquals("base_" + A + "_" + B,
iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
+ assertEquals("base_" + A, iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
+ assertEquals("base", iterator.next().toString());
assertFalse(iterator.hasNext());
try
{
@@ -89,11 +89,11 @@
Locale l = new Locale("a", "b", "");
BundleName.Iterator iterator = new BundleName.Iterator("base", l);
assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "_" + B, iterator.next());
+ assertEquals("base_" + A + "_" + B,
iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
+ assertEquals("base_" + A, iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
+ assertEquals("base", iterator.next().toString());
assertFalse(iterator.hasNext());
try
{
@@ -110,9 +110,9 @@
Locale l = new Locale("a");
BundleName.Iterator iterator = new BundleName.Iterator("base", l);
assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
+ assertEquals("base_" + A, iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
+ assertEquals("base", iterator.next().toString());
assertFalse(iterator.hasNext());
try
{
@@ -129,9 +129,9 @@
Locale l = new Locale("a", "", "");
BundleName.Iterator iterator = new BundleName.Iterator("base", l);
assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
+ assertEquals("base_" + A, iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
+ assertEquals("base", iterator.next().toString());
assertFalse(iterator.hasNext());
try
{
@@ -148,11 +148,11 @@
Locale l = new Locale("a", "", "c");
BundleName.Iterator iterator = new BundleName.Iterator("base", l);
assertTrue(iterator.hasNext());
- assertEquals("base_" + A + "__" + C, iterator.next());
+ assertEquals("base_" + A + "__" + C,
iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base_" + A, iterator.next());
+ assertEquals("base_" + A, iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
+ assertEquals("base", iterator.next().toString());
assertFalse(iterator.hasNext());
try
{
@@ -169,11 +169,11 @@
Locale l = new Locale("", "b", "c");
BundleName.Iterator iterator = new BundleName.Iterator("base", l);
assertTrue(iterator.hasNext());
- assertEquals("base__" + B + "_" + C, iterator.next());
+ assertEquals("base__" + B + "_" + C,
iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base__" + B, iterator.next());
+ assertEquals("base__" + B, iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
+ assertEquals("base", iterator.next().toString());
assertFalse(iterator.hasNext());
try
{
@@ -190,9 +190,9 @@
Locale l = new Locale("", "", "c");
BundleName.Iterator iterator = new BundleName.Iterator("base", l);
assertTrue(iterator.hasNext());
- assertEquals("base___" + C, iterator.next());
+ assertEquals("base", iterator.next().toString());
assertTrue(iterator.hasNext());
- assertEquals("base", iterator.next());
+ assertEquals("base", iterator.next().toString());
assertFalse(iterator.hasNext());
try
{
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocaleFormatTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocaleFormatTestCase.java 2008-01-09
23:25:22 UTC (rev 9469)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/i18n/LocaleFormatTestCase.java 2008-01-10
00:22:06 UTC (rev 9470)
@@ -27,7 +27,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
-import java.io.Writer;
import java.io.IOException;
import org.jboss.portal.common.i18n.LocaleFormat;
@@ -35,6 +34,7 @@
import org.jboss.portal.common.i18n.AbstractLocaleFormat;
import org.jboss.portal.common.util.FormatConversionException;
import org.jboss.portal.common.util.ConversionException;
+import org.jboss.portal.common.text.CharWriter;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -203,14 +203,14 @@
return locale;
}
- protected void internalWrite(Locale locale, Writer writer) throws IOException,
ConversionException
+ protected void internalWrite(Locale locale, CharWriter writer) throws IOException,
ConversionException
{
String string = (String)localeToString.get(locale);
if (string == null)
{
throw new ConversionException();
}
- writer.write(string);
+ writer.append(string);
}
}