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
47 public class ActionUtil {
48
49 public static void getEntry(ActionRequest actionRequest) throws Exception {
50 HttpServletRequest request = PortalUtil.getHttpServletRequest(
51 actionRequest);
52
53 getEntry(request);
54 }
55
56 public static void getEntry(RenderRequest renderRequest) throws Exception {
57 HttpServletRequest request = PortalUtil.getHttpServletRequest(
58 renderRequest);
59
60 getEntry(request);
61 }
62
63 public static void getEntry(HttpServletRequest request) throws Exception {
64 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
65 WebKeys.THEME_DISPLAY);
66
67 long entryId = ParamUtil.getLong(request, "entryId");
68
69 String urlTitle = ParamUtil.getString(request, "urlTitle");
70
71 BlogsEntry entry = null;
72
73 if (entryId > 0) {
74 entry = BlogsEntryServiceUtil.getEntry(entryId);
75 }
76 else if (Validator.isNotNull(urlTitle)) {
77 try {
78 entry = BlogsEntryServiceUtil.getEntry(
79 themeDisplay.getScopeGroupId(), urlTitle);
80 }
81 catch (NoSuchEntryException nsee) {
82 if (urlTitle.indexOf(StringPool.UNDERLINE) != -1) {
83
84
87 urlTitle = StringUtil.replace(
88 urlTitle, StringPool.UNDERLINE, StringPool.DASH);
89
90 entry = BlogsEntryServiceUtil.getEntry(
91 themeDisplay.getScopeGroupId(), urlTitle);
92 }
93 else {
94 throw nsee;
95 }
96 }
97 }
98
99 request.setAttribute(WebKeys.BLOGS_ENTRY, entry);
100 }
101
102 }