001    /**
002     * Copyright (c) 2000-2010 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 java.util.HashMap;
030    
031    import javax.servlet.http.HttpServletRequest;
032    import javax.servlet.http.HttpServletResponse;
033    import javax.servlet.http.HttpSession;
034    
035    /**
036     * @author Michael Young
037     */
038    public class DefaultLandingPageAction extends Action {
039    
040            public void run(HttpServletRequest request, HttpServletResponse response)
041                    throws ActionException {
042    
043                    try {
044                            doRun(request, response);
045                    }
046                    catch (Exception e) {
047                            throw new ActionException(e);
048                    }
049            }
050    
051            protected void doRun(
052                            HttpServletRequest request, HttpServletResponse response)
053                    throws Exception {
054    
055                    long companyId = PortalUtil.getCompanyId(request);
056    
057                    String path = PrefsPropsUtil.getString(
058                            companyId, PropsKeys.DEFAULT_LANDING_PAGE_PATH);
059    
060                    if (_log.isInfoEnabled()) {
061                            _log.info(
062                                    PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL + path);
063                    }
064    
065                    if (Validator.isNotNull(path)) {
066                            LastPath lastPath = new LastPath(
067                                    StringPool.BLANK, path, new HashMap<String, String[]>());
068    
069                            HttpSession session = request.getSession();
070    
071                            session.setAttribute(WebKeys.LAST_PATH, lastPath);
072                    }
073    
074                    // The commented code shows how you can programmaticaly set the user's
075                    // landing page. You can modify this class to utilize a custom algorithm
076                    // for forwarding a user to his landing page. See the references to this
077                    // class in portal.properties.
078    
079                    /*Map<String, String[]> params = new HashMap<String, String[]>();
080    
081                    params.put("p_l_id", new String[] {"1806"});
082    
083                    LastPath lastPath = new LastPath("/c", "/portal/layout", params);
084    
085                    session.setAttribute(WebKeys.LAST_PATH, lastPath);*/
086            }
087    
088            private static Log _log = LogFactoryUtil.getLog(
089                    DefaultLandingPageAction.class);
090    
091    }