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   */
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 }