001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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.PropsKeys;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portal.kernel.util.Validator;
025    import com.liferay.portal.util.PortalUtil;
026    import com.liferay.portal.util.PrefsPropsUtil;
027    import com.liferay.portal.util.WebKeys;
028    
029    import javax.servlet.http.HttpServletRequest;
030    import javax.servlet.http.HttpServletResponse;
031    import javax.servlet.http.HttpSession;
032    
033    /**
034     * @author Michael Young
035     */
036    public class DefaultLandingPageAction extends Action {
037    
038            @Override
039            public void run(HttpServletRequest request, HttpServletResponse response)
040                    throws ActionException {
041    
042                    try {
043                            doRun(request, response);
044                    }
045                    catch (Exception e) {
046                            throw new ActionException(e);
047                    }
048            }
049    
050            protected void doRun(
051                            HttpServletRequest request, HttpServletResponse response)
052                    throws Exception {
053    
054                    long companyId = PortalUtil.getCompanyId(request);
055    
056                    String path = PrefsPropsUtil.getString(
057                            companyId, PropsKeys.DEFAULT_LANDING_PAGE_PATH);
058    
059                    if (_log.isInfoEnabled()) {
060                            _log.info(
061                                    PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL + path);
062                    }
063    
064                    if (Validator.isNotNull(path)) {
065                            LastPath lastPath = new LastPath(StringPool.BLANK, path);
066    
067                            HttpSession session = request.getSession();
068    
069                            session.setAttribute(WebKeys.LAST_PATH, lastPath);
070                    }
071    
072                    // The commented code shows how you can programmaticaly set the user's
073                    // landing page. You can modify this class to utilize a custom algorithm
074                    // for forwarding a user to his landing page. See the references to this
075                    // class in portal.properties.
076    
077                    /*Map<String, String[]> params = new HashMap<String, String[]>();
078    
079                    params.put("p_l_id", new String[] {"1806"});
080    
081                    LastPath lastPath = new LastPath("/c", "/portal/layout", params);
082    
083                    session.setAttribute(WebKeys.LAST_PATH, lastPath);*/
084            }
085    
086            private static Log _log = LogFactoryUtil.getLog(
087                    DefaultLandingPageAction.class);
088    
089    }