1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.events;
21  
22  import com.liferay.portal.kernel.events.Action;
23  import com.liferay.portal.kernel.events.ActionException;
24  import com.liferay.portal.kernel.log.Log;
25  import com.liferay.portal.kernel.log.LogFactoryUtil;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.portal.struts.LastPath;
29  import com.liferay.portal.util.PortalUtil;
30  import com.liferay.portal.util.PrefsPropsUtil;
31  import com.liferay.portal.util.PropsKeys;
32  import com.liferay.portal.util.WebKeys;
33  
34  import java.util.HashMap;
35  
36  import javax.servlet.http.HttpServletRequest;
37  import javax.servlet.http.HttpServletResponse;
38  import javax.servlet.http.HttpSession;
39  
40  /**
41   * <a href="DefaultLandingPageAction.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Michael Young
44   *
45   */
46  public class DefaultLandingPageAction extends Action {
47  
48      public void run(HttpServletRequest request, HttpServletResponse response)
49          throws ActionException {
50  
51          try {
52              doRun(request, response);
53          }
54          catch (Exception e) {
55              throw new ActionException(e);
56          }
57      }
58  
59      protected void doRun(
60              HttpServletRequest request, HttpServletResponse response)
61          throws Exception {
62  
63          long companyId = PortalUtil.getCompanyId(request);
64  
65          String path = PrefsPropsUtil.getString(
66              companyId, PropsKeys.DEFAULT_LANDING_PAGE_PATH);
67  
68          if (_log.isInfoEnabled()) {
69              _log.info(
70                  PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL + path);
71          }
72  
73          if (Validator.isNotNull(path)) {
74              LastPath lastPath = new LastPath(
75                  StringPool.BLANK, path, new HashMap<String, String[]>());
76  
77              HttpSession session = request.getSession();
78  
79              session.setAttribute(WebKeys.LAST_PATH, lastPath);
80          }
81  
82          // The commented code shows how you can programmaticaly set the user's
83          // landing page. You can modify this class to utilize a custom algorithm
84          // for forwarding a user to his landing page. See the references to this
85          // class in portal.properties.
86  
87          /*Map<String, String[]> params = new HashMap<String, String[]>();
88  
89          params.put("p_l_id", new String[] {"1806"});
90  
91          LastPath lastPath = new LastPath("/c", "/portal/layout", params);
92  
93          session.setAttribute(WebKeys.LAST_PATH, lastPath);*/
94      }
95  
96      private static Log _log =
97          LogFactoryUtil.getLog(DefaultLandingPageAction.class);
98  
99  }