Author: chris.laprun(a)jboss.com
Date: 2007-02-13 22:53:20 -0500 (Tue, 13 Feb 2007)
New Revision: 6262
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java
Modified:
trunk/wsrp/build.xml
trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
Log:
- JBPORTAL-1260: Use JBoss XB to correctly parse xsd:dateTime.
- Added simple test case.
Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml 2007-02-14 00:30:34 UTC (rev 6261)
+++ trunk/wsrp/build.xml 2007-02-14 03:53:20 UTC (rev 6262)
@@ -573,7 +573,7 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.v1.producer.MarkupTestRunner"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.v1.producer.RegistrationTestRunner"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.v1.producer.PortletManagementTestRunner"/>
- </x-test>
+ </x-test>
<x-sysproperty>
<!--
<jvmarg value="-Xdebug"/>
@@ -678,6 +678,7 @@
<x-test>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.ProducerSessionInformationTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.WSRPPortletURLTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.UserContextConverterTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.handler.RequestHeaderClientHandlerTestCase"/>
</x-test>
<x-sysproperty>
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java
(rev 0)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java 2007-02-14
03:53:20 UTC (rev 6262)
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+
+package org.jboss.portal.test.wsrp.other;
+
+import junit.framework.TestCase;
+import org.jboss.xb.binding.SimpleTypeBindings;
+
+import java.util.Calendar;
+
+/**
+ * Needs more complete tests!!
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class UserContextConverterTestCase extends TestCase
+{
+ public void testDateFormat()
+ {
+ String dateAsString = "1983-12-11T00:00:00.000+01:00";
+ Calendar bdate = SimpleTypeBindings.unmarshalDateTime(dateAsString);
+ String result = SimpleTypeBindings.marshalDateTime(bdate);
+ assertEquals(dateAsString, result);
+ }
+}
Property changes on:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java 2007-02-14
00:30:34 UTC (rev 6261)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java 2007-02-14
03:53:20 UTC (rev 6262)
@@ -34,14 +34,11 @@
import org.jboss.portal.wsrp.core.Telecom;
import org.jboss.portal.wsrp.core.TelephoneNum;
import org.jboss.portal.wsrp.core.UserProfile;
+import org.jboss.xb.binding.SimpleTypeBindings;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -54,7 +51,7 @@
*/
public class UserContextConverter
{
- public static final String XSD_DATETIME_FORMAT =
"yyy-MM-dd'T'HH:mm:ss";
+ public static final String XSD_DATETIME_FORMAT =
"yyy-MM-dd'T'HH:mm:ss.SSSZ";
public static UserContext
createPortalUserContextFrom(org.jboss.portal.wsrp.core.UserContext userContext,
String[] desiredLocales, String
preferredLocale)
@@ -87,19 +84,7 @@
String bdateAsString = (String)userInfos.get(P3PConstants.INFO_USER_BDATE);
if (bdateAsString != null)
{
- Locale locale = userContext.getLocale();
- SimpleDateFormat format = new SimpleDateFormat(XSD_DATETIME_FORMAT, locale);
- format.setLenient(false); // should maybe make it lenient?
- try
- {
- Date date = format.parse(bdateAsString);
- bdate = Calendar.getInstance(locale);
- bdate.setTime(date);
- }
- catch (ParseException e)
- {
- throw new IllegalArgumentException(bdateAsString + " is not a valid
birthday date!");
- }
+ bdate = SimpleTypeBindings.unmarshalDateTime(bdateAsString);
}
EmployerInfo employerInfo = new
EmployerInfo((String)userInfos.get(P3PConstants.INFO_USER_EMPLOYER),
@@ -185,8 +170,7 @@
Calendar bdate = profile.getBdate();
if (bdate != null)
{
- DateFormat dateFormat = new SimpleDateFormat(XSD_DATETIME_FORMAT,
getLocale());
- infos.put(P3PConstants.INFO_USER_BDATE, dateFormat.format(bdate));
+ infos.put(P3PConstants.INFO_USER_BDATE,
SimpleTypeBindings.marshalDateTime(bdate));
}
infos.put(P3PConstants.INFO_USER_GENDER, profile.getGender());