1
19
20 package com.liferay.portlet.blogs.action;
21
22 import com.liferay.portal.kernel.util.ParamUtil;
23 import com.liferay.portal.kernel.util.StringPool;
24 import com.liferay.portal.kernel.util.StringUtil;
25 import com.liferay.portal.kernel.util.Validator;
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.blogs.NoSuchEntryException;
30 import com.liferay.portlet.blogs.model.BlogsEntry;
31 import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
32
33 import javax.portlet.ActionRequest;
34 import javax.portlet.RenderRequest;
35
36 import javax.servlet.http.HttpServletRequest;
37
38
44 public class ActionUtil {
45
46 public static void getEntry(ActionRequest actionRequest) throws Exception {
47 HttpServletRequest request = PortalUtil.getHttpServletRequest(
48 actionRequest);
49
50 getEntry(request);
51 }
52
53 public static void getEntry(RenderRequest renderRequest) throws Exception {
54 HttpServletRequest request = PortalUtil.getHttpServletRequest(
55 renderRequest);
56
57 getEntry(request);
58 }
59
60 public static void getEntry(HttpServletRequest request) throws Exception {
61 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
62 WebKeys.THEME_DISPLAY);
63
64 long entryId = ParamUtil.getLong(request, "entryId");
65
66 String urlTitle = ParamUtil.getString(request, "urlTitle");
67
68 BlogsEntry entry = null;
69
70 if (entryId > 0) {
71 entry = BlogsEntryServiceUtil.getEntry(entryId);
72 }
73 else if (Validator.isNotNull(urlTitle)) {
74 try {
75 entry = BlogsEntryServiceUtil.getEntry(
76 themeDisplay.getScopeGroupId(), urlTitle);
77 }
78 catch (NoSuchEntryException nsee) {
79 if (urlTitle.indexOf(StringPool.UNDERLINE) != -1) {
80
81
84 urlTitle = StringUtil.replace(
85 urlTitle, StringPool.UNDERLINE, StringPool.DASH);
86
87 entry = BlogsEntryServiceUtil.getEntry(
88 themeDisplay.getScopeGroupId(), urlTitle);
89 }
90 else {
91 throw nsee;
92 }
93 }
94 }
95
96 request.setAttribute(WebKeys.BLOGS_ENTRY, entry);
97 }
98
99 }