Java tutorial
/** * Copyright (c) 2000-2012 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.portlet.wiki.action; 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.security.auth.PrincipalException; import com.liferay.portal.struts.PortletAction; import com.liferay.portal.util.WebKeys; import com.liferay.portlet.wiki.NoSuchNodeException; import com.liferay.portlet.wiki.NoSuchPageException; import com.liferay.portlet.wiki.model.WikiNode; import javax.portlet.PortletConfig; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * @author Brian Wing Shun Chan * @author Jorge Ferrer */ public class ViewPageAction extends PortletAction { @Override public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception { long categoryId = ParamUtil.getLong(renderRequest, "categoryId"); if (categoryId > 0) { return ViewNodeAction.viewNode(mapping, renderRequest, "portlet.wiki.view_categorized_pages"); } String tag = ParamUtil.getString(renderRequest, "tag"); if (Validator.isNotNull(tag)) { return ViewNodeAction.viewNode(mapping, renderRequest, "portlet.wiki.view_tagged_pages"); } try { ActionUtil.getNode(renderRequest); ActionUtil.getPage(renderRequest); } catch (Exception e) { if (e instanceof NoSuchNodeException || e instanceof NoSuchPageException || e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass().getName()); return mapping.findForward("portlet.wiki.error"); } else { throw e; } } return mapping.findForward(getForward(renderRequest, "portlet.wiki.view_page")); } protected void getNode(RenderRequest renderRequest) throws Exception { ActionUtil.getNode(renderRequest); WikiNode node = (WikiNode) renderRequest.getAttribute(WebKeys.WIKI_NODE); if (node != null) { return; } ActionUtil.getFirstVisibleNode(renderRequest); } @Override protected boolean isCheckMethodOnProcessAction() { return false; } }