/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.blogs.web.internal.portlet.action; import com.liferay.blogs.exception.NoSuchEntryException; import com.liferay.blogs.model.BlogsEntry; import com.liferay.blogs.service.BlogsEntryServiceUtil; import com.liferay.portal.kernel.servlet.SessionErrors; import com.liferay.portal.kernel.theme.ThemeDisplay; import com.liferay.portal.kernel.util.CharPool; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.StringUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.util.WebKeys; import javax.portlet.PortletRequest; /** * @author Brian Wing Shun Chan */ public class ActionUtil { public static BlogsEntry getEntry(PortletRequest portletRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute( WebKeys.THEME_DISPLAY); long entryId = ParamUtil.getLong(portletRequest, "entryId"); String urlTitle = ParamUtil.getString(portletRequest, "urlTitle"); BlogsEntry entry = null; if (entryId > 0) { entry = BlogsEntryServiceUtil.getEntry(entryId); } else if (Validator.isNotNull(urlTitle) && SessionErrors.isEmpty(portletRequest)) { try { entry = BlogsEntryServiceUtil.getEntry( themeDisplay.getScopeGroupId(), urlTitle); } catch (NoSuchEntryException nsee) { if (urlTitle.indexOf(CharPool.UNDERLINE) != -1) { // Check another URL title for backwards compatibility. See // LEP-5733. urlTitle = StringUtil.replace( urlTitle, CharPool.UNDERLINE, CharPool.DASH); entry = BlogsEntryServiceUtil.getEntry( themeDisplay.getScopeGroupId(), urlTitle); } else { throw nsee; } } } if ((entry != null) && entry.isInTrash()) { throw new NoSuchEntryException("{entryId=" + entryId + "}"); } return entry; } }