KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > blogs > actions > GetUserInfoAction


1 /*
2  * ____.
3  * __/\ ______| |__/\. _______
4  * __ .____| | \ | +----+ \
5  * _______| /--| | | - \ _ | : - \_________
6  * \\______: :---| : : | : | \________>
7  * |__\---\_____________:______: :____|____:_____\
8  * /_____|
9  *
10  * . . . i n j a h i a w e t r u s t . . .
11  *
12  *
13  *
14  * ----- BEGIN LICENSE BLOCK -----
15  * Version: JCSL 1.0
16  *
17  * The contents of this file are subject to the Jahia Community Source License
18  * 1.0 or later (the "License"); you may not use this file except in
19  * compliance with the License. You may obtain a copy of the License at
20  * http://www.jahia.org/license
21  *
22  * Software distributed under the License is distributed on an "AS IS" basis,
23  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
24  * for the rights, obligations and limitations governing use of the contents
25  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
26  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
27  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
28  *
29  * The Shared Modifications are Jahia View Helper.
30  *
31  * The Developer of the Shared Modifications is Jahia Solution Sàrl.
32  * Portions created by the Initial Developer are Copyright (C) 2002 by the
33  * Initial Developer. All Rights Reserved.
34  *
35  * ----- END LICENSE BLOCK -----
36  */

37
38 package org.jahia.blogs.actions;
39
40 import org.jahia.blogs.model.UserInfo;
41
42 import org.jahia.services.usermanager.JahiaUser;
43
44 import org.jahia.exceptions.JahiaException;
45
46 import org.apache.log4j.Logger;
47
48 import java.util.Hashtable JavaDoc;
49
50 /**
51  * Action used to get a user's information from the Jahia content repository.
52  * Compliant with Blogger API's getUserInfo method.
53  *
54  * @author Xavier Lawrence
55  */

56 public class GetUserInfoAction extends AbstractAction {
57     
58     // log4j logger
59
static Logger log = Logger.getLogger(GetUserInfoAction.class);
60     
61     /** Creates a new instance of GetUserInfoAction */
62     public GetUserInfoAction(String JavaDoc appKey, String JavaDoc userName, String JavaDoc password) {
63         super.appKey = appKey;
64         super.userName = userName;
65         super.password = password;
66     }
67
68     /**
69      * Authenticates a user and returns basic user info (nickName, firstName,
70      * lastName, url and email).
71      *
72      * @return A Hashtable containing the user information
73      */

74     public Object JavaDoc execute() throws JahiaException {
75         
76         // Create commmon resources
77
super.init();
78         
79         // First check that the user is registered to this site.
80
JahiaUser user = super.checkLogin();
81         
82         if (user == null) {
83             throw new JahiaException("User: "+userName+
84                     " does not exist", "User: "+userName+ " does not exist",
85                     JahiaException.ENTRY_NOT_FOUND,
86                     JahiaException.WARNING_SEVERITY);
87         }
88         
89         Hashtable JavaDoc userInfo = new Hashtable JavaDoc(6);
90         
91         userInfo.put(UserInfo.USER_ID, user.getUsername());
92         userInfo.put(UserInfo.NICKNAME, user.getUsername());
93         userInfo.put(UserInfo.URL, "");
94         userInfo.put(UserInfo.EMAIL, user.getUserProperty("email").getValue());
95         userInfo.put(UserInfo.LASTNAME, user.getUserProperty("lastname").getValue());
96         userInfo.put(UserInfo.FIRSTNAME, user.getUserProperty("firstname").getValue());
97         
98         log.debug("Returning userInfo: "+userInfo);
99         return userInfo;
100     }
101 }
102
Popular Tags