Author: chris.laprun(a)jboss.com
Date: 2009-10-13 09:27:59 -0400 (Tue, 13 Oct 2009)
New Revision: 338
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/UserContextConverter.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
Log:
- Avoid NPEs.
- Provide a dummy implementation of RenderURL.getPublicNavigationalStateChanges so that
GateIn doesn't crash.
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/UserContextConverter.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/UserContextConverter.java 2009-10-13
12:32:13 UTC (rev 337)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/UserContextConverter.java 2009-10-13
13:27:59 UTC (rev 338)
@@ -68,7 +68,10 @@
{
org.oasis.wsrp.v1.UserContext wsrpUserContext =
WSRPTypeFactory.createUserContext(userContextKey);
wsrpUserContext.setProfile(createUserProfileFrom(userContext));
- wsrpUserContext.getUserCategories().addAll(userCategories);
+ if (WSRPTypeFactory.existsAndIsNotEmpty(userCategories))
+ {
+ wsrpUserContext.getUserCategories().addAll(userCategories);
+ }
return wsrpUserContext;
}
@@ -76,7 +79,7 @@
{
Map<String, String> userInfos = userContext.getInformations();
- if (userInfos == null || userInfos.isEmpty())
+ if (!WSRPTypeFactory.existsAndIsNotEmpty(userInfos))
{
return null;
}
@@ -169,8 +172,7 @@
}
/**
- * Builds a Portal {@link org.gatein.pc.api.spi.UserContext} from a WSRP {@link
- * org.oasis.wsrp.v1.UserContext}.
+ * Builds a Portal {@link org.gatein.pc.api.spi.UserContext} from a WSRP {@link
org.oasis.wsrp.v1.UserContext}.
*
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @since 2.4 (May 8, 2006)
@@ -300,21 +302,19 @@
public List<Locale> getLocales()
{
- int length = desiredLocales.size();
- if (length > 0)
+ List<Locale> locales = Collections.emptyList();
+
+ if (WSRPTypeFactory.existsAndIsNotEmpty(desiredLocales))
{
- List<Locale> locales = new ArrayList<Locale>(length);
+ locales = new ArrayList<Locale>(desiredLocales.size());
for (String desiredLocale : desiredLocales)
{
Locale locale = WSRPUtils.getLocale(desiredLocale);
locales.add(locale);
}
- return locales;
}
- else
- {
- return Collections.emptyList();
- }
+
+ return locales;
}
public Object getAttribute(String arg0)
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2009-10-13
12:32:13 UTC (rev 337)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2009-10-13
13:27:59 UTC (rev 338)
@@ -675,7 +675,8 @@
public Map<String, String[]> getPublicNavigationalStateChanges()
{
- throw new UnsupportedOperationException("getPublicNavigationalStateChanges
is not currently supported!"); // todo: fix me
+ // todo: implement properly
+ return null;
}
public Mode getMode()
@@ -1120,8 +1121,23 @@
return markupType;
}
- private static boolean existsAndIsNotEmpty(Collection collection)
+ /**
+ * @param collection
+ * @return
+ * @deprecated use ParameterValidation.existsAndIsNotEmpty instead
+ */
+ static boolean existsAndIsNotEmpty(Collection collection)
{
return collection != null && !collection.isEmpty();
}
+
+ /**
+ * @param map
+ * @return
+ * @deprecated use ParameterValidation.existsAndIsNotEmpty instead
+ */
+ static boolean existsAndIsNotEmpty(Map map)
+ {
+ return map != null && !map.isEmpty();
+ }
}
Show replies by date