| CustomUserAttributes.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portlet;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19 import com.liferay.portal.kernel.util.Randomizer;
20
21 import java.util.Map;
22
23 /**
24 * <a href="CustomUserAttributes.java.html"><b><i>View Source</i></b></a>
25 *
26 * <p>
27 * A separate instance of this class is created every time
28 * <code>renderRequest.getAttribute(PortletRequest.USER_INFO)</code> is called.
29 * It is safe to cache attributes in this instance because you can assume that
30 * all calls to this instance belong to the same user.
31 * </p>
32 *
33 * @author Brian Wing Shun Chan
34 */
35 public class CustomUserAttributes implements Cloneable {
36
37 public String getValue(String name, Map<String, String> userInfo) {
38 if (name == null) {
39 return null;
40 }
41
42 if (_log.isDebugEnabled()) {
43 String companyId = userInfo.get(UserAttributes.LIFERAY_COMPANY_ID);
44 String userId = userInfo.get(UserAttributes.LIFERAY_USER_ID);
45
46 _log.debug("Company id " + companyId);
47 _log.debug("User id " + userId);
48 }
49
50 if (name.equals("user.name.random")) {
51 String[] names = new String[] {"Aaa", "Bbb", "Ccc"};
52
53 return names[Randomizer.getInstance().nextInt(3)];
54 }
55 else {
56 return null;
57 }
58 }
59
60 public Object clone() {
61 return new CustomUserAttributes();
62 }
63
64 private static Log _log = LogFactoryUtil.getLog(CustomUserAttributes.class);
65
66 }