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.blogs.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.theme.ThemeDisplay;
28  import com.liferay.portal.util.PortalUtil;
29  import com.liferay.portal.util.WebKeys;
30  import com.liferay.portlet.blogs.model.BlogsCategory;
31  import com.liferay.portlet.blogs.model.BlogsEntry;
32  import com.liferay.portlet.blogs.service.BlogsCategoryServiceUtil;
33  import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
34  
35  import javax.portlet.ActionRequest;
36  import javax.portlet.RenderRequest;
37  
38  import javax.servlet.http.HttpServletRequest;
39  
40  /**
41   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class ActionUtil {
47  
48      public static void getCategory(ActionRequest req) throws Exception {
49          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
50  
51          getCategory(httpReq);
52      }
53  
54      public static void getCategory(RenderRequest req) throws Exception {
55          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
56  
57          getCategory(httpReq);
58      }
59  
60      public static void getCategory(HttpServletRequest req) throws Exception {
61          long categoryId = ParamUtil.getLong(req, "categoryId");
62  
63          BlogsCategory category = null;
64  
65          if (categoryId > 0) {
66              category = BlogsCategoryServiceUtil.getCategory(categoryId);
67          }
68  
69          req.setAttribute(WebKeys.BLOGS_CATEGORY, category);
70      }
71  
72      public static void getEntry(ActionRequest req) throws Exception {
73          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
74  
75          getEntry(httpReq);
76      }
77  
78      public static void getEntry(RenderRequest req) throws Exception {
79          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
80  
81          getEntry(httpReq);
82      }
83  
84      public static void getEntry(HttpServletRequest req) throws Exception {
85          ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(
86              WebKeys.THEME_DISPLAY);
87  
88          long entryId = ParamUtil.getLong(req, "entryId");
89  
90          String urlTitle = ParamUtil.getString(req, "urlTitle");
91  
92          BlogsEntry entry = null;
93  
94          if (entryId > 0) {
95              entry = BlogsEntryServiceUtil.getEntry(entryId);
96          }
97          else if (Validator.isNotNull(urlTitle)) {
98              entry = BlogsEntryServiceUtil.getEntry(
99                  themeDisplay.getPortletGroupId(), urlTitle);
100         }
101 
102         req.setAttribute(WebKeys.BLOGS_ENTRY, entry);
103     }
104 
105 }