1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.bookmarks.action;
16  
17  import com.liferay.portal.kernel.util.ParamUtil;
18  import com.liferay.portal.util.PortalUtil;
19  import com.liferay.portal.util.WebKeys;
20  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
21  import com.liferay.portlet.bookmarks.model.BookmarksFolder;
22  import com.liferay.portlet.bookmarks.service.BookmarksEntryServiceUtil;
23  import com.liferay.portlet.bookmarks.service.BookmarksFolderServiceUtil;
24  
25  import javax.portlet.ActionRequest;
26  import javax.portlet.RenderRequest;
27  
28  import javax.servlet.http.HttpServletRequest;
29  
30  /**
31   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class ActionUtil {
36  
37      public static void getFolder(ActionRequest actionRequest) throws Exception {
38          HttpServletRequest request = PortalUtil.getHttpServletRequest(
39              actionRequest);
40  
41          getFolder(request);
42      }
43  
44      public static void getFolder(RenderRequest renderRequest) throws Exception {
45          HttpServletRequest request = PortalUtil.getHttpServletRequest(
46              renderRequest);
47  
48          getFolder(request);
49      }
50  
51      public static void getFolder(HttpServletRequest request) throws Exception {
52          long folderId = ParamUtil.getLong(request, "folderId");
53  
54          BookmarksFolder folder = null;
55  
56          if (folderId > 0) {
57              folder = BookmarksFolderServiceUtil.getFolder(folderId);
58          }
59  
60          request.setAttribute(WebKeys.BOOKMARKS_FOLDER, folder);
61      }
62  
63      public static void getEntry(ActionRequest actionRequest) throws Exception {
64          HttpServletRequest request = PortalUtil.getHttpServletRequest(
65              actionRequest);
66  
67          getEntry(request);
68      }
69  
70      public static void getEntry(RenderRequest renderRequest) throws Exception {
71          HttpServletRequest request = PortalUtil.getHttpServletRequest(
72              renderRequest);
73  
74          getEntry(request);
75      }
76  
77      public static void getEntry(HttpServletRequest request) throws Exception {
78          long entryId = ParamUtil.getLong(request, "entryId");
79  
80          BookmarksEntry entry = null;
81  
82          if (entryId > 0) {
83              entry = BookmarksEntryServiceUtil.getEntry(entryId);
84          }
85  
86          request.setAttribute(WebKeys.BOOKMARKS_ENTRY, entry);
87      }
88  
89  }