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