1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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  /**
42   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
43   *
44   * @author Brian Wing Shun Chan
45   */
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                      // Check another URL title for backwards compatibility. See
84                      // LEP-5733.
85  
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 }