1
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
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 }