1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portlet.imagegallery.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.imagegallery.model.IGFolder;
21  import com.liferay.portlet.imagegallery.model.IGImage;
22  import com.liferay.portlet.imagegallery.model.impl.IGFolderImpl;
23  import com.liferay.portlet.imagegallery.service.IGFolderServiceUtil;
24  import com.liferay.portlet.imagegallery.service.IGImageServiceUtil;
25  
26  import javax.portlet.ActionRequest;
27  import javax.portlet.RenderRequest;
28  
29  import javax.servlet.http.HttpServletRequest;
30  
31  /**
32   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class ActionUtil {
37  
38      public static void getFolder(ActionRequest actionRequest) throws Exception {
39          HttpServletRequest request = PortalUtil.getHttpServletRequest(
40              actionRequest);
41  
42          getFolder(request);
43      }
44  
45      public static void getFolder(RenderRequest renderRequest) throws Exception {
46          HttpServletRequest request = PortalUtil.getHttpServletRequest(
47              renderRequest);
48  
49          getFolder(request);
50      }
51  
52      public static void getFolder(HttpServletRequest request) throws Exception {
53          long folderId = ParamUtil.getLong(request, "folderId");
54  
55          IGFolder folder = null;
56  
57          if ((folderId > 0) &&
58              (folderId != IGFolderImpl.DEFAULT_PARENT_FOLDER_ID)) {
59  
60              folder = IGFolderServiceUtil.getFolder(folderId);
61          }
62  
63          request.setAttribute(WebKeys.IMAGE_GALLERY_FOLDER, folder);
64      }
65  
66      public static void getImage(ActionRequest actionRequest) throws Exception {
67          HttpServletRequest request = PortalUtil.getHttpServletRequest(
68              actionRequest);
69  
70          getImage(request);
71      }
72  
73      public static void getImage(RenderRequest renderRequest) throws Exception {
74          HttpServletRequest request = PortalUtil.getHttpServletRequest(
75              renderRequest);
76  
77          getImage(request);
78      }
79  
80      public static void getImage(HttpServletRequest request) throws Exception {
81          long imageId = ParamUtil.getLong(request, "imageId");
82  
83          IGImage image = null;
84  
85          if (imageId > 0) {
86              image = IGImageServiceUtil.getImage(imageId);
87          }
88  
89          request.setAttribute(WebKeys.IMAGE_GALLERY_IMAGE, image);
90      }
91  
92  }