001
014
015 package com.liferay.portal.events;
016
017 import com.liferay.portal.kernel.events.Action;
018 import com.liferay.portal.kernel.events.ActionException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.struts.LastPath;
022 import com.liferay.portal.kernel.util.HtmlUtil;
023 import com.liferay.portal.kernel.util.PropsKeys;
024 import com.liferay.portal.kernel.util.StringPool;
025 import com.liferay.portal.kernel.util.StringUtil;
026 import com.liferay.portal.kernel.util.Validator;
027 import com.liferay.portal.model.User;
028 import com.liferay.portal.util.PortalUtil;
029 import com.liferay.portal.util.PrefsPropsUtil;
030 import com.liferay.portal.util.WebKeys;
031
032 import javax.servlet.http.HttpServletRequest;
033 import javax.servlet.http.HttpServletResponse;
034 import javax.servlet.http.HttpSession;
035
036
039 public class DefaultLandingPageAction extends Action {
040
041 @Override
042 public void run(HttpServletRequest request, HttpServletResponse response)
043 throws ActionException {
044
045 try {
046 doRun(request, response);
047 }
048 catch (Exception e) {
049 throw new ActionException(e);
050 }
051 }
052
053 protected void doRun(
054 HttpServletRequest request, HttpServletResponse response)
055 throws Exception {
056
057 long companyId = PortalUtil.getCompanyId(request);
058
059 String path = PrefsPropsUtil.getString(
060 companyId, PropsKeys.DEFAULT_LANDING_PAGE_PATH);
061
062 if (_log.isInfoEnabled()) {
063 _log.info(
064 PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL + path);
065 }
066
067 if (Validator.isNull(path)) {
068 return;
069 }
070
071 HttpSession session = request.getSession();
072
073 if (path.contains("${liferay:screenName}") ||
074 path.contains("${liferay:userId}")) {
075
076 User user = (User)session.getAttribute(WebKeys.USER);
077
078 if (user == null) {
079 return;
080 }
081
082 path = StringUtil.replace(
083 path,
084 new String[] {"${liferay:screenName}", "${liferay:userId}"},
085 new String[] {
086 HtmlUtil.escapeURL(user.getScreenName()),
087 String.valueOf(user.getUserId())
088 });
089 }
090
091 LastPath lastPath = new LastPath(StringPool.BLANK, path);
092
093 session.setAttribute(WebKeys.LAST_PATH, lastPath);
094
095
096
097
098
099
100
107 }
108
109 private static Log _log = LogFactoryUtil.getLog(
110 DefaultLandingPageAction.class);
111
112 }