/** * 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.knowledge.base.web.internal.portlet; import com.liferay.knowledge.base.constants.KBPortletKeys; import com.liferay.knowledge.base.exception.NoSuchArticleException; import com.liferay.knowledge.base.exception.NoSuchCommentException; import com.liferay.knowledge.base.model.KBArticle; import com.liferay.knowledge.base.web.internal.constants.KBWebKeys; import com.liferay.portal.kernel.exception.NoSuchSubscriptionException; import com.liferay.portal.kernel.model.Release; import com.liferay.portal.kernel.security.auth.PrincipalException; import com.liferay.portal.kernel.servlet.SessionErrors; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.workflow.WorkflowConstants; import java.io.IOException; import javax.portlet.Portlet; import javax.portlet.PortletException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Peter Shin * @author Brian Wing Shun Chan */ @Component( immediate = true, property = { "com.liferay.portlet.css-class-wrapper=knowledge-base-portlet knowledge-base-portlet-search", "com.liferay.portlet.display-category=category.cms", "com.liferay.portlet.header-portlet-css=/admin/css/common.css", "com.liferay.portlet.icon=/icons/search.png", "com.liferay.portlet.scopeable=true", "javax.portlet.display-name=Knowledge Base Search", "javax.portlet.expiration-cache=0", "javax.portlet.init-param.always-send-redirect=true", "javax.portlet.init-param.copy-request-parameters=true", "javax.portlet.init-param.template-path=/search/", "javax.portlet.init-param.view-template=/search/view.jsp", "javax.portlet.name=" + KBPortletKeys.KNOWLEDGE_BASE_SEARCH, "javax.portlet.resource-bundle=content.Language", "javax.portlet.security-role-ref=administrator,guest,power-user,user", "javax.portlet.supported-public-render-parameter=categoryId", "javax.portlet.supported-public-render-parameter=tag", "javax.portlet.supports.mime-type=text/html" }, service = Portlet.class ) public class SearchPortlet extends BaseKBPortlet { @Override protected void doDispatch( RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { String mvcPath = ParamUtil.getString( renderRequest, "mvcPath", viewTemplate); long assetCategoryId = ParamUtil.getLong(renderRequest, "categoryId"); String assetTagName = ParamUtil.getString(renderRequest, "tag"); if ((mvcPath.equals(viewTemplate) && (assetCategoryId > 0)) || (mvcPath.equals(viewTemplate) && Validator.isNotNull(assetTagName))) { String path = templatePath + "view_prp_articles.jsp"; include(path, renderRequest, renderResponse); } else if (SessionErrors.contains( renderRequest, NoSuchArticleException.class.getName()) || SessionErrors.contains( renderRequest, NoSuchCommentException.class.getName()) || SessionErrors.contains( renderRequest, NoSuchSubscriptionException.class.getName()) || SessionErrors.contains( renderRequest, PrincipalException.getNestedClasses())) { include(templatePath + "error.jsp", renderRequest, renderResponse); } else { super.doDispatch(renderRequest, renderResponse); } } @Override protected void doRender( RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { try { renderRequest.setAttribute( KBWebKeys.DL_MIME_TYPE_DISPLAY_CONTEXT, dlMimeTypeDisplayContext); KBArticle kbArticle = null; long resourcePrimKey = ParamUtil.getLong( renderRequest, "resourcePrimKey"); if (resourcePrimKey > 0) { kbArticle = kbArticleService.getLatestKBArticle( resourcePrimKey, WorkflowConstants.STATUS_APPROVED); } renderRequest.setAttribute( KBWebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle); renderRequest.setAttribute( KBWebKeys.KNOWLEDGE_BASE_STATUS, WorkflowConstants.STATUS_APPROVED); } catch (Exception e) { if (e instanceof NoSuchArticleException || e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass()); } else { throw new PortletException(e); } } } @Reference( target = "(&(release.bundle.symbolic.name=com.liferay.knowledge.base.web)(release.schema.version=1.0.0))", unbind = "-" ) protected void setRelease(Release release) { } }