You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2007/02/14 11:49:34 UTC
svn commit: r507480 -
/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxModule.java
Author: andreas
Date: Wed Feb 14 02:49:33 2007
New Revision: 507480
URL: http://svn.apache.org/viewvc?view=rev&rev=507480
Log:
Don't throw NPE when user doesn't exist in InboxModule
Modified:
lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxModule.java
Modified: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxModule.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxModule.java?view=diff&rev=507480&r1=507479&r2=507480
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxModule.java (original)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxModule.java Wed Feb 14 02:49:33 2007
@@ -32,10 +32,15 @@
import org.apache.lenya.cms.repository.Session;
/**
- * <p>Inbox module.</p>
- * <p>Attributes:</p>
+ * <p>
+ * Inbox module.
+ * </p>
+ * <p>
+ * Attributes:
+ * </p>
* <ul>
- * <li><strong>newMessageCount</strong> - the number of unread messages as string</li>
+ * <li><strong>newMessageCount</strong> - the number of unread messages as
+ * string</li>
* </ul>
*/
public class InboxModule extends AbstractInputModule implements Serviceable {
@@ -43,8 +48,9 @@
protected static final String NEW_MESSAGE_COUNT = "newMessageCount";
protected ServiceManager manager;
- public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
-
+ public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+ throws ConfigurationException {
+
Object value = null;
if (name.equals(NEW_MESSAGE_COUNT)) {
InboxManager inboxManager = null;
@@ -53,26 +59,31 @@
Request request = ObjectModelHelper.getRequest(objectModel);
Session session = RepositoryUtil.getSession(manager, request);
User user = session.getIdentity().getUser();
- Inbox inbox = inboxManager.getInbox(user);
-
- int count = 0;
- InboxMessage[] messages = inbox.getMessages();
- for (int i = 0; i < messages.length; i++) {
- if (!messages[i].isMarkedAsRead()) {
- count++;
+ if (user == null) {
+ return "0";
+ } else {
+ Inbox inbox = inboxManager.getInbox(user);
+ int count = 0;
+ InboxMessage[] messages = inbox.getMessages();
+ for (int i = 0; i < messages.length; i++) {
+ if (!messages[i].isMarkedAsRead()) {
+ count++;
+ }
}
+ value = Integer.toString(count);
}
- value = Integer.toString(count);
-
+
} catch (Exception e) {
throw new ConfigurationException("Attribute [" + name + "]: ", e);
- }
- finally {
+ } finally {
if (inboxManager != null) {
this.manager.release(inboxManager);
}
}
}
+ else {
+ throw new ConfigurationException("Attribute: [" + name + "] not supported.");
+ }
return value;
}
@@ -80,6 +91,4 @@
this.manager = manager;
}
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org