001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }