Author: sdumitriu
Date: 2008-02-08 16:49:06 +0100 (Fri, 08 Feb 2008)
New Revision: 7399

Modified:
   
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/api/User.java
Log:
XWIKI-2088: Add a method to retrieve the e-mail address of a user
Done.
Patch submitted by Marius Florea, applied with minor javadoc changes.


Modified: 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/api/User.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/api/User.java
    2008-02-08 15:25:56 UTC (rev 7398)
+++ 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/api/User.java
    2008-02-08 15:49:06 UTC (rev 7399)
@@ -1,54 +1,76 @@
-/*
- * See the NOTICE file distributed with this work for additional
- * information regarding copyright ownership.
- *
- * 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 com.xpn.xwiki.api;
-
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.user.api.XWikiGroupService;
-import com.xpn.xwiki.user.api.XWikiUser;
-
-import java.util.Collection;
-
-public class User extends Api
-{
-    private XWikiUser user;
-
-    public User(XWikiUser user, XWikiContext context)
-    {
-        super(context);
-        this.user = user;
-    }
-
-    public XWikiUser getUser()
-    {
-        if (hasProgrammingRights()) {
-            return user;
-        }
-        return null;
-    }
-
-    public boolean isUserInGroup(String groupName) throws XWikiException
-    {
-        XWikiGroupService groupService = 
getXWikiContext().getWiki().getGroupService(getXWikiContext());
-        Collection groups = groupService.listGroupsForUser(user.getUser(), 
getXWikiContext());
-        return groups.contains(groupName);
-    }
-}
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * 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 com.xpn.xwiki.api;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.objects.BaseObject;
+import com.xpn.xwiki.user.api.XWikiGroupService;
+import com.xpn.xwiki.user.api.XWikiUser;
+
+import java.util.Collection;
+
+public class User extends Api
+{
+    private XWikiUser user;
+
+    public User(XWikiUser user, XWikiContext context)
+    {
+        super(context);
+        this.user = user;
+    }
+
+    public XWikiUser getUser()
+    {
+        if (hasProgrammingRights()) {
+            return user;
+        }
+        return null;
+    }
+
+    public boolean isUserInGroup(String groupName) throws XWikiException
+    {
+        XWikiGroupService groupService = 
getXWikiContext().getWiki().getGroupService(getXWikiContext());
+        Collection groups = groupService.listGroupsForUser(user.getUser(), 
getXWikiContext());
+        return groups.contains(groupName);
+    }
+
+    /**
+     * API to retrieve the e-mail address of this user. This e-mail address is 
taken from the user
+     * profile. If the user hasn't changed his profile, then this is the 
e-mail address he filled in
+     * the registration form.
+     * 
+     * @return The e-mail address from the user profile, or <tt>null</tt> if 
there is an error
+     *         retrieving the email.
+     */
+    public String getEmail()
+    {
+        XWikiDocument userDoc;
+        try {
+            userDoc = getXWikiContext().getWiki().getDocument(user.getUser(), 
getXWikiContext());
+            BaseObject obj = userDoc.getObject("XWiki.XWikiUsers");
+            return obj.getStringValue("email");
+        } catch (Exception e) {
+            return null;
+        }
+    }
+}

_______________________________________________
notifications mailing list
notifications@xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to