1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.imagegallery.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.util.PortalUtil;
27  import com.liferay.portal.util.WebKeys;
28  import com.liferay.portlet.imagegallery.model.IGFolder;
29  import com.liferay.portlet.imagegallery.model.IGImage;
30  import com.liferay.portlet.imagegallery.model.impl.IGFolderImpl;
31  import com.liferay.portlet.imagegallery.service.IGFolderServiceUtil;
32  import com.liferay.portlet.imagegallery.service.IGImageServiceUtil;
33  
34  import javax.portlet.ActionRequest;
35  import javax.portlet.RenderRequest;
36  
37  import javax.servlet.http.HttpServletRequest;
38  
39  /**
40   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class ActionUtil {
46  
47      public static void getFolder(ActionRequest actionRequest) throws Exception {
48          HttpServletRequest request = PortalUtil.getHttpServletRequest(
49              actionRequest);
50  
51          getFolder(request);
52      }
53  
54      public static void getFolder(RenderRequest renderRequest) throws Exception {
55          HttpServletRequest request = PortalUtil.getHttpServletRequest(
56              renderRequest);
57  
58          getFolder(request);
59      }
60  
61      public static void getFolder(HttpServletRequest request) throws Exception {
62          long folderId = ParamUtil.getLong(request, "folderId");
63  
64          IGFolder folder = null;
65  
66          if ((folderId > 0) &&
67              (folderId != IGFolderImpl.DEFAULT_PARENT_FOLDER_ID)) {
68  
69              folder = IGFolderServiceUtil.getFolder(folderId);
70          }
71  
72          request.setAttribute(WebKeys.IMAGE_GALLERY_FOLDER, folder);
73      }
74  
75      public static void getImage(ActionRequest actionRequest) throws Exception {
76          HttpServletRequest request = PortalUtil.getHttpServletRequest(
77              actionRequest);
78  
79          getImage(request);
80      }
81  
82      public static void getImage(RenderRequest renderRequest) throws Exception {
83          HttpServletRequest request = PortalUtil.getHttpServletRequest(
84              renderRequest);
85  
86          getImage(request);
87      }
88  
89      public static void getImage(HttpServletRequest request) throws Exception {
90          long imageId = ParamUtil.getLong(request, "imageId");
91  
92          IGImage image = null;
93  
94          if (imageId > 0) {
95              image = IGImageServiceUtil.getImage(imageId);
96          }
97  
98          request.setAttribute(WebKeys.IMAGE_GALLERY_IMAGE, image);
99      }
100 
101 }