1   /**
2    * Copyright (c) 2000-2007 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.shopping.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.theme.ThemeDisplay;
27  import com.liferay.portal.util.PortalUtil;
28  import com.liferay.portal.util.WebKeys;
29  import com.liferay.portlet.shopping.model.ShoppingCategory;
30  import com.liferay.portlet.shopping.model.ShoppingCoupon;
31  import com.liferay.portlet.shopping.model.ShoppingItem;
32  import com.liferay.portlet.shopping.model.ShoppingOrder;
33  import com.liferay.portlet.shopping.model.impl.ShoppingCategoryImpl;
34  import com.liferay.portlet.shopping.service.ShoppingCategoryServiceUtil;
35  import com.liferay.portlet.shopping.service.ShoppingCouponServiceUtil;
36  import com.liferay.portlet.shopping.service.ShoppingItemServiceUtil;
37  import com.liferay.portlet.shopping.service.ShoppingOrderServiceUtil;
38  
39  import javax.portlet.ActionRequest;
40  import javax.portlet.RenderRequest;
41  
42  import javax.servlet.http.HttpServletRequest;
43  
44  /**
45   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
46   *
47   * @author Brian Wing Shun Chan
48   *
49   */
50  public class ActionUtil {
51  
52      public static void getCategory(ActionRequest req) throws Exception {
53          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
54  
55          getCategory(httpReq);
56      }
57  
58      public static void getCategory(RenderRequest req) throws Exception {
59          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
60  
61          getCategory(httpReq);
62      }
63  
64      public static void getCategory(HttpServletRequest req) throws Exception {
65          long categoryId = ParamUtil.getLong(req, "categoryId");
66  
67          ShoppingCategory category = null;
68  
69          if ((categoryId > 0) &&
70              (categoryId != ShoppingCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
71  
72              category = ShoppingCategoryServiceUtil.getCategory(categoryId);
73          }
74  
75          req.setAttribute(WebKeys.SHOPPING_CATEGORY, category);
76      }
77  
78      public static void getCoupon(ActionRequest req) throws Exception {
79          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
80  
81          getCoupon(httpReq);
82      }
83  
84      public static void getCoupon(RenderRequest req) throws Exception {
85          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
86  
87          getCoupon(httpReq);
88      }
89  
90      public static void getCoupon(HttpServletRequest req) throws Exception {
91          ThemeDisplay themeDisplay =
92              (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
93  
94          long couponId = ParamUtil.getLong(req, "couponId");
95  
96          ShoppingCoupon coupon = null;
97  
98          if (couponId > 0) {
99              coupon = ShoppingCouponServiceUtil.getCoupon(
100                 themeDisplay.getPlid(), couponId);
101         }
102 
103         req.setAttribute(WebKeys.SHOPPING_COUPON, coupon);
104     }
105 
106     public static void getItem(ActionRequest req) throws Exception {
107         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
108 
109         getItem(httpReq);
110     }
111 
112     public static void getItem(RenderRequest req) throws Exception {
113         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
114 
115         getItem(httpReq);
116     }
117 
118     public static void getItem(HttpServletRequest req) throws Exception {
119         long itemId = ParamUtil.getLong(req, "itemId");
120 
121         ShoppingItem item = null;
122 
123         if (itemId > 0) {
124             item = ShoppingItemServiceUtil.getItem(itemId);
125         }
126 
127         req.setAttribute(WebKeys.SHOPPING_ITEM, item);
128     }
129 
130     public static void getOrder(ActionRequest req) throws Exception {
131         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
132 
133         getOrder(httpReq);
134     }
135 
136     public static void getOrder(RenderRequest req) throws Exception {
137         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
138 
139         getOrder(httpReq);
140     }
141 
142     public static void getOrder(HttpServletRequest req) throws Exception {
143         ThemeDisplay themeDisplay =
144             (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
145 
146         long orderId = ParamUtil.getLong(req, "orderId");
147 
148         ShoppingOrder order = null;
149 
150         if (orderId > 0) {
151             order = ShoppingOrderServiceUtil.getOrder(
152                 themeDisplay.getPlid(), orderId);
153         }
154 
155         req.setAttribute(WebKeys.SHOPPING_ORDER, order);
156     }
157 
158 }