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 actionMapping, 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());
055
056 return actionMapping.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 actionMapping.findForward(
067 "portlet.wiki.view_categorized_pages");
068 }
069 else {
070 return actionMapping.findForward(defaultForward);
071 }
072 }
073
074 @Override
075 public ActionForward render(
076 ActionMapping actionMapping, ActionForm actionForm,
077 PortletConfig portletConfig, RenderRequest renderRequest,
078 RenderResponse renderResponse)
079 throws Exception {
080
081 return viewNode(
082 actionMapping, renderRequest,
083 getForward(renderRequest, "portlet.wiki.view_node"));
084 }
085
086 }