1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class ActionUtil {
45  
46      public static void getFolder(ActionRequest actionRequest) throws Exception {
47          HttpServletRequest request = PortalUtil.getHttpServletRequest(
48              actionRequest);
49  
50          getFolder(request);
51      }
52  
53      public static void getFolder(RenderRequest renderRequest) throws Exception {
54          HttpServletRequest request = PortalUtil.getHttpServletRequest(
55              renderRequest);
56  
57          getFolder(request);
58      }
59  
60      public static void getFolder(HttpServletRequest request) throws Exception {
61          long folderId = ParamUtil.getLong(request, "folderId");
62  
63          IGFolder folder = null;
64  
65          if ((folderId > 0) &&
66              (folderId != IGFolderImpl.DEFAULT_PARENT_FOLDER_ID)) {
67  
68              folder = IGFolderServiceUtil.getFolder(folderId);
69          }
70  
71          request.setAttribute(WebKeys.IMAGE_GALLERY_FOLDER, folder);
72      }
73  
74      public static void getImage(ActionRequest actionRequest) throws Exception {
75          HttpServletRequest request = PortalUtil.getHttpServletRequest(
76              actionRequest);
77  
78          getImage(request);
79      }
80  
81      public static void getImage(RenderRequest renderRequest) throws Exception {
82          HttpServletRequest request = PortalUtil.getHttpServletRequest(
83              renderRequest);
84  
85          getImage(request);
86      }
87  
88      public static void getImage(HttpServletRequest request) throws Exception {
89          long imageId = ParamUtil.getLong(request, "imageId");
90  
91          IGImage image = null;
92  
93          if (imageId > 0) {
94              image = IGImageServiceUtil.getImage(imageId);
95          }
96  
97          request.setAttribute(WebKeys.IMAGE_GALLERY_IMAGE, image);
98      }
99  
100 }