Author: julien(a)jboss.com
Date: 2007-05-06 12:33:54 -0400 (Sun, 06 May 2007)
New Revision: 7200
Added:
trunk/common/src/main/org/jboss/portal/common/i18n/DefaultLocaleFormat.java
trunk/common/src/main/org/jboss/portal/common/i18n/I18NTools.java
trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFactory.java
trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFormat.java
trunk/common/src/main/org/jboss/portal/common/i18n/LocaleManager.java
trunk/common/src/main/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java
trunk/common/src/main/org/jboss/portal/common/util/ConversionException.java
trunk/common/src/main/org/jboss/portal/common/util/FormatConversionException.java
trunk/common/src/main/org/jboss/portal/common/util/NullConversionException.java
trunk/common/src/main/org/jboss/portal/test/common/LocaleFormatTestCase.java
Removed:
trunk/common/src/main/org/jboss/portal/common/i18n/LocaleInfo.java
trunk/common/src/main/org/jboss/portal/common/value/ConversionException.java
trunk/common/src/main/org/jboss/portal/common/value/FormatConversionException.java
trunk/common/src/main/org/jboss/portal/common/value/NullConversionException.java
trunk/common/src/main/org/jboss/portal/test/common/LocaleInfoTestCase.java
Modified:
trunk/common/build.xml
trunk/common/src/main/org/jboss/portal/common/i18n/BundleName.java
trunk/common/src/main/org/jboss/portal/common/i18n/LocalizedString.java
trunk/common/src/main/org/jboss/portal/common/value/Converter.java
trunk/common/src/main/org/jboss/portal/common/value/Helper.java
trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaDataFactory.java
trunk/portlet/src/main/org/jboss/portal/portlet/deployment/PortletApplicationMetaDataFactory.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/portlet/info/WSRPPortletInfo.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupRequest.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerConfigurationFactory.java
Log:
- removed obsolete LocaleInfo class
- moved locale conversion methods which are useful and used to new LocaleFormat class
which alllow conversion of Locale to a string format back and forth
- updated test cases accordingly
- moved ConversionException class to o.j.p.common.util so it can be reused more easily in
various packages
Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml 2007-05-05 21:55:31 UTC (rev 7199)
+++ trunk/common/build.xml 2007-05-06 16:33:54 UTC (rev 7200)
@@ -221,7 +221,7 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.common.test.TestParametrizationTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.FastURLEncoderTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.AbstractInvocationContextTestCase"/>
- <test todir="${test.reports}"
name="org.jboss.portal.test.common.LocaleInfoTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.common.LocaleFormatTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.ParentChildResourceBundleTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.ValveTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.ValueTestCase"/>
Modified: trunk/common/src/main/org/jboss/portal/common/i18n/BundleName.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/BundleName.java 2007-05-05 21:55:31
UTC (rev 7199)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/BundleName.java 2007-05-06 16:33:54
UTC (rev 7200)
@@ -238,15 +238,15 @@
}
if (from < 0)
{
-
+ throw new IllegalArgumentException();
}
if (to < s.length())
{
-
+ throw new IllegalArgumentException();
}
if (to < from)
{
-
+ throw new IllegalArgumentException();
}
//
Added: trunk/common/src/main/org/jboss/portal/common/i18n/DefaultLocaleFormat.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/DefaultLocaleFormat.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/DefaultLocaleFormat.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -0,0 +1,96 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.i18n;
+
+import org.jboss.portal.common.util.FormatConversionException;
+
+import java.util.Locale;
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * Implementation for the programmatic name of a locale.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+class DefaultLocaleFormat extends LocaleFormat
+{
+
+ /** . */
+ private LocaleFactory factory;
+
+ public DefaultLocaleFormat(LocaleFactory factory)
+ {
+ this.factory = factory;
+ }
+
+ public DefaultLocaleFormat()
+ {
+ this(LocaleFactory.DEFAULT_FACTORY);
+ }
+
+ protected Locale internalGetLocale(String value) throws FormatConversionException
+ {
+ int p1 = value.lastIndexOf('_');
+ if (p1 < 0)
+ {
+ return factory.createLocale(value);
+ }
+
+ //
+ String a = (p1 == (value.length() - 1)) ? "" : value.substring(p1 + 1,
value.length());
+
+ //
+ int p2 = value.lastIndexOf('_', p1 - 1);
+ if (p2 < 0)
+ {
+ if (a.length() == 0)
+ {
+ throw new FormatConversionException();
+ }
+ else
+ {
+ return factory.createLocale(value.substring(0, p1), a);
+ }
+ }
+
+ //
+ boolean emptyLanguage = p2 == p1 - 1;
+ if (p2 == 0 && emptyLanguage)
+ {
+ throw new FormatConversionException();
+ }
+
+ //
+ String b = emptyLanguage ? "" : value.substring(p2 + 1, p1);
+
+ //
+ return factory.createLocale(value.substring(0, p2), b, a);
+ }
+
+ protected void internalWrite(Locale locale, Writer writer) throws IOException
+ {
+ writer.write(locale.toString());
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/common/i18n/I18NTools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/I18NTools.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/I18NTools.java 2007-05-06 16:33:54
UTC (rev 7200)
@@ -0,0 +1,87 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.i18n;
+
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class I18NTools
+{
+
+ /**
+ * Separator.
+ */
+ private static final String RFC3066_SEPARATOR = "-";
+
+ /**
+ * Retrieves the language identification tag associated to the specified Locale as
defined by
+ * <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC
3066</a> limited to 2-letter
+ * language code per ISO standard 639, a "-" (dash) and a 2-letter country
code per
+ * ISO 3166 alpha-2 country codes. E.g. "en-US" for American English,
"en-GB" for
+ * British English, etc.
+ *
+ * @param locale the locale which language tag is wanted
+ * @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
+ */
+ public static String getRFC3066LanguageTagFor(Locale locale)
+ {
+ String country = locale.getCountry(); // country will be empty if no country was
specified in the locale
+ return locale.getLanguage() + ((country.length() == 2) ? RFC3066_SEPARATOR +
country : country);
+ }
+
+ /**
+ * Compute the trailing name for a given locale.
+ *
+ * @param locale the locale
+ * @return the trailing name
+ * @throws IllegalArgumentException if locale is null
+ */
+ public static String computeTrailingName(Locale locale) throws
IllegalArgumentException
+ {
+ if (locale == null)
+ {
+ throw new IllegalArgumentException("locale parameter is null");
+ }
+ StringBuffer tmp = new StringBuffer();
+ if (locale.getLanguage() != null && locale.getLanguage().length() > 0)
+ {
+ tmp.append('_').append(locale.getLanguage());
+ if (locale.getCountry() != null && locale.getCountry().length() > 0)
+ {
+ tmp.append('_').append(locale.getCountry());
+ {
+ if (locale.getVariant() != null && locale.getVariant().length()
> 0)
+ {
+ tmp.append('_').append(locale.getVariant());
+ }
+ }
+ }
+ }
+ return tmp.toString();
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFactory.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFactory.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFactory.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.i18n;
+
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface LocaleFactory
+{
+
+ LocaleFactory DEFAULT_FACTORY = new LocaleFactory()
+ {
+ public Locale createLocale(String language)
+ {
+ return new Locale(language);
+ }
+
+ public Locale createLocale(String language, String country)
+ {
+ return new Locale(language, country);
+ }
+
+ public Locale createLocale(String language, String country, String variant)
+ {
+ return new Locale(language, country, variant);
+ }
+ };
+
+ Locale createLocale(String language);
+
+ Locale createLocale(String language, String country);
+
+ Locale createLocale(String language, String country, String variant);
+
+}
Added: trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFormat.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFormat.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFormat.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -0,0 +1,96 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.i18n;
+
+import org.jboss.portal.common.io.UndeclaredIOException;
+import org.jboss.portal.common.util.ConversionException;
+import org.jboss.portal.common.util.NullConversionException;
+
+import java.util.Locale;
+import java.io.Writer;
+import java.io.IOException;
+import java.io.StringWriter;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LocaleFormat
+{
+
+ /** . */
+ public static final LocaleFormat RFC3066_LANGUAGE_TAG = new
RFC3066LanguageTagLocaleFormat();
+
+ /** . */
+ public static final LocaleFormat DEFAULT = new DefaultLocaleFormat();
+
+ public Locale getLocale(String value) throws ConversionException
+ {
+ if (value == null)
+ {
+ throw new NullConversionException("No null locale value accepted");
+ }
+ return internalGetLocale(value);
+ }
+
+ public String toString(Locale locale) throws ConversionException
+ {
+ if (locale == null)
+ {
+ throw new NullConversionException("No null locale accepted");
+ }
+ return internalToString(locale);
+ }
+
+ public void write(Locale locale, Writer writer) throws IOException,
ConversionException
+ {
+ if (locale == null)
+ {
+ throw new NullConversionException("No null locale accepted");
+ }
+ if (writer == null)
+ {
+ throw new IllegalArgumentException("No null writer accepted");
+ }
+ internalWrite(locale, writer);
+ }
+
+ protected abstract Locale internalGetLocale(String value) throws ConversionException;
+
+ protected String internalToString(Locale locale) throws ConversionException
+ {
+ try
+ {
+ StringWriter writer = new StringWriter();
+ internalWrite(locale, writer);
+ return writer.toString();
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
+ }
+
+ protected abstract void internalWrite(Locale locale, Writer writer) throws
IOException, ConversionException;
+
+}
Deleted: trunk/common/src/main/org/jboss/portal/common/i18n/LocaleInfo.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/LocaleInfo.java 2007-05-05 21:55:31
UTC (rev 7199)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/LocaleInfo.java 2007-05-06 16:33:54
UTC (rev 7200)
@@ -1,460 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.common.i18n;
-
-import org.apache.log4j.Logger;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Additional infos about a locale.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- * @noinspection ALL
- */
-public final class LocaleInfo
-{
-
- // Static fields
****************************************************************************************************
-
- /**
- * The logger.
- */
- private static Logger log = Logger.getLogger(LocaleInfo.class);
-
- /**
- * The locale info map.
- */
- private static volatile Infos sharedInfos = createFromAvailableLocales();
-
- /**
- * Separator.
- */
- private static final String RFC3066_SEPARATOR = "-";
-
- /**
- * Valid language tag matcher (see <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC 3066</a>).
- */
- private static final Pattern RFC3066_COMPOUND_LANG_PATTERN =
Pattern.compile("(\\p{Lower}{2})(-(\\p{Upper}{2}))?");
-
- /**
- * Sorted valid ISO country codes (needed for Arrays.binarySearch).
- */
- private static final String[] SORTED_ISO_COUNTRIES = Locale.getISOCountries();
-
- /**
- * Sorted valid ISO language codes (needed for Arrays.binarySearch).
- */
- private static final String[] SORTED_ISO_LANGUAGES = Locale.getISOLanguages();
-
- private static final Comparator c = new Comparator()
- {
- public int compare(Object o1, Object o2)
- {
- String s1 = ((LocaleInfo)o1).getTrailingName();
- String s2 = ((LocaleInfo)o2).getTrailingName();
- return s1.compareTo(s2);
- }
- };
-
-
- static
- {
- // should already be sorted but in case they're not...
- Arrays.sort(SORTED_ISO_COUNTRIES);
- Arrays.sort(SORTED_ISO_LANGUAGES);
- }
-
- // Fields
***********************************************************************************************************
-
- /**
- * The parent locale info or null if no parent.
- */
- private LocaleInfo parent;
-
- /**
- * The relaled locale.
- */
- private Locale locale;
-
- /**
- * The trailing name used to compute resource bundle name.
- */
- private String trailingName;
-
- /**
- * The RFC3066 language tag.
- */
- private String rfc3066LangageTag;
-
- // Constructor
******************************************************************************************************
-
- private LocaleInfo(LocaleInfo parent, Locale locale)
- {
- this.locale = locale;
- this.trailingName = computeTrailingName(locale);
- this.parent = parent;
-
- //
- this.rfc3066LangageTag = getRFC3066LanguageTagFor(locale);
- }
-
- // Public
***********************************************************************************************************
-
- public LocaleInfo getParent()
- {
- return parent;
- }
-
- public Locale getLocale()
- {
- return locale;
- }
-
- public String getTrailingName()
- {
- return trailingName;
- }
-
- /**
- * Retrieves the language identification tag associated to this LocaleInfo as defined
by
- * <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC
3066</a> limited to 2-letter
- * language code per ISO standard 639, a "-" (dash) and a 2-letter country
code per
- * ISO 3166 alpha-2 country codes. E.g. "en-US" for American English,
"en-GB" for
- * British English, etc.
- *
- * @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
- */
- public String getRFC3066LanguageTag()
- {
- return rfc3066LangageTag;
- }
-
- /**
- * Retrieves the language identification tag associated to the specified Locale as
defined by
- * <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC
3066</a> limited to 2-letter
- * language code per ISO standard 639, a "-" (dash) and a 2-letter country
code per
- * ISO 3166 alpha-2 country codes. E.g. "en-US" for American English,
"en-GB" for
- * British English, etc.
- *
- * @param locale the locale which language tag is wanted
- * @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
- */
- public static String getRFC3066LanguageTagFor(Locale locale)
- {
- String country = locale.getCountry(); // country will be empty if no country was
specified in the locale
- return locale.getLanguage() + ((country.length() == 2) ? RFC3066_SEPARATOR +
country : country);
- }
-
- // Object override
**************************************************************************************************
-
- public String toString()
- {
- return locale.toString();
- }
-
- // Static
***********************************************************************************************************
-
- /**
- * Compute the trailing name for a given locale.
- *
- * @param locale the locale
- * @return the trailing name
- * @throws IllegalArgumentException if locale is null
- */
- public static String computeTrailingName(Locale locale) throws
IllegalArgumentException
- {
- if (locale == null)
- {
- throw new IllegalArgumentException("locale parameter is null");
- }
- StringBuffer tmp = new StringBuffer();
- if (locale.getLanguage() != null && locale.getLanguage().length() > 0)
- {
- tmp.append('_').append(locale.getLanguage());
- if (locale.getCountry() != null && locale.getCountry().length() > 0)
- {
- tmp.append('_').append(locale.getCountry());
- {
- if (locale.getVariant() != null && locale.getVariant().length()
> 0)
- {
- tmp.append('_').append(locale.getVariant());
- }
- }
- }
- }
- return tmp.toString();
- }
-
- /**
- * <p>Get an info object.</p>
- * <p/>
- * <p>Whenever the info object cannot be found then it creates a new one and
possibly several
- * since each info object may have a non null parent.</p>
- * <p/>
- * <p>If the infos argument is null, then the static shared infos is used to
perform a lookup.
- * If the lookup returns null then the shared infos is cloned and updated with the
newly created
- * info objects. The operation performed is a copy on write and is thread safe. Note
that concurrent
- * updates may cause the lost of info object in the shared infos.</p>
- * <p/>
- * <p>If the infos argument is not null, then it is used to perform a lookup
first. If the lookup returns null
- * then the infos object udpated with the newly created info objects. Note that no
cloning of the infos object
- * is performed.</p>
- *
- * @param locale the locale
- * @param infos the infos
- * @return A info object for the given locale
- */
- private static LocaleInfo getInfo(Locale locale, final Infos infos)
- {
- // Perform a lookup first
- Infos workInfos = null;
- if (infos != null)
- {
- workInfos = infos;
- }
- else
- {
- workInfos = sharedInfos;
- }
- LocaleInfo info = (LocaleInfo)workInfos.byLocaleCode.get(locale.toString());
-
- // If the lookup fail we create a new object
- if (info == null)
- {
- // Clone if it is shared
- if (infos == null)
- {
- workInfos = new Infos(workInfos);
- }
-
- // Perform parent resolution
- LocaleInfo parent = null;
- if (locale.getVariant() != null && locale.getVariant().length() > 0)
- {
- // If this is a language/country/variant, try to get language/country
- Locale parentLocale = new Locale(locale.getLanguage(), locale.getCountry());
- parent = getInfo(parentLocale, workInfos);
- }
- else if (locale.getCountry() != null && locale.getCountry().length()
> 0)
- {
- // If this is a language/country, try to get language
- Locale parentLocale = new Locale(locale.getLanguage());
- parent = getInfo(parentLocale, workInfos);
- }
- else
- {
- // When it is language then the parent is null
- parent = null;
- }
-
- //
- info = new LocaleInfo(parent, locale);
- log.debug("LocaleInfo " + locale.toString() + "
initialized");
-
- // Add to map
- workInfos.byLocale.put(info.getLocale(), info);
- workInfos.byLocaleCode.put(info.getLocale().toString(), info);
- workInfos.byRFC3066LanguageTag.put(info.getRFC3066LanguageTag(), info);
- workInfos.list.add(info);
-// Collections.sort(workInfos.list, c);
-
- // Replace if we have cloned
- if (infos == null)
- {
- sharedInfos = workInfos;
- }
- }
- return info;
- }
-
-
- /**
- * Create an infos object from the set of locales returned by
<code>Locale.getAvailableLocales()</code>.
- */
- private static Infos createFromAvailableLocales()
- {
- // Initialize all objects
- Infos workInfos = new Infos();
- Locale[] temp = Locale.getAvailableLocales();
- for (int i = 0; i < temp.length; i++)
- {
- Locale locale = temp[i];
- getInfo(locale, workInfos);
- }
- return workInfos;
- }
-
- /**
- * Return a collection of all available locale info for the platform.
- */
- public static Collection getAll()
- {
- return sharedInfos.unmodifiableList;
- }
-
- /**
- * Return the locale info for a specific code.
- *
- * @throws IllegalArgumentException if the locale info is not found for the code
- */
- public static LocaleInfo decodeLocaleInfo(String code) throws
IllegalArgumentException
- {
- LocaleInfo info = (LocaleInfo)sharedInfos.byLocaleCode.get(code);
- if (info == null)
- {
- throw new IllegalArgumentException("No locale info found for " +
code);
- }
- return info;
- }
-
- /**
- * Return the locale info for a specific locale.
- *
- * @throws IllegalArgumentException if the locale is not found for the code
- */
- public static LocaleInfo decodeLocaleInfo(Locale locale)
- {
- LocaleInfo info = (LocaleInfo)sharedInfos.byLocale.get(locale);
- if (info == null)
- {
- throw new IllegalArgumentException("No locale info found for " +
locale);
- }
- return info;
- }
-
- /**
- * Returns an info object based on the given language identification tag as defined
by
- * <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC
3066</a> limited to 2-letter
- * language code per ISO standard 639, a "-" (dash) and a 2-letter country
code per
- * ISO 3166 alpha-2 country codes. E.g. "en-US" for American English,
"en-GB" for
- * British English, etc.
- *
- * @param languageIdentificationTag the language tag to build the Locale from
- * @return a LocaleInfo associated to the given compound language tag
- * @throws IllegalArgumentException if the given compound language is not a valid one
or null
- * @since 2.4
- */
- public static LocaleInfo decodeLocaleInfoFromRFC3066LanguageTag(String
languageIdentificationTag)
- {
- if (languageIdentificationTag == null)
- {
- throw new IllegalArgumentException("Null language identification tag not
accepted");
- }
-
- LocaleInfo info =
(LocaleInfo)sharedInfos.byRFC3066LanguageTag.get(languageIdentificationTag);
- if (info == null)
- {
- Matcher matcher =
RFC3066_COMPOUND_LANG_PATTERN.matcher(languageIdentificationTag);
- if (matcher.matches())
- {
- String language = matcher.group(1);
- if (Arrays.binarySearch(SORTED_ISO_LANGUAGES, language) < 0)
- {
- throw new IllegalArgumentException("Invalid ISO language code: "
+ language);
- }
- String country = matcher.group(3);
- if (country != null && Arrays.binarySearch(SORTED_ISO_COUNTRIES,
country) < 0)
- {
- throw new IllegalArgumentException("Invalid ISO country code: "
+ country);
- }
- return new LocaleInfo(LocaleInfo.decodeLocaleInfo(language), new
Locale(language, country));
- }
- throw new IllegalArgumentException(languageIdentificationTag + " is not a
valid compound language : accepted " +
- "format is xx-YY where xx is a valid ISO language code and YY is a valid
country code. See " +
- "java.util.Locale javadoc for more info.");
- }
- return info;
- }
-
-
- /**
- * Hold the several ways to retrieve infos object.
- */
- private static class Infos
- {
- /**
- * The info by locale.
- */
- private Map byLocale;
-
- /**
- * The info by locale#toString() code.
- */
- private Map byLocaleCode;
-
- /**
- * The info by locale RFC3066 language tag.
- */
- private Map byRFC3066LanguageTag;
-
- /**
- * All the infos.
- */
- private List list;
-
- /**
- * All the infos as an unmodifiable list.
- */
- private List unmodifiableList;
-
- /**
- * Construct a new info object.
- */
- public Infos()
- {
- this.byLocale = new HashMap();
- this.byLocaleCode = new HashMap();
- this.byRFC3066LanguageTag = new HashMap();
- this.list = new ArrayList();
- this.unmodifiableList = Collections.unmodifiableList(list);
- }
-
- /**
- * Clone the info object state passed as argument.
- */
- public Infos(Infos that)
- {
- this.byLocale = new HashMap(that.byLocale);
- this.byLocaleCode = new HashMap(that.byLocaleCode);
- this.byRFC3066LanguageTag = new HashMap(that.byRFC3066LanguageTag);
- this.list = new ArrayList(that.list);
- this.unmodifiableList = Collections.unmodifiableList(list);
- }
- }
-}
Added: trunk/common/src/main/org/jboss/portal/common/i18n/LocaleManager.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/LocaleManager.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/LocaleManager.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.i18n;
+
+import org.jboss.portal.common.util.Tools;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class LocaleManager
+{
+
+ /** . */
+ private static final Collection all =
Collections.unmodifiableSet(Tools.toSet(Locale.getAvailableLocales()));
+
+ /**
+ * Return a collection of all available locale info for the platform.
+ */
+ public static Collection getLocales()
+ {
+ return all;
+ }
+}
Modified: trunk/common/src/main/org/jboss/portal/common/i18n/LocalizedString.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/LocalizedString.java 2007-05-05
21:55:31 UTC (rev 7199)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/LocalizedString.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -23,6 +23,7 @@
package org.jboss.portal.common.i18n;
import org.apache.log4j.Logger;
+import org.jboss.portal.common.util.ConversionException;
import java.util.Collections;
import java.util.HashMap;
@@ -298,7 +299,7 @@
* @return a Map.Entry representing the most appropriate mapping between Locale and
localized value, based on locale
* preferences.
* @throws IllegalArgumentException if the array is null or one of the array string is
null or invalid (see {@link
- *
LocaleInfo#decodeLocaleInfoFromRFC3066LanguageTag(String)}
+ *
LocaleFormat#RFC3066_LANGUAGE_TAG#getLocale(String)}
* @since 2.4
*/
public Value getPreferredOrBestLocalizedMappingFor(String[] desiredLocales) throws
IllegalArgumentException
@@ -331,11 +332,10 @@
//
try
{
- LocaleInfo info =
LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(desiredLocale);
- Locale locale = info.getLocale();
+ Locale locale =
LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale(desiredLocale);
value = getValue(locale, true);
}
- catch (IllegalArgumentException e)
+ catch (ConversionException e)
{
if (log.isDebugEnabled())
{
Added:
trunk/common/src/main/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java
(rev 0)
+++
trunk/common/src/main/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -0,0 +1,113 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.i18n;
+
+import org.jboss.portal.common.util.FormatConversionException;
+
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import java.util.Locale;
+import java.util.Arrays;
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+class RFC3066LanguageTagLocaleFormat extends LocaleFormat
+{
+
+ /**
+ * Separator.
+ */
+ private static final String RFC3066_SEPARATOR = "-";
+
+ /**
+ * Valid language tag matcher (see <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC 3066</a>).
+ */
+ private final Pattern RFC3066_COMPOUND_LANG_PATTERN =
Pattern.compile("(\\p{Lower}{2})(-(\\p{Upper}{2}))?");
+
+ /**
+ * Sorted valid ISO country codes (needed for Arrays.binarySearch).
+ */
+ private final String[] SORTED_ISO_COUNTRIES = Locale.getISOCountries();
+
+ /**
+ * Sorted valid ISO language codes (needed for Arrays.binarySearch).
+ */
+ private final String[] SORTED_ISO_LANGUAGES = Locale.getISOLanguages();
+
+ protected Locale internalGetLocale(String value) throws FormatConversionException
+ {
+ Matcher matcher = RFC3066_COMPOUND_LANG_PATTERN.matcher(value);
+ if (matcher.matches())
+ {
+ String language = matcher.group(1);
+ if (Arrays.binarySearch(SORTED_ISO_LANGUAGES, language) < 0)
+ {
+ throw new FormatConversionException("Invalid ISO language code: " +
language);
+ }
+ String country = matcher.group(3);
+ if (country == null)
+ {
+ return new Locale(language);
+ }
+ else if (Arrays.binarySearch(SORTED_ISO_COUNTRIES, country) < 0)
+ {
+ throw new FormatConversionException("Invalid ISO country code: " +
country);
+ }
+ return new Locale(language, country);
+ }
+ throw new FormatConversionException(value + " is not a valid compound language
: accepted " +
+ "format is xx-YY where xx is a valid ISO language code and YY is a valid
country code. See " +
+ "java.util.Locale javadoc for more info.");
+ }
+
+ /**
+ * Retrieves the language identification tag associated to the specified Locale as
defined by
+ * <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC
3066</a> limited to 2-letter
+ * language code per ISO standard 639, a "-" (dash) and a 2-letter country
code per
+ * ISO 3166 alpha-2 country codes. E.g. "en-US" for American English,
"en-GB" for
+ * British English, etc.
+ *
+ * @param locale the locale which language tag is wanted
+ * @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
+ {
+ String country = locale.getCountry(); // country will be empty if no country was
specified in the locale
+ writer.write(locale.getLanguage());
+ if (country.length() == 2)
+ {
+ writer.write(RFC3066_SEPARATOR);
+ writer.write(country);
+ }
+ else
+ {
+ writer.write(country);
+ }
+ }
+}
Copied: trunk/common/src/main/org/jboss/portal/common/util/ConversionException.java (from
rev 7178, trunk/common/src/main/org/jboss/portal/common/value/ConversionException.java)
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/ConversionException.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/util/ConversionException.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.util;
+
+/**
+ * Signals that an error occured during a conversion.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class ConversionException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 4647584036804084315L;
+
+ public ConversionException()
+ {
+ }
+
+ public ConversionException(String message)
+ {
+ super(message);
+ }
+
+ public ConversionException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public ConversionException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/common/util/ConversionException.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: trunk/common/src/main/org/jboss/portal/common/util/FormatConversionException.java
(from rev 7178,
trunk/common/src/main/org/jboss/portal/common/value/FormatConversionException.java)
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/FormatConversionException.java
(rev 0)
+++
trunk/common/src/main/org/jboss/portal/common/util/FormatConversionException.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.util;
+
+/**
+ * A non expected format prevents a conversion to happen.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class FormatConversionException extends ConversionException
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -6642578306452728356L;
+
+ public FormatConversionException()
+ {
+ }
+
+ public FormatConversionException(String message)
+ {
+ super(message);
+ }
+
+ public FormatConversionException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public FormatConversionException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/common/util/FormatConversionException.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: trunk/common/src/main/org/jboss/portal/common/util/NullConversionException.java
(from rev 7178,
trunk/common/src/main/org/jboss/portal/common/value/NullConversionException.java)
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/NullConversionException.java
(rev 0)
+++
trunk/common/src/main/org/jboss/portal/common/util/NullConversionException.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.util;
+
+/**
+ * A null pointer prevents a conversion to happen.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class NullConversionException extends ConversionException
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 5948866940278003857L;
+
+ public NullConversionException()
+ {
+ }
+
+ public NullConversionException(String message)
+ {
+ super(message);
+ }
+
+ public NullConversionException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public NullConversionException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/common/util/NullConversionException.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Deleted: trunk/common/src/main/org/jboss/portal/common/value/ConversionException.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/common/value/ConversionException.java 2007-05-05
21:55:31 UTC (rev 7199)
+++
trunk/common/src/main/org/jboss/portal/common/value/ConversionException.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -1,48 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.common.value;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class ConversionException extends Exception
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 4647584036804084315L;
- public ConversionException()
- {
- }
- public ConversionException(String message)
- {
- super(message);
- }
- public ConversionException(String message, Throwable cause)
- {
- super(message, cause);
- }
- public ConversionException(Throwable cause)
- {
- super(cause);
- }
-}
Modified: trunk/common/src/main/org/jboss/portal/common/value/Converter.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/value/Converter.java 2007-05-05 21:55:31
UTC (rev 7199)
+++ trunk/common/src/main/org/jboss/portal/common/value/Converter.java 2007-05-06 16:33:54
UTC (rev 7200)
@@ -22,7 +22,10 @@
******************************************************************************/
package org.jboss.portal.common.value;
+import org.jboss.portal.common.util.FormatConversionException;
+import org.jboss.portal.common.util.NullConversionException;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
@@ -40,7 +43,7 @@
* String to object conversion.
*
* @throws NullConversionException if the value nullity prevent the conversion
- * @throws FormatConversionException if the value cannot be converted
+ * @throws org.jboss.portal.common.util.FormatConversionException if the value cannot
be converted
*/
Object toObject(String value) throws NullConversionException,
FormatConversionException;
Deleted:
trunk/common/src/main/org/jboss/portal/common/value/FormatConversionException.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/common/value/FormatConversionException.java 2007-05-05
21:55:31 UTC (rev 7199)
+++
trunk/common/src/main/org/jboss/portal/common/value/FormatConversionException.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -1,52 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.common.value;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class FormatConversionException extends ConversionException
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = -6642578306452728356L;
-
- public FormatConversionException()
- {
- }
-
- public FormatConversionException(String message)
- {
- super(message);
- }
-
- public FormatConversionException(String message, Throwable cause)
- {
- super(message, cause);
- }
-
- public FormatConversionException(Throwable cause)
- {
- super(cause);
- }
-}
Modified: trunk/common/src/main/org/jboss/portal/common/value/Helper.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/value/Helper.java 2007-05-05 21:55:31
UTC (rev 7199)
+++ trunk/common/src/main/org/jboss/portal/common/value/Helper.java 2007-05-06 16:33:54
UTC (rev 7200)
@@ -22,7 +22,10 @@
******************************************************************************/
package org.jboss.portal.common.value;
+import org.jboss.portal.common.util.FormatConversionException;
+import org.jboss.portal.common.util.NullConversionException;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
Deleted: trunk/common/src/main/org/jboss/portal/common/value/NullConversionException.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/common/value/NullConversionException.java 2007-05-05
21:55:31 UTC (rev 7199)
+++
trunk/common/src/main/org/jboss/portal/common/value/NullConversionException.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -1,52 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.common.value;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class NullConversionException extends ConversionException
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 5948866940278003857L;
-
- public NullConversionException()
- {
- }
-
- public NullConversionException(String message)
- {
- super(message);
- }
-
- public NullConversionException(String message, Throwable cause)
- {
- super(message, cause);
- }
-
- public NullConversionException(Throwable cause)
- {
- super(cause);
- }
-}
Added: trunk/common/src/main/org/jboss/portal/test/common/LocaleFormatTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/LocaleFormatTestCase.java
(rev 0)
+++
trunk/common/src/main/org/jboss/portal/test/common/LocaleFormatTestCase.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -0,0 +1,143 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common;
+
+import junit.framework.TestCase;
+
+import java.util.Locale;
+
+import org.jboss.portal.common.i18n.LocaleFormat;
+import org.jboss.portal.common.util.FormatConversionException;
+import org.jboss.portal.common.util.ConversionException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class LocaleFormatTestCase extends TestCase
+{
+
+ public void testgetLocaleFromDefaultFormat() throws ConversionException
+ {
+ assertEquals(new Locale("a"),
LocaleFormat.DEFAULT.getLocale("a"));
+ assertEquals(new Locale("a", "b"),
LocaleFormat.DEFAULT.getLocale("a_b"));
+ assertEquals(new Locale("", "b"),
LocaleFormat.DEFAULT.getLocale("_b"));
+ assertEquals(new Locale("a", "b", "c"),
LocaleFormat.DEFAULT.getLocale("a_b_c"));
+ assertEquals(new Locale("a", "", "b"),
LocaleFormat.DEFAULT.getLocale("a__b"));
+ assertEquals(new Locale("", "a", "b"),
LocaleFormat.DEFAULT.getLocale("_a_b"));
+ assertEquals(new Locale(""),
LocaleFormat.DEFAULT.getLocale(""));
+
+ //
+ try
+ {
+ assertEquals(new Locale("", "", "a"),
LocaleFormat.DEFAULT.getLocale("__a"));
+ fail();
+ }
+ catch (ConversionException expected)
+ {
+ }
+ try
+ {
+ assertEquals(new Locale("", "", ""),
LocaleFormat.DEFAULT.getLocale("__"));
+ fail();
+ }
+ catch (ConversionException expected)
+ {
+ }
+ try
+ {
+ LocaleFormat.DEFAULT.getLocale("_");
+ fail();
+ }
+ catch (ConversionException expected)
+ {
+ }
+ }
+
+ public void testToStringFromDefaultFormat() throws ConversionException
+ {
+ assertEquals("a", LocaleFormat.DEFAULT.toString(new
Locale("a")));
+ assertEquals("", LocaleFormat.DEFAULT.toString(new
Locale("")));
+
+ //
+ assertEquals("", LocaleFormat.DEFAULT.toString(new Locale("",
"")));
+ assertEquals("a_B", LocaleFormat.DEFAULT.toString(new
Locale("a", "b")));
+ assertEquals("a", LocaleFormat.DEFAULT.toString(new Locale("a",
"")));
+ assertEquals("_A", LocaleFormat.DEFAULT.toString(new Locale("",
"a")));
+
+ //
+ assertEquals("a_B_c", LocaleFormat.DEFAULT.toString(new
Locale("a", "b", "c")));
+ assertEquals("_A_b", LocaleFormat.DEFAULT.toString(new
Locale("", "a", "b")));
+ assertEquals("a__b", LocaleFormat.DEFAULT.toString(new
Locale("a", "", "b")));
+ assertEquals("a_B", LocaleFormat.DEFAULT.toString(new
Locale("a", "b", "")));
+ assertEquals("", LocaleFormat.DEFAULT.toString(new Locale("",
"", "a")));
+ assertEquals("a", LocaleFormat.DEFAULT.toString(new Locale("a",
"", "")));
+ assertEquals("_A", LocaleFormat.DEFAULT.toString(new Locale("",
"a", "")));
+ assertEquals("", LocaleFormat.DEFAULT.toString(new Locale("",
"", "")));
+ }
+
+ public void testGetLocaleFromRFC3066LanguageTag() throws ConversionException
+ {
+ assertEquals(new Locale("en"),
LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("en"));
+ assertEquals(new Locale("en", "US"),
LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("en-US"));
+
+ try
+ {
+ LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("wrong");
+ fail("Should have failed since an invalid String was passed.");
+ }
+ catch (FormatConversionException e)
+ {
+ //expected
+ }
+
+ try
+ {
+ LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("zz");
+ fail("Should have failed since an invalid language code was
passed.");
+ }
+ catch (FormatConversionException e)
+ {
+ //expected
+ }
+
+ try
+ {
+ LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("fr-ZZ");
+ fail("Should have failed since an invalid country code was passed.");
+ }
+ catch (FormatConversionException e)
+ {
+ //expected
+ }
+
+ // weird combination should work as well
+ LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("fr-US");
+ }
+
+ public void testGetRFC3066LanguageTagFromLocale() throws ConversionException
+ {
+ assertEquals("en", LocaleFormat.RFC3066_LANGUAGE_TAG.toString(new
Locale("en")));
+ assertEquals("en-US", LocaleFormat.RFC3066_LANGUAGE_TAG.toString(new
Locale("en", "US")));
+ }
+}
Deleted: trunk/common/src/main/org/jboss/portal/test/common/LocaleInfoTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/LocaleInfoTestCase.java 2007-05-05
21:55:31 UTC (rev 7199)
+++ trunk/common/src/main/org/jboss/portal/test/common/LocaleInfoTestCase.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -1,119 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import junit.framework.TestCase;
-import org.jboss.portal.common.i18n.LocaleInfo;
-
-import java.util.Iterator;
-import java.util.Locale;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class LocaleInfoTestCase extends TestCase
-{
- public LocaleInfoTestCase(String key)
- {
- super(key);
- }
-
- public void testParent()
- {
- // Locate a locale with language/country/variant to achieve the test
- LocaleInfo info1 = null;
- for (Iterator i = LocaleInfo.getAll().iterator(); i.hasNext();)
- {
- LocaleInfo tmp = (LocaleInfo)i.next();
- if (tmp.getLocale().getVariant() != null &&
tmp.getLocale().getVariant().length() > 0)
- {
- info1 = tmp;
- break;
- }
- }
-
- // The test to pass
- assertNotNull("Cannot found a locale with language/country/variant",
info1);
-
- // Test the language/country parent
- LocaleInfo info2 = info1.getParent();
- assertNotNull(info2);
- assertEquals(new Locale(info1.getLocale().getLanguage(),
info1.getLocale().getCountry(), ""), info2.getLocale());
-
- // Test the language parent
- LocaleInfo info3 = info2.getParent();
- assertNotNull(info3);
- assertEquals(new Locale(info1.getLocale().getLanguage(), "",
""), info3.getLocale());
-
- // Test no parent
- LocaleInfo info4 = info3.getParent();
- assertNull(info4);
- }
-
- public void testGetLocaleFromRFC3066LanguageTag()
- {
- assertEquals(new Locale("en"),
LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag("en").getLocale());
- assertEquals(new Locale("en", "US"),
LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag("en-US").getLocale());
-
- try
- {
- LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag("wrong");
- fail("Should have failed since an invalid String was passed.");
- }
- catch (IllegalArgumentException e)
- {
- //expected
- }
-
- try
- {
- LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag("zz");
- fail("Should have failed since an invalid language code was
passed.");
- }
- catch (IllegalArgumentException e)
- {
- //expected
- }
-
- try
- {
- LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag("fr-ZZ");
- fail("Should have failed since an invalid country code was passed.");
- }
- catch (IllegalArgumentException e)
- {
- //expected
- }
-
- // weird combination should work as well
- LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag("fr-US");
- }
-
- public void testGetRFC3066LanguageTagFromLocale()
- {
- assertEquals("en", LocaleInfo.decodeLocaleInfo(new
Locale("en")).getRFC3066LanguageTag());
- assertEquals("en-US", LocaleInfo.decodeLocaleInfo(new
Locale("en", "US")).getRFC3066LanguageTag());
- }
-
-}
Modified: trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java 2007-05-05
21:55:31 UTC (rev 7199)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -49,9 +49,11 @@
import org.jboss.portal.api.node.PortalNode;
import org.jboss.portal.api.node.PortalNodeURL;
import org.jboss.portal.common.p3p.P3PConstants;
-import org.jboss.portal.common.i18n.LocaleInfo;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.URLTools;
+import org.jboss.portal.common.util.ConversionException;
+import org.jboss.portal.common.i18n.LocaleFormat;
+import org.jboss.portal.common.i18n.LocaleManager;
import org.jboss.portal.core.aspects.controller.node.Navigation;
import org.jboss.portal.core.modules.MailModule;
import org.jboss.portal.core.portlet.PortletHelper;
@@ -295,10 +297,9 @@
//
//String selectedLocale =
(String)user.getProfile().get(User.INFO_USER_LOCALE);
String selectedLocale = (String)getProperty(user, User.INFO_USER_LOCALE);
- for (Iterator i = LocaleInfo.getAll().iterator(); i.hasNext();)
+ for (Iterator i = LocaleManager.getLocales().iterator(); i.hasNext();)
{
- LocaleInfo info = (LocaleInfo)i.next();
- Locale locale = info.getLocale();
+ Locale locale = (Locale)i.next();
DelegateContext localeCtx = ctx.next("locale");
localeCtx.put("name", locale.getDisplayName(requestLocale));
localeCtx.put("id", locale.toString());
@@ -911,7 +912,7 @@
String interests = req.getParameter("interests");
String signature = req.getParameter("signature");
String extra = req.getParameter("extra");
- String locale = req.getParameter("locale");
+ String localeParam = req.getParameter("locale");
String theme = req.getParameter("theme");
if (nbErrors == 0)
@@ -949,12 +950,16 @@
setProperty(user, User.INFO_USER_TIME_ZONE_OFFSET,
timezoneoffset.toString());
}
- LocaleInfo localeInfo = LocaleInfo.decodeLocaleInfo(locale);
- if (localeInfo != null)
+ try
{
+ Locale locale = LocaleFormat.DEFAULT.getLocale(localeParam);
//setProperty(user, User.INFO_USER_LOCALE, localeInfo.getLocale());
- setProperty(user, User.INFO_USER_LOCALE, localeInfo.getLocale().toString());
+ setProperty(user, User.INFO_USER_LOCALE, locale.toString());
}
+ catch (ConversionException e)
+ {
+ log.error("Cannot convert locale format", e);
+ }
putNonEmptyProperty(user, User.INFO_USER_THEME, theme);
putNonEmptyProperty(user, User.INFO_USER_HOMEPAGE, homepage);
@@ -993,7 +998,7 @@
portletHelper.setRenderParameter(resp, "HOMEPAGE", homepage);
portletHelper.setRenderParameter(resp, "SELECTEDTIMEZONE",
"" + timezoneoffset);
- portletHelper.setRenderParameter(resp, "SELECTEDLOCALE", locale);
+ portletHelper.setRenderParameter(resp, "SELECTEDLOCALE",
localeParam);
portletHelper.setRenderParameter(resp, "THEME", theme);
portletHelper.setRenderParameter(resp, "ICQ", icq);
portletHelper.setRenderParameter(resp, "AIM", aim);
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaDataFactory.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaDataFactory.java 2007-05-05
21:55:31 UTC (rev 7199)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaDataFactory.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -23,7 +23,8 @@
import org.jboss.xb.binding.GenericObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
+import org.jboss.portal.common.util.ConversionException;
import org.xml.sax.Attributes;
import java.util.Locale;
@@ -67,8 +68,16 @@
LocalizedValueMetaData value = new LocalizedValueMetaData();
if (lang != null)
{
- Locale locale = LocaleInfo.decodeLocaleInfo(lang).getLocale();
- value.setLocale(locale);
+ try
+ {
+ Locale locale = LocaleFormat.DEFAULT.getLocale(lang);
+ value.setLocale(locale);
+ }
+ catch (ConversionException e)
+ {
+ log.error("Cannot obtain language value", e);
+ return null;
+ }
}
return value;
}
@@ -78,8 +87,16 @@
LocalizedValueMetaData value = new LocalizedValueMetaData();
if (lang != null)
{
- Locale locale = LocaleInfo.decodeLocaleInfo(lang).getLocale();
- value.setLocale(locale);
+ try
+ {
+ Locale locale = LocaleFormat.DEFAULT.getLocale(lang);
+ value.setLocale(locale);
+ }
+ catch (ConversionException e)
+ {
+ log.error("Cannot obtain language value", e);
+ return null;
+ }
}
return value;
}
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/deployment/PortletApplicationMetaDataFactory.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/deployment/PortletApplicationMetaDataFactory.java 2007-05-05
21:55:31 UTC (rev 7199)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/deployment/PortletApplicationMetaDataFactory.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -23,8 +23,9 @@
package org.jboss.portal.portlet.deployment;
import org.jboss.portal.Mode;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.util.ConversionException;
import org.jboss.portal.portlet.TransportGuarantee;
import org.jboss.portal.portlet.impl.jsr168.metadata.CacheConfigMetaData;
import org.jboss.portal.portlet.impl.jsr168.metadata.ContentTypeMetaData;
@@ -44,6 +45,7 @@
import org.jboss.xb.binding.GenericObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
import org.xml.sax.Attributes;
+import org.apache.log4j.Logger;
import java.util.Iterator;
import java.util.List;
@@ -56,6 +58,9 @@
public class PortletApplicationMetaDataFactory implements GenericObjectModelFactory
{
+ /** . */
+ private static final Logger log =
Logger.getLogger(PortletApplicationMetaDataFactory.class);
+
public Object newRoot(Object root, UnmarshallingContext nav, String nsURI, String
localName, Attributes attrs)
{
return new PortletApplicationMetaData();
@@ -76,8 +81,16 @@
DescriptionMetaData value = new DescriptionMetaData();
if (lang != null)
{
- Locale locale = LocaleInfo.decodeLocaleInfo(lang).getLocale();
- value.setLocale(locale);
+ try
+ {
+ Locale locale = LocaleFormat.DEFAULT.getLocale(lang);
+ value.setLocale(locale);
+ }
+ catch (ConversionException e)
+ {
+ log.error("Cannot obtain language value", e);
+ return null;
+ }
}
return value;
}
@@ -125,8 +138,16 @@
DisplayNameMetaData value = new DisplayNameMetaData();
if (lang != null)
{
- Locale locale = LocaleInfo.decodeLocaleInfo(lang).getLocale();
- value.setLocale(locale);
+ try
+ {
+ Locale locale = LocaleFormat.DEFAULT.getLocale(lang);
+ value.setLocale(locale);
+ }
+ catch (ConversionException e)
+ {
+ log.error("Cannot obtain language value", e);
+ return null;
+ }
}
return value;
}
@@ -264,8 +285,15 @@
}
else if ("supported-locale".equals(localName))
{
- Locale locale = LocaleInfo.decodeLocaleInfo(value).getLocale();
- portlet.getLanguages().getSupportedLocales().add(locale);
+ try
+ {
+ Locale locale = LocaleFormat.DEFAULT.getLocale(value);
+ portlet.getLanguages().getSupportedLocales().add(locale);
+ }
+ catch (ConversionException e)
+ {
+ log.error("Cannot obtain language value", e);
+ }
}
else if ("preferences-validator".equals(localName))
{
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java 2007-05-05
21:55:31 UTC (rev 7199)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -24,7 +24,7 @@
package org.jboss.portal.wsrp;
import org.jboss.portal.common.p3p.P3PConstants;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.portlet.spi.UserContext;
import org.jboss.portal.wsrp.core.Contact;
import org.jboss.portal.wsrp.core.EmployerInfo;
@@ -158,7 +158,7 @@
public WSRPMappedUserContext(org.jboss.portal.wsrp.core.UserContext userContext,
String[] desiredLocales, String preferredLocale)
{
this.desiredLocales = desiredLocales;
- this.locale =
LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(preferredLocale).getLocale();
+ this.locale = WSRPUtils.getLocale(preferredLocale);
if (userContext != null)
{
UserProfile profile = userContext.getProfile();
@@ -282,8 +282,8 @@
List locales = new ArrayList(length);
for (int i = 0; i < length; i++)
{
- LocaleInfo info =
LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(desiredLocales[i]);
- locales.add(info.getLocale());
+ Locale locale = WSRPUtils.getLocale(desiredLocales[i]);
+ locales.add(locale);
}
return locales;
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2007-05-05 21:55:31 UTC (rev
7199)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2007-05-06 16:33:54 UTC (rev
7200)
@@ -25,8 +25,9 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.common.util.ConversionException;
import org.jboss.portal.portlet.ActionURL;
import org.jboss.portal.portlet.PortletContext;
import org.jboss.portal.portlet.PortletURL;
@@ -214,7 +215,7 @@
for (Iterator iterator = localesOrderedByPreference.iterator(); iterator.hasNext();
i++)
{
Locale locale = (Locale)iterator.next();
- desiredLocales[i] = LocaleInfo.getRFC3066LanguageTagFor(locale);
+ desiredLocales[i] = toString(locale);
}
return desiredLocales;
}
@@ -341,7 +342,7 @@
}
else
{
- locale = LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(lang).getLocale();
+ locale = getLocale(lang);
}
LocalizedString localizedString = new
LocalizedString(wsrpLocalizedString.getValue(), locale);
@@ -357,7 +358,7 @@
public static org.jboss.portal.wsrp.core.LocalizedString
convertToWSRPLocalizedString(LocalizedString regLocalizedString)
{
ParameterValidation.throwIllegalArgExceptionIfNull(regLocalizedString,
"LocalizedString");
- return
WSRPTypeFactory.createLocalizedString(LocaleInfo.getRFC3066LanguageTagFor(regLocalizedString.getLocale()),
+ return
WSRPTypeFactory.createLocalizedString(toString(regLocalizedString.getLocale()),
regLocalizedString.getResourceName(), regLocalizedString.getValue());
}
@@ -382,7 +383,7 @@
if (desiredLocales == null || desiredLocales.length == 0)
{
- desiredLocales = new
String[]{LocaleInfo.getRFC3066LanguageTagFor(Locale.getDefault())};
+ desiredLocales = new String[]{toString(Locale.getDefault())};
}
org.jboss.portal.common.i18n.LocalizedString.Value bestMapping =
localizedString.getPreferredOrBestLocalizedMappingFor(desiredLocales);
@@ -390,9 +391,39 @@
{
Locale locale = bestMapping.getLocale();
String value = bestMapping.getString();
- String language = LocaleInfo.decodeLocaleInfo(locale).getRFC3066LanguageTag();
+ String language = toString(locale);
return WSRPTypeFactory.createLocalizedString(language, null, value);
}
return null;
}
+
+ public static Locale getLocale(String lang) throws IllegalArgumentException
+ {
+ try
+ {
+ return LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale(lang);
+ }
+ catch (ConversionException e)
+ {
+ // Previous behavior on using ConversionException was like that
+ IllegalArgumentException iae = new IllegalArgumentException();
+ iae.initCause(e);
+ throw iae;
+ }
+ }
+
+ public static String toString(Locale locale) throws IllegalArgumentException
+ {
+ try
+ {
+ return LocaleFormat.RFC3066_LANGUAGE_TAG.toString(locale);
+ }
+ catch (ConversionException e)
+ {
+ // Previous behavior on using ConversionException was like that
+ IllegalArgumentException iae = new IllegalArgumentException();
+ iae.initCause(e);
+ throw iae;
+ }
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-05-05
21:55:31 UTC (rev 7199)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -24,7 +24,7 @@
package org.jboss.portal.wsrp.consumer;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPTypeFactory;
@@ -219,7 +219,7 @@
else
{
// todo: deal with language more appropriately
- prop = new RegistrationProperty(name, value,
LocaleInfo.getRFC3066LanguageTagFor(Locale.getDefault()));
+ prop = new RegistrationProperty(name, value,
WSRPUtils.toString(Locale.getDefault()));
getOrCreateRegistrationPropertiesMap(false).put(name, prop);
dirty = true;
}
@@ -475,7 +475,7 @@
PropertyDescription description = descriptions[i];
String name = description.getName();
RegistrationPropertyDescription desc =
WSRPUtils.convertToRegistrationPropertyDescription(description);
- RegistrationProperty prop = new RegistrationProperty(name, null,
LocaleInfo.getRFC3066LanguageTagFor(desc.getLang()));
+ RegistrationProperty prop = new RegistrationProperty(name, null,
WSRPUtils.toString(desc.getLang()));
prop.setDescription(desc);
prop.setStatus(RegistrationProperty.MISSING_VALUE_STATUS);
prop.setInvalid(true);
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-05-05
21:55:31 UTC (rev 7199)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -24,7 +24,7 @@
import org.jboss.portal.api.event.PortalEvent;
import org.jboss.portal.api.event.PortalEventContext;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.common.value.StringValue;
@@ -348,7 +348,7 @@
case PropertyChange.PREF_UPDATE:
// todo: deal with language more appropriately
updates.add(WSRPTypeFactory.createProperty(change.getKey(),
- LocaleInfo.getRFC3066LanguageTagFor(Locale.getDefault()),
change.getValue().asString()));
+ WSRPUtils.toString(Locale.getDefault()),
change.getValue().asString()));
break;
default:
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/portlet/info/WSRPPortletInfo.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/portlet/info/WSRPPortletInfo.java 2007-05-05
21:55:31 UTC (rev 7199)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/portlet/info/WSRPPortletInfo.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -25,7 +25,7 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.portlet.info.CacheInfo;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
@@ -300,7 +300,7 @@
}
keywordsString = sb.toString();
// fix-me: for now assume that they all have the same language... this could
get messy!
- locale =
LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(keywords[0].getLang()).getLocale();
+ locale = WSRPUtils.getLocale(keywords[0].getLang());
}
}
@@ -317,7 +317,7 @@
}
return new
org.jboss.portal.common.i18n.LocalizedString(wsrpLocalizedString.getValue(),
-
LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(wsrpLocalizedString.getLang()).getLocale());
+ WSRPUtils.getLocale(wsrpLocalizedString.getLang()));
}
class MIMETypeInfo
@@ -347,8 +347,8 @@
locales = new HashSet(localeNumber);
for (int i = 0; i < localeNumber; i++)
{
- LocaleInfo info =
LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(localeNames[i]);
- locales.add(info.getLocale());
+ Locale locale = WSRPUtils.getLocale(localeNames[i]);
+ locales.add(locale);
}
}
else
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupRequest.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupRequest.java 2007-05-05
21:55:31 UTC (rev 7199)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupRequest.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -23,7 +23,7 @@
package org.jboss.portal.wsrp.producer;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.wsrp.WSRPUtils;
import org.jboss.portal.wsrp.core.MarkupType;
@@ -75,7 +75,7 @@
}
else
{
- return LocaleInfo.getRFC3066LanguageTagFor(Locale.ENGLISH); // no locale was
provided, use English...
+ return WSRPUtils.toString(Locale.ENGLISH); // no locale was provided, use
English...
}
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2007-05-05
21:55:31 UTC (rev 7199)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -24,8 +24,8 @@
package org.jboss.portal.wsrp.producer;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.i18n.LocaleInfo;
import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.value.StringValue;
import org.jboss.portal.common.value.Value;
@@ -368,7 +368,7 @@
value = (Value)entry.getValue();
prefInfo = info.getPreferences().getPreference(key);
displayName = prefInfo.getDisplayName();
- String lang =
LocaleInfo.getRFC3066LanguageTagFor(displayName.getDefaultLocale());
+ String lang = WSRPUtils.toString(displayName.getDefaultLocale());
resProperties[i] = WSRPTypeFactory.createProperty(key, lang,
value.asString()); //todo: check what we should use key
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java 2007-05-05
21:55:31 UTC (rev 7199)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -24,7 +24,7 @@
package org.jboss.portal.wsrp.producer;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
@@ -280,7 +280,7 @@
int i = 0;
for (Iterator iterator = locales.iterator(); iterator.hasNext();)
{
- localeNames[i++] =
LocaleInfo.getRFC3066LanguageTagFor((Locale)iterator.next());
+ localeNames[i++] = WSRPUtils.toString((Locale)iterator.next());
}
return localeNames;
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerConfigurationFactory.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerConfigurationFactory.java 2007-05-05
21:55:31 UTC (rev 7199)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerConfigurationFactory.java 2007-05-06
16:33:54 UTC (rev 7200)
@@ -23,12 +23,13 @@
package org.jboss.portal.wsrp.producer.config;
-import org.jboss.portal.common.i18n.LocaleInfo;
+import org.jboss.portal.common.i18n.LocaleFormat;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.wsrp.producer.config.impl.ProducerConfigurationImpl;
import org.jboss.portal.wsrp.producer.config.impl.ProducerRegistrationRequirementsImpl;
import org.jboss.portal.wsrp.registration.LocalizedString;
import org.jboss.portal.wsrp.registration.RegistrationPropertyDescription;
+import org.jboss.portal.wsrp.WSRPUtils;
import org.jboss.util.StringPropertyReplacer;
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
@@ -171,7 +172,7 @@
{
String lang = attrs.getValue("xml:lang");
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(lang,
"xml:lang", localName);
- Locale locale = LocaleInfo.decodeLocaleInfo(lang).getLocale();
+ Locale locale = WSRPUtils.getLocale(lang);
String resourceName = attrs.getValue("resourceName");