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