forked from liferay/liferay-portal
/
DefaultLandingPageAction.java
105 lines (81 loc) · 2.94 KB
/
DefaultLandingPageAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.portal.events;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.struts.LastPath;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.PrefsPropsUtil;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* @author Michael Young
*/
public class DefaultLandingPageAction extends Action {
@Override
public void run(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse)
throws ActionException {
try {
doRun(httpServletRequest, httpServletResponse);
}
catch (Exception exception) {
throw new ActionException(exception);
}
}
protected void doRun(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse)
throws Exception {
String path = PrefsPropsUtil.getString(
PortalUtil.getCompanyId(httpServletRequest),
PropsKeys.DEFAULT_LANDING_PAGE_PATH);
if (_log.isInfoEnabled()) {
_log.info(
PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL + path);
}
if (Validator.isNull(path)) {
return;
}
HttpSession httpSession = httpServletRequest.getSession();
if (path.contains("${liferay:screenName}") ||
path.contains("${liferay:userId}")) {
User user = (User)httpSession.getAttribute(WebKeys.USER);
if (user == null) {
return;
}
path = StringUtil.replace(
path,
new String[] {"${liferay:screenName}", "${liferay:userId}"},
new String[] {
HtmlUtil.escapeURL(user.getScreenName()),
String.valueOf(user.getUserId())
});
}
LastPath lastPath = new LastPath(StringPool.BLANK, path);
httpSession.setAttribute(WebKeys.LAST_PATH, lastPath);
// The commented code shows how you can programmaticaly set the user's
// landing page. You can modify this class to utilize a custom algorithm
// for forwarding a user to his landing page. See the references to this
// class in portal.properties.
/*Map<String, String[]> params = new HashMap<>();
params.put("p_l_id", new String[] {"1806"});
LastPath lastPath = new LastPath("/c", "/portal/layout", params);
httpSession.setAttribute(WebKeys.LAST_PATH, lastPath);*/
}
private static final Log _log = LogFactoryUtil.getLog(
DefaultLandingPageAction.class);
}