001
014
015 package com.liferay.portlet.wiki.action;
016
017 import com.liferay.portal.kernel.servlet.SessionErrors;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.security.auth.PrincipalException;
020 import com.liferay.portal.struts.PortletAction;
021 import com.liferay.portlet.wiki.NoSuchNodeException;
022 import com.liferay.portlet.wiki.model.WikiNode;
023
024 import javax.portlet.PortletConfig;
025 import javax.portlet.RenderRequest;
026 import javax.portlet.RenderResponse;
027
028 import org.apache.struts.action.ActionForm;
029 import org.apache.struts.action.ActionForward;
030 import org.apache.struts.action.ActionMapping;
031
032
036 public class ViewNodeAction extends PortletAction {
037
038 public static ActionForward viewNode(
039 ActionMapping mapping, RenderRequest renderRequest,
040 String defaultForward)
041 throws Exception {
042
043 try {
044 WikiNode node = ActionUtil.getNode(renderRequest);
045
046 if (node == null) {
047 ActionUtil.getFirstVisibleNode(renderRequest);
048 }
049 }
050 catch (Exception e) {
051 if (e instanceof NoSuchNodeException ||
052 e instanceof PrincipalException) {
053
054 SessionErrors.add(renderRequest, e.getClass().getName());
055
056 return mapping.findForward("portlet.wiki.error");
057 }
058 else {
059 throw e;
060 }
061 }
062
063 long categoryId = ParamUtil.getLong(renderRequest, "categoryId");
064
065 if (categoryId > 0) {
066 return mapping.findForward("portlet.wiki.view_categorized_pages");
067 }
068 else {
069 return mapping.findForward(defaultForward);
070 }
071 }
072
073 public ActionForward render(
074 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
075 RenderRequest renderRequest, RenderResponse renderResponse)
076 throws Exception {
077
078 return viewNode(
079 mapping, renderRequest,
080 getForward(renderRequest, "portlet.wiki.view_node"));
081 }
082
083 }