1
14
15 package com.liferay.portlet.blogs.action;
16
17 import com.liferay.portal.kernel.util.ParamUtil;
18 import com.liferay.portal.kernel.util.StringPool;
19 import com.liferay.portal.kernel.util.StringUtil;
20 import com.liferay.portal.kernel.util.Validator;
21 import com.liferay.portal.theme.ThemeDisplay;
22 import com.liferay.portal.util.PortalUtil;
23 import com.liferay.portal.util.WebKeys;
24 import com.liferay.portlet.blogs.NoSuchEntryException;
25 import com.liferay.portlet.blogs.model.BlogsEntry;
26 import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
27
28 import javax.portlet.ActionRequest;
29 import javax.portlet.RenderRequest;
30
31 import javax.servlet.http.HttpServletRequest;
32
33
38 public class ActionUtil {
39
40 public static void getEntry(ActionRequest actionRequest) throws Exception {
41 HttpServletRequest request = PortalUtil.getHttpServletRequest(
42 actionRequest);
43
44 getEntry(request);
45 }
46
47 public static void getEntry(RenderRequest renderRequest) throws Exception {
48 HttpServletRequest request = PortalUtil.getHttpServletRequest(
49 renderRequest);
50
51 getEntry(request);
52 }
53
54 public static void getEntry(HttpServletRequest request) throws Exception {
55 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
56 WebKeys.THEME_DISPLAY);
57
58 long entryId = ParamUtil.getLong(request, "entryId");
59
60 String urlTitle = ParamUtil.getString(request, "urlTitle");
61
62 BlogsEntry entry = null;
63
64 if (entryId > 0) {
65 entry = BlogsEntryServiceUtil.getEntry(entryId);
66 }
67 else if (Validator.isNotNull(urlTitle)) {
68 try {
69 entry = BlogsEntryServiceUtil.getEntry(
70 themeDisplay.getScopeGroupId(), urlTitle);
71 }
72 catch (NoSuchEntryException nsee) {
73 if (urlTitle.indexOf(StringPool.UNDERLINE) != -1) {
74
75
78 urlTitle = StringUtil.replace(
79 urlTitle, StringPool.UNDERLINE, StringPool.DASH);
80
81 entry = BlogsEntryServiceUtil.getEntry(
82 themeDisplay.getScopeGroupId(), urlTitle);
83 }
84 else {
85 throw nsee;
86 }
87 }
88 }
89
90 request.setAttribute(WebKeys.BLOGS_ENTRY, entry);
91 }
92
93 }