001
014
015 package com.liferay.portlet.blogs.action;
016
017 import com.liferay.portal.kernel.util.CharPool;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.kernel.util.StringUtil;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.portal.theme.ThemeDisplay;
022 import com.liferay.portal.util.PortalUtil;
023 import com.liferay.portal.util.WebKeys;
024 import com.liferay.portlet.blogs.NoSuchEntryException;
025 import com.liferay.portlet.blogs.model.BlogsEntry;
026 import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
027
028 import javax.portlet.PortletRequest;
029
030 import javax.servlet.http.HttpServletRequest;
031
032
035 public class ActionUtil {
036
037 public static void getEntry(HttpServletRequest request) throws Exception {
038 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
039 WebKeys.THEME_DISPLAY);
040
041 long entryId = ParamUtil.getLong(request, "entryId");
042
043 String urlTitle = ParamUtil.getString(request, "urlTitle");
044
045 BlogsEntry entry = null;
046
047 if (entryId > 0) {
048 entry = BlogsEntryServiceUtil.getEntry(entryId);
049 }
050 else if (Validator.isNotNull(urlTitle)) {
051 try {
052 entry = BlogsEntryServiceUtil.getEntry(
053 themeDisplay.getScopeGroupId(), urlTitle);
054 }
055 catch (NoSuchEntryException nsee) {
056 if (urlTitle.indexOf(CharPool.UNDERLINE) != -1) {
057
058
059
060
061 urlTitle = StringUtil.replace(
062 urlTitle, CharPool.UNDERLINE, CharPool.DASH);
063
064 entry = BlogsEntryServiceUtil.getEntry(
065 themeDisplay.getScopeGroupId(), urlTitle);
066 }
067 else {
068 throw nsee;
069 }
070 }
071 }
072
073 request.setAttribute(WebKeys.BLOGS_ENTRY, entry);
074 }
075
076 public static void getEntry(PortletRequest portletRequest)
077 throws Exception {
078
079 HttpServletRequest request = PortalUtil.getHttpServletRequest(
080 portletRequest);
081
082 getEntry(request);
083 }
084
085 }