JBoss Portal SVN: r7208 - in trunk/core/src/resources: test/deployment and 1 other directory.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-05-06 20:49:23 -0400 (Sun, 06 May 2007)
New Revision: 7208
Modified:
trunk/core/src/resources/portal-core-sar/dtd/jboss-portlet_2_6.dtd
trunk/core/src/resources/test/deployment/jboss-portlet.xml
Log:
- Fixed test case.
- Typos.
Modified: trunk/core/src/resources/portal-core-sar/dtd/jboss-portlet_2_6.dtd
===================================================================
--- trunk/core/src/resources/portal-core-sar/dtd/jboss-portlet_2_6.dtd 2007-05-07 00:19:29 UTC (rev 7207)
+++ trunk/core/src/resources/portal-core-sar/dtd/jboss-portlet_2_6.dtd 2007-05-07 00:49:23 UTC (rev 7208)
@@ -140,7 +140,7 @@
<!ELEMENT header-content (link|script|meta)*>
<!--
-Creates an header markup element for linked resources,
+Creates a header markup element for linked resources,
see http://www.w3.org/TR/html401/struct/links.html#h-12.3
At runtime the href attribute value will be prefixed with the context path
@@ -166,7 +166,7 @@
<!ELEMENT link EMPTY>
<!--
-Creates an header markup for scripting,
+Creates a header markup for scripting,
see http://www.w3.org/TR/html401/interact/scripts.html
At runtime the src attribute value will be prefixed with the context path
@@ -199,7 +199,7 @@
<!ELEMENT script (#PCDATA)>
<!--
-Creates an header markup for adding meta data to a page,
+Creates a header markup for adding meta data to a page,
see http://www.w3.org/TR/html401/struct/global.html#h-7.4.4
Example:
Modified: trunk/core/src/resources/test/deployment/jboss-portlet.xml
===================================================================
--- trunk/core/src/resources/test/deployment/jboss-portlet.xml 2007-05-07 00:19:29 UTC (rev 7207)
+++ trunk/core/src/resources/test/deployment/jboss-portlet.xml 2007-05-07 00:49:23 UTC (rev 7208)
@@ -26,7 +26,7 @@
<portlet-name>Portlet1</portlet-name>
<remotable>true</remotable>
<header-content>
- <link rel="stylesheet" type="text/css" href="test.css" title="stylesheet title" media="screen"/>
+ <link rel="stylesheet" type="text/css" href="test.css" media="screen"/>
<script type="text/javascript" src="test.js"/>
<meta name="description" content="test content"/>
</header-content>
18 years, 12 months
JBoss Portal SVN: r7207 - in trunk/wsrp/src: resources/tests/test-producer-configuration-lib-jar and 1 other directory.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-05-06 20:19:29 -0400 (Sun, 06 May 2007)
New Revision: 7207
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/config/ProducerConfigurationTestCase.java
trunk/wsrp/src/resources/tests/test-producer-configuration-lib-jar/extended.xml
Log:
- Fixed ProducerConfigurationTestCase.
Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/config/ProducerConfigurationTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/config/ProducerConfigurationTestCase.java 2007-05-06 21:48:33 UTC (rev 7206)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/config/ProducerConfigurationTestCase.java 2007-05-07 00:19:29 UTC (rev 7207)
@@ -28,6 +28,7 @@
import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
import org.jboss.portal.registration.policies.DefaultRegistrationPropertyValidator;
import org.jboss.portal.registration.policies.RegistrationPropertyValidator;
+import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.producer.config.ProducerConfiguration;
import org.jboss.portal.wsrp.producer.config.ProducerConfigurationFactory;
import org.jboss.portal.wsrp.producer.config.ProducerRegistrationRequirements;
@@ -103,26 +104,32 @@
assertTrue(properties.isEmpty());
}
- public void testInvalidProducerConfiguration() throws Exception
+ public void testInvalidMultipleRegistrationConfiguration() throws Exception
{
try
{
- getProducerConfiguration("invalid1.xml");
- fail("Invalid value for fullServiceDescriptionRequiresRegistration should have caused failure");
+ getProducerConfiguration("invalid2.xml");
+ fail("Only one registration-configuration element allowed!");
}
catch (Exception expected)
{
}
+ }
+ public void testInvalidTypeValue() throws Exception
+ {
try
{
- getProducerConfiguration("invalid2.xml");
- fail("Only one registration-configuration element allowed!");
+ getProducerConfiguration("invalid-type.xml");
+ fail("Invalid type for property description should fail.");
}
catch (Exception expected)
{
}
+ }
+ public void testInvalidPropertyValidator()
+ {
try
{
getProducerConfiguration("invalid3.xml");
@@ -131,22 +138,25 @@
catch (Exception expected)
{
}
+ }
+ public void testInvalidFullServiceDescriptionValue()
+ {
try
{
- getProducerConfiguration("invalid-type.xml");
- fail("Invalid type for property description should fail.");
+ getProducerConfiguration("invalid1.xml");
+ fail("Invalid value for fullServiceDescriptionRequiresRegistration should have caused failure");
}
- catch (IllegalArgumentException expected)
+ catch (Exception expected)
{
}
}
- private ProducerConfiguration getProducerConfiguration(String fileName)
- throws JBossXBException, IOException
+ private ProducerConfiguration getProducerConfiguration(String fileName) throws JBossXBException, IOException
{
URL location = Thread.currentThread().getContextClassLoader().getResource(fileName);
assertNotNull(location);
+ System.out.println("location = " + location);
Object o = unmarshaller.unmarshal(location.openStream(), factory, null);
assertNotNull(o);
@@ -159,7 +169,7 @@
RegistrationPropertyDescription desc = requirements.getRegistrationPropertyWith("name" + index);
assertNotNull(desc);
assertEquals(new QName("name" + index), desc.getName());
- assertEquals(new QName("xsd:string"), desc.getType());
+ assertEquals(WSRPConstants.XSD_STRING, desc.getType());
LocalizedString localizedString = new LocalizedString("hint" + index, Locale.ENGLISH);
localizedString.setResourceName("resource.hint" + index);
Modified: trunk/wsrp/src/resources/tests/test-producer-configuration-lib-jar/extended.xml
===================================================================
--- trunk/wsrp/src/resources/tests/test-producer-configuration-lib-jar/extended.xml 2007-05-06 21:48:33 UTC (rev 7206)
+++ trunk/wsrp/src/resources/tests/test-producer-configuration-lib-jar/extended.xml 2007-05-07 00:19:29 UTC (rev 7207)
@@ -29,14 +29,14 @@
<registration-property-description>
<name>name1</name>
<type>xsd:string</type>
+ <label xml:lang="en" resourceName="resource.label1">label1</label>
<hint xml:lang="en" resourceName="resource.hint1">hint1</hint>
- <label xml:lang="en" resourceName="resource.label1">label1</label>
</registration-property-description>
<registration-property-description>
<name>name2</name>
<type>xsd:string</type>
+ <label xml:lang="en" resourceName="resource.label2">label2</label>
<hint xml:lang="en" resourceName="resource.hint2">hint2</hint>
- <label xml:lang="en" resourceName="resource.label2">label2</label>
</registration-property-description>
</registration-configuration>
</producer-configuration>
18 years, 12 months
JBoss Portal SVN: r7206 - trunk/core/src/main/org/jboss/portal/core.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-05-06 17:48:33 -0400 (Sun, 06 May 2007)
New Revision: 7206
Modified:
trunk/core/src/main/org/jboss/portal/core/CoreConstants.java
Log:
removed useless constants
Modified: trunk/core/src/main/org/jboss/portal/core/CoreConstants.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/CoreConstants.java 2007-05-06 21:43:31 UTC (rev 7205)
+++ trunk/core/src/main/org/jboss/portal/core/CoreConstants.java 2007-05-06 21:48:33 UTC (rev 7206)
@@ -40,11 +40,7 @@
*/
public static final class Session
{
-
/** . */
- public static final String GUEST_INFO = "jboss.portal.guest_info";
-
- /** . */
public static final String USER_FINALIZER = "jboss.portal.user_finalizer";
}
@@ -61,7 +57,4 @@
public static final String PORTAL_SERVLET_PATH = "jboss.portal.servlet_path";
}
}
-
- /** . */
- public static final String REQUEST_TYPE = "jboss.portal.request_type";
}
18 years, 12 months
JBoss Portal SVN: r7205 - in trunk/core/src: main/org/jboss/portal/core/model/portal and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-05-06 17:43:31 -0400 (Sun, 06 May 2007)
New Revision: 7205
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/Context.java
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ContextImpl.java
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
trunk/core/src/main/org/jboss/portal/core/model/portal/Window.java
trunk/core/src/resources/portal-core-sar/conf/hibernate/portal/domain.hbm.xml
Log:
- added missing Context interface
- renamed instanceRef -> URI field on the WindowImpl object (need to keep the underlying DB field instanceRef though)
- added convenient Window.getPage() method
Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ContextImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ContextImpl.java 2007-05-06 21:05:30 UTC (rev 7204)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ContextImpl.java 2007-05-06 21:43:31 UTC (rev 7205)
@@ -26,6 +26,7 @@
import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.Context;
import java.util.HashMap;
@@ -33,7 +34,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public class ContextImpl extends PortalObjectImpl implements PortalContainer
+public class ContextImpl extends PortalObjectImpl implements Context
{
public ContextImpl()
Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java 2007-05-06 21:05:30 UTC (rev 7204)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java 2007-05-06 21:43:31 UTC (rev 7205)
@@ -24,6 +24,7 @@
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.model.content.spi.handler.ContentState;
@@ -43,7 +44,7 @@
public static final String PORTAL_PROP_WINDOW_CONTENT_TYPE = "portal.windowContentType";
// Persistent state
- protected String instanceRef;
+ protected String uri;
// Runtime fields
protected AbstractPortalObjectContainer.Context context;
@@ -56,7 +57,7 @@
//
this.contentType = null;
- this.instanceRef = null;
+ this.uri = null;
}
/**
@@ -81,7 +82,7 @@
//
this.contentType = contentType;
- this.instanceRef = contentURI;
+ this.uri = contentURI;
//
setDeclaredProperty(PORTAL_PROP_WINDOW_CONTENT_TYPE, contentType.toString());
@@ -101,16 +102,21 @@
this.context = (AbstractPortalObjectContainer.Context)context;
}
- public String getInstanceRef()
+ public String getURI()
{
- return instanceRef;
+ return uri;
}
- public void setInstanceRef(String instanceRef)
+ public void setURI(String uri)
{
- this.instanceRef = instanceRef;
+ this.uri = uri;
}
+ public Page getPage()
+ {
+ return (Page)getParent();
+ }
+
public Content getContent()
{
return getContentState().getContent();
@@ -134,11 +140,6 @@
return contentType;
}
- public String getURI()
- {
- return instanceRef;
- }
-
public int getType()
{
return PortalObject.TYPE_WINDOW;
@@ -147,7 +148,7 @@
protected PortalObjectImpl cloneObject()
{
WindowImpl clone = new WindowImpl();
- clone.setInstanceRef(instanceRef);
+ clone.setURI(uri);
clone.setDeclaredPropertyMap(new HashMap(getDeclaredPropertyMap()));
clone.setListener(getListener());
return clone;
@@ -173,12 +174,12 @@
public String getURI()
{
- return instanceRef;
+ return WindowImpl.this.uri;
}
public void setURI(String uri)
{
- instanceRef = uri;
+ WindowImpl.this.uri = uri;
}
private void destroy()
Added: trunk/core/src/main/org/jboss/portal/core/model/portal/Context.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/Context.java (rev 0)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/Context.java 2007-05-06 21:43:31 UTC (rev 7205)
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * 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.core.model.portal;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface Context extends PortalContainer
+{
+}
Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/Window.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/Window.java 2007-05-06 21:05:30 UTC (rev 7204)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/Window.java 2007-05-06 21:43:31 UTC (rev 7205)
@@ -33,7 +33,15 @@
*/
public interface Window extends PortalObject
{
+
/**
+ * Return the page containing this window.
+ *
+ * @return the page
+ */
+ Page getPage();
+
+ /**
* Return the window content type.
*
* @return the window content type
Modified: trunk/core/src/resources/portal-core-sar/conf/hibernate/portal/domain.hbm.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/conf/hibernate/portal/domain.hbm.xml 2007-05-06 21:05:30 UTC (rev 7204)
+++ trunk/core/src/resources/portal-core-sar/conf/hibernate/portal/domain.hbm.xml 2007-05-06 21:43:31 UTC (rev 7205)
@@ -165,7 +165,7 @@
table="JBP_WINDOW">
<key column="PK"/>
<property
- name="instanceRef"
+ name="URI"
column="INSTANCE_REF"/>
</joined-subclass>
</class>
18 years, 12 months
JBoss Portal SVN: r7204 - trunk/core/src/main/org/jboss/portal/core/portlet/user.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-05-06 17:05:30 -0400 (Sun, 06 May 2007)
New Revision: 7204
Modified:
trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
Log:
minor locale improvement
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-06 21:01:14 UTC (rev 7203)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java 2007-05-06 21:05:30 UTC (rev 7204)
@@ -302,8 +302,9 @@
Locale locale = (Locale)i.next();
DelegateContext localeCtx = ctx.next("locale");
localeCtx.put("name", locale.getDisplayName(requestLocale));
- localeCtx.put("id", locale.toString());
- if (selectedLocale != null && selectedLocale.equals(locale.toString()))
+ String localeString = locale.toString();
+ localeCtx.put("id", localeString);
+ if (selectedLocale != null && selectedLocale.equals(localeString))
{
localeCtx.put("selected", "selected");
}
@@ -954,7 +955,7 @@
{
Locale locale = LocaleFormat.DEFAULT.getLocale(localeParam);
//setProperty(user, User.INFO_USER_LOCALE, localeInfo.getLocale());
- setProperty(user, User.INFO_USER_LOCALE, locale.toString());
+ setProperty(user, User.INFO_USER_LOCALE, LocaleFormat.DEFAULT.toString(locale));
}
catch (ConversionException e)
{
18 years, 12 months
JBoss Portal SVN: r7203 - in trunk/common/src/main/org/jboss/portal: test/common and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-05-06 17:01:14 -0400 (Sun, 06 May 2007)
New Revision: 7203
Added:
trunk/common/src/main/org/jboss/portal/common/i18n/AbstractLocaleFormat.java
trunk/common/src/main/org/jboss/portal/common/i18n/CachingLocaleFormat.java
Modified:
trunk/common/src/main/org/jboss/portal/common/i18n/DefaultLocaleFormat.java
trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFormat.java
trunk/common/src/main/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java
trunk/common/src/main/org/jboss/portal/test/common/LocaleFormatTestCase.java
Log:
added LocaleFormat caching using a concurrent hashmap
Added: trunk/common/src/main/org/jboss/portal/common/i18n/AbstractLocaleFormat.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/AbstractLocaleFormat.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/AbstractLocaleFormat.java 2007-05-06 21:01:14 UTC (rev 7203)
@@ -0,0 +1,90 @@
+/******************************************************************************
+ * 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.ConversionException;
+import org.jboss.portal.common.util.NullConversionException;
+import org.jboss.portal.common.io.UndeclaredIOException;
+
+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 AbstractLocaleFormat implements LocaleFormat
+{
+
+ 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;
+
+}
Added: trunk/common/src/main/org/jboss/portal/common/i18n/CachingLocaleFormat.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/CachingLocaleFormat.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/CachingLocaleFormat.java 2007-05-06 21:01:14 UTC (rev 7203)
@@ -0,0 +1,106 @@
+/******************************************************************************
+ * 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.ConversionException;
+
+import java.util.Locale;
+import java.io.Writer;
+import java.io.IOException;
+
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class CachingLocaleFormat implements LocaleFormat
+{
+
+ /** . */
+ private final LocaleFormat delegate;
+
+ /** . */
+ private final ConcurrentHashMap localeCache;
+
+ /** . */
+ private final ConcurrentHashMap stringCache;
+
+ /**
+ * @param delegate the delegate when the cache value has not been found
+ * @throws IllegalArgumentException if the delegate object provided is null
+ */
+ public CachingLocaleFormat(LocaleFormat delegate) throws IllegalArgumentException
+ {
+ if (delegate == null)
+ {
+ throw new IllegalArgumentException("No null delegate is possible");
+ }
+ this.delegate = delegate;
+ this.localeCache = new ConcurrentHashMap();
+ this.stringCache = new ConcurrentHashMap();
+ }
+
+ public Locale getLocale(String value) throws ConversionException
+ {
+ Locale locale = (Locale)localeCache.get(value);
+
+ //
+ if (locale != null)
+ {
+ return locale;
+ }
+ else
+ {
+ locale = delegate.getLocale(value);
+ localeCache.put(value, locale);
+ }
+
+ //
+ return locale;
+ }
+
+ public String toString(Locale locale) throws ConversionException
+ {
+ String string = (String)stringCache.get(locale);
+
+ //
+ if (string != null)
+ {
+ return string;
+ }
+ else
+ {
+ string = delegate.toString(locale);
+ stringCache.put(locale, string);
+ }
+
+ //
+ return string;
+ }
+
+ public void write(Locale locale, Writer writer) throws IOException, ConversionException
+ {
+ delegate.write(locale, writer);
+ }
+}
Modified: trunk/common/src/main/org/jboss/portal/common/i18n/DefaultLocaleFormat.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/DefaultLocaleFormat.java 2007-05-06 19:50:29 UTC (rev 7202)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/DefaultLocaleFormat.java 2007-05-06 21:01:14 UTC (rev 7203)
@@ -25,6 +25,9 @@
import org.jboss.portal.common.util.FormatConversionException;
import java.util.Locale;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
import java.io.Writer;
import java.io.IOException;
@@ -34,10 +37,24 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-class DefaultLocaleFormat extends LocaleFormat
+class DefaultLocaleFormat extends AbstractLocaleFormat
{
/** . */
+ private static final Map CACHE = new HashMap();
+
+ static
+ {
+ for (Iterator i = LocaleManager.getLocales().iterator();i.hasNext();)
+ {
+ Locale locale = (Locale)i.next();
+
+ //
+ CACHE.put(locale.toString(), locale);
+ }
+ }
+
+ /** . */
private LocaleFactory factory;
public DefaultLocaleFormat(LocaleFactory factory)
@@ -52,6 +69,13 @@
protected Locale internalGetLocale(String value) throws FormatConversionException
{
+ Locale locale = (Locale)CACHE.get(value);
+ if (locale != null)
+ {
+ return locale;
+ }
+
+ //
int p1 = value.lastIndexOf('_');
if (p1 < 0)
{
Modified: trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFormat.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFormat.java 2007-05-06 19:50:29 UTC (rev 7202)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/LocaleFormat.java 2007-05-06 21:01:14 UTC (rev 7203)
@@ -22,75 +22,35 @@
******************************************************************************/
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 interface LocaleFormat
{
/** . */
- public static final LocaleFormat RFC3066_LANGUAGE_TAG = new RFC3066LanguageTagLocaleFormat();
+ final LocaleFormat RFC3066_LANGUAGE_TAG = new RFC3066LanguageTagLocaleFormat();
/** . */
- public static final LocaleFormat DEFAULT = new DefaultLocaleFormat();
+ 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);
- }
+ /** . */
+ final LocaleFormat RFC3066_LANGUAGE_TAG_NO_CACHE = new CachingLocaleFormat(new RFC3066LanguageTagLocaleFormat());
- public String toString(Locale locale) throws ConversionException
- {
- if (locale == null)
- {
- throw new NullConversionException("No null locale accepted");
- }
- return internalToString(locale);
- }
+ /** . */
+ final LocaleFormat DEFAULT_NO_CACHE = new CachingLocaleFormat(new DefaultLocaleFormat());
- 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);
- }
+ Locale getLocale(String value) throws ConversionException;
- protected abstract Locale internalGetLocale(String value) throws ConversionException;
+ String toString(Locale locale) 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);
- }
- }
+ void write(Locale locale, Writer writer) throws IOException, ConversionException;
- protected abstract void internalWrite(Locale locale, Writer writer) throws IOException, ConversionException;
-
}
Modified: trunk/common/src/main/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java 2007-05-06 19:50:29 UTC (rev 7202)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/RFC3066LanguageTagLocaleFormat.java 2007-05-06 21:01:14 UTC (rev 7203)
@@ -35,7 +35,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-class RFC3066LanguageTagLocaleFormat extends LocaleFormat
+class RFC3066LanguageTagLocaleFormat extends AbstractLocaleFormat
{
/**
Modified: trunk/common/src/main/org/jboss/portal/test/common/LocaleFormatTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/LocaleFormatTestCase.java 2007-05-06 19:50:29 UTC (rev 7202)
+++ trunk/common/src/main/org/jboss/portal/test/common/LocaleFormatTestCase.java 2007-05-06 21:01:14 UTC (rev 7203)
@@ -25,8 +25,14 @@
import junit.framework.TestCase;
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;
+import org.jboss.portal.common.i18n.CachingLocaleFormat;
+import org.jboss.portal.common.i18n.AbstractLocaleFormat;
import org.jboss.portal.common.util.FormatConversionException;
import org.jboss.portal.common.util.ConversionException;
@@ -39,13 +45,13 @@
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(""));
+ assertEquals(new Locale("a"), LocaleFormat.DEFAULT_NO_CACHE.getLocale("a"));
+ assertEquals(new Locale("a", "b"), LocaleFormat.DEFAULT_NO_CACHE.getLocale("a_b"));
+ assertEquals(new Locale("", "b"), LocaleFormat.DEFAULT_NO_CACHE.getLocale("_b"));
+ assertEquals(new Locale("a", "b", "c"), LocaleFormat.DEFAULT_NO_CACHE.getLocale("a_b_c"));
+ assertEquals(new Locale("a", "", "b"), LocaleFormat.DEFAULT_NO_CACHE.getLocale("a__b"));
+ assertEquals(new Locale("", "a", "b"), LocaleFormat.DEFAULT_NO_CACHE.getLocale("_a_b"));
+ assertEquals(new Locale(""), LocaleFormat.DEFAULT_NO_CACHE.getLocale(""));
//
try
@@ -58,7 +64,7 @@
}
try
{
- assertEquals(new Locale("", "", ""), LocaleFormat.DEFAULT.getLocale("__"));
+ assertEquals(new Locale("", "", ""), LocaleFormat.DEFAULT_NO_CACHE.getLocale("__"));
fail();
}
catch (ConversionException expected)
@@ -76,34 +82,34 @@
public void testToStringFromDefaultFormat() throws ConversionException
{
- assertEquals("a", LocaleFormat.DEFAULT.toString(new Locale("a")));
- assertEquals("", LocaleFormat.DEFAULT.toString(new Locale("")));
+ assertEquals("a", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("a")));
+ assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.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("", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("", "")));
+ assertEquals("a_B", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("a", "b")));
+ assertEquals("a", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("a", "")));
+ assertEquals("_A", LocaleFormat.DEFAULT_NO_CACHE.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("", "", "")));
+ assertEquals("a_B_c", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("a", "b", "c")));
+ assertEquals("_A_b", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("", "a", "b")));
+ assertEquals("a__b", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("a", "", "b")));
+ assertEquals("a_B", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("a", "b", "")));
+ assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("", "", "a")));
+ assertEquals("a", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("a", "", "")));
+ assertEquals("_A", LocaleFormat.DEFAULT_NO_CACHE.toString(new Locale("", "a", "")));
+ assertEquals("", LocaleFormat.DEFAULT_NO_CACHE.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"));
+ assertEquals(new Locale("en"), LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("en"));
+ assertEquals(new Locale("en", "US"), LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("en-US"));
try
{
- LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("wrong");
+ LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("wrong");
fail("Should have failed since an invalid String was passed.");
}
catch (FormatConversionException e)
@@ -113,7 +119,7 @@
try
{
- LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("zz");
+ LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("zz");
fail("Should have failed since an invalid language code was passed.");
}
catch (FormatConversionException e)
@@ -123,7 +129,7 @@
try
{
- LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("fr-ZZ");
+ LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.getLocale("fr-ZZ");
fail("Should have failed since an invalid country code was passed.");
}
catch (FormatConversionException e)
@@ -132,12 +138,80 @@
}
// weird combination should work as well
- LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale("fr-US");
+ LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.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")));
+ assertEquals("en", LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.toString(new Locale("en")));
+ assertEquals("en-US", LocaleFormat.RFC3066_LANGUAGE_TAG_NO_CACHE.toString(new Locale("en", "US")));
}
+
+ public void testCachingLocaleFormat() throws ConversionException
+ {
+ TestLocaleFormat delegate = new TestLocaleFormat();
+ delegate.put(new Locale("abc"), "abc");
+ CachingLocaleFormat format = new CachingLocaleFormat(delegate);
+
+ //
+ assertEquals(new Locale("abc"), format.getLocale("abc"));
+ assertEquals("abc", format.toString(new Locale("abc")));
+
+ //
+ try
+ {
+ format.getLocale("def");
+ fail();
+ }
+ catch (ConversionException e)
+ {
+ }
+
+ //
+ try
+ {
+ format.toString(new Locale("def"));
+ fail();
+ }
+ catch (ConversionException e)
+ {
+ }
+ }
+
+ private static class TestLocaleFormat extends AbstractLocaleFormat
+ {
+
+ /** . */
+ private final Map localeToString = new HashMap();
+
+ /** . */
+ private final Map stringToLocale = new HashMap();
+
+ private void put(Locale locale, String string)
+ {
+ localeToString.put(locale, string);
+ stringToLocale.put(string, locale);
+ }
+
+ protected Locale internalGetLocale(String value) throws ConversionException
+ {
+ Locale locale = (Locale)stringToLocale.get(value);
+ if (locale == null)
+ {
+ throw new ConversionException();
+ }
+ return locale;
+ }
+
+ protected void internalWrite(Locale locale, Writer writer) throws IOException, ConversionException
+ {
+ String string = (String)localeToString.get(locale);
+ if (string == null)
+ {
+ throw new ConversionException();
+ }
+ writer.write(string);
+ }
+ }
+
}
18 years, 12 months
JBoss Portal SVN: r7202 - in trunk/wsrp/src: main/org/jboss/portal/wsrp/producer/config and 2 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-05-06 15:50:29 -0400 (Sun, 06 May 2007)
New Revision: 7202
Added:
trunk/wsrp/src/resources/tests/test-producer-configuration-lib-jar/invalid-type.xml
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/config/ProducerConfigurationTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerConfigurationFactory.java
trunk/wsrp/src/resources/portal-wsrp-sar/dtd/jboss-wsrp-producer_2_6.dtd
Log:
- Updated Producer DTD to reflect the fact that hint and resourceName are optional
- Fixed ProducerConfigurationFactory which should only accept xsd:string property types for now.
- Added test case.
Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/config/ProducerConfigurationTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/config/ProducerConfigurationTestCase.java 2007-05-06 17:21:10 UTC (rev 7201)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/config/ProducerConfigurationTestCase.java 2007-05-06 19:50:29 UTC (rev 7202)
@@ -131,6 +131,15 @@
catch (Exception expected)
{
}
+
+ try
+ {
+ getProducerConfiguration("invalid-type.xml");
+ fail("Invalid type for property description should fail.");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
}
private ProducerConfiguration getProducerConfiguration(String fileName)
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-06 17:21:10 UTC (rev 7201)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerConfigurationFactory.java 2007-05-06 19:50:29 UTC (rev 7202)
@@ -23,13 +23,13 @@
package org.jboss.portal.wsrp.producer.config;
-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.WSRPUtils;
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;
@@ -156,7 +156,12 @@
else if ("type".equals(localName))
{
value = StringPropertyReplacer.replaceProperties(value);
- desc.setType(new QName(value));
+ if (!"xsd:string".equals(value))
+ {
+ throw new IllegalArgumentException("'" + value + "' is not a supported type. Currently, only 'xsd:string' is supported.");
+ }
+
+ desc.setType(WSRPConstants.XSD_STRING);
}
}
Modified: trunk/wsrp/src/resources/portal-wsrp-sar/dtd/jboss-wsrp-producer_2_6.dtd
===================================================================
--- trunk/wsrp/src/resources/portal-wsrp-sar/dtd/jboss-wsrp-producer_2_6.dtd 2007-05-06 17:21:10 UTC (rev 7201)
+++ trunk/wsrp/src/resources/portal-wsrp-sar/dtd/jboss-wsrp-producer_2_6.dtd 2007-05-06 19:50:29 UTC (rev 7202)
@@ -60,16 +60,16 @@
<registration-property-description>
<name>name1</name>
<type>xsd:string</type>
+ <label xml:lang="en" resourceName="resource.label1">label1</label>
<hint xml:lang="en" resourceName="resource.hint1">hint1</hint>
- <label xml:lang="en" resourceName="resource.label1">label1</label>
</registration-property-description>
-->
-<!ELEMENT registration-property-description ( name, type, hint, label )>
+<!ELEMENT registration-property-description ( name, type, label, hint? )>
<!-- The name of the registration property -->
<!ELEMENT name ( #PCDATA )>
-<!-- The qualified name of the type of the registration property. As of Portal 2.6, only xml:string is supported. -->
+<!-- The qualified name of the type of the registration property. As of Portal 2.6, only xsd:string is supported. -->
<!ELEMENT type ( #PCDATA )>
<!-- A description of the registration property and its usage targeted at end users. -->
@@ -77,11 +77,11 @@
<!-- The language in which the hint is written. -->
<!ATTLIST hint xml:lang CDATA #REQUIRED>
<!-- A resource name identifying the hint in localization bundles (currently unsupported in Portal 2.6). -->
-<!ATTLIST hint resourceName CDATA #REQUIRED>
+<!ATTLIST hint resourceName CDATA #IMPLIED>
<!-- A short, human readable name for the property, intended for consumer-generated administration interface. -->
<!ELEMENT label ( #PCDATA )>
<!-- The language in which the label is written. -->
<!ATTLIST label xml:lang CDATA #REQUIRED>
<!-- A resource name identifying the label in localization bundles (currently unsupported in Portal 2.6). -->
-<!ATTLIST label resourceName CDATA #REQUIRED>
+<!ATTLIST label resourceName CDATA #IMPLIED>
Added: trunk/wsrp/src/resources/tests/test-producer-configuration-lib-jar/invalid-type.xml
===================================================================
--- trunk/wsrp/src/resources/tests/test-producer-configuration-lib-jar/invalid-type.xml (rev 0)
+++ trunk/wsrp/src/resources/tests/test-producer-configuration-lib-jar/invalid-type.xml 2007-05-06 19:50:29 UTC (rev 7202)
@@ -0,0 +1,34 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2007, 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<!DOCTYPE producer-configuration PUBLIC "-//JBoss Portal//DTD WSRP Local Producer Configuration 2.6//EN"
+ "http://www.jboss.org/portal/dtd/jboss-wsrp-producer_2_6.dtd">
+
+<producer-configuration>
+ <registration-configuration>
+ <registration-property-description>
+ <name>name</name>
+ <type>unknown type</type>
+ <label xml:lang="en">label</label>
+ </registration-property-description>
+ </registration-configuration>
+</producer-configuration>
18 years, 12 months
JBoss Portal SVN: r7201 - trunk/core/src/main/org/jboss/portal/core/aspects/server.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-05-06 13:21:10 -0400 (Sun, 06 May 2007)
New Revision: 7201
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/server/LocaleInterceptor.java
Log:
- JBPORTAL-1380 : LocaleInterceptor does not build correctly the Locale from the user favorite locale
Modified: trunk/core/src/main/org/jboss/portal/core/aspects/server/LocaleInterceptor.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/aspects/server/LocaleInterceptor.java 2007-05-06 16:33:54 UTC (rev 7200)
+++ trunk/core/src/main/org/jboss/portal/core/aspects/server/LocaleInterceptor.java 2007-05-06 17:21:10 UTC (rev 7201)
@@ -23,6 +23,8 @@
package org.jboss.portal.core.aspects.server;
import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.common.i18n.LocaleFormat;
+import org.jboss.portal.common.util.ConversionException;
import org.jboss.portal.server.ServerInterceptor;
import org.jboss.portal.server.ServerInvocation;
import org.jboss.portal.server.ServerRequest;
@@ -55,24 +57,25 @@
//
if (profile != null)
{
+ Locale locale = null;
Object lc = profile.get(User.INFO_USER_LOCALE);
- Locale locale = null;
if (lc instanceof Locale)
{
locale = (Locale)lc;
}
- else
+ else if (lc != null)
{
try
{
- locale = new Locale(lc.toString());
+ locale = LocaleFormat.DEFAULT.getLocale(lc.toString());
}
- catch (Exception e)
+ catch (ConversionException e)
{
//just to hide failure
}
}
+ //
if (locale != null)
{
locales.add(locale);
18 years, 12 months
JBoss Portal SVN: r7200 - in trunk: common/src/main/org/jboss/portal/common/i18n and 11 other directories.
by portal-commits@lists.jboss.org
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");
19 years
JBoss Portal SVN: r7199 - trunk/core-admin/src/main/org/jboss/portal/core/admin/ui.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-05-05 17:55:31 -0400 (Sat, 05 May 2007)
New Revision: 7199
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
Log:
JBPORTAL-1386 : "Dashboard" permission to a page, then the "Dashboard" link in the upper right of the page is missing.
Modified: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-05-05 17:30:04 UTC (rev 7198)
+++ trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-05-05 21:55:31 UTC (rev 7199)
@@ -583,8 +583,7 @@
new SelectItem("view", "View"),
new SelectItem("viewrecursive", "View Recursive"),
new SelectItem("personalize", "Personalize"),
- new SelectItem("personalizerecursive", "Personalize Recursive"),
- new SelectItem("dashboard", "Dashboard"),
+ new SelectItem("personalizerecursive", "Personalize Recursive")
};
}
19 years