1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.blogs.action;
16  
17  import com.liferay.portal.kernel.util.CharPool;
18  import com.liferay.portal.kernel.util.ParamUtil;
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  /**
34   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   */
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(CharPool.UNDERLINE) != -1) {
74  
75                      // Check another URL title for backwards compatibility. See
76                      // LEP-5733.
77  
78                      urlTitle = StringUtil.replace(
79                          urlTitle, CharPool.UNDERLINE, CharPool.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  }