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.kernel.util.Validator;
020 import com.liferay.portal.security.auth.PrincipalException;
021 import com.liferay.portal.struts.PortletAction;
022 import com.liferay.portal.util.WebKeys;
023 import com.liferay.portlet.wiki.NoSuchNodeException;
024 import com.liferay.portlet.wiki.NoSuchPageException;
025 import com.liferay.portlet.wiki.model.WikiNode;
026
027 import javax.portlet.PortletConfig;
028 import javax.portlet.RenderRequest;
029 import javax.portlet.RenderResponse;
030
031 import org.apache.struts.action.ActionForm;
032 import org.apache.struts.action.ActionForward;
033 import org.apache.struts.action.ActionMapping;
034
035
039 public class ViewPageAction extends PortletAction {
040
041 public ActionForward render(
042 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
043 RenderRequest renderRequest, RenderResponse renderResponse)
044 throws Exception {
045
046 long categoryId = ParamUtil.getLong(renderRequest, "categoryId");
047 String title = ParamUtil.getString(renderRequest, "title");
048
049 if ((categoryId > 0) || Validator.isNull(title)) {
050 if (categoryId > 0) {
051 return ViewNodeAction.viewNode(
052 mapping, renderRequest,
053 "portlet.wiki.view_categorized_pages");
054 }
055
056 String tag = ParamUtil.getString(renderRequest, "tag");
057
058 if (Validator.isNotNull(tag)) {
059 return ViewNodeAction.viewNode(
060 mapping, renderRequest, "portlet.wiki.view_tagged_pages");
061 }
062 }
063
064 try {
065 ActionUtil.getNode(renderRequest);
066 ActionUtil.getPage(renderRequest);
067 }
068 catch (Exception e) {
069 if (e instanceof NoSuchNodeException ||
070 e instanceof NoSuchPageException ||
071 e instanceof PrincipalException) {
072
073 SessionErrors.add(renderRequest, e.getClass().getName());
074
075 return mapping.findForward("portlet.wiki.error");
076 }
077 else {
078 throw e;
079 }
080 }
081
082 return mapping.findForward(
083 getForward(renderRequest, "portlet.wiki.view_page"));
084 }
085
086 protected void getNode(RenderRequest renderRequest) throws Exception {
087 ActionUtil.getNode(renderRequest);
088
089 WikiNode node = (WikiNode)renderRequest.getAttribute(WebKeys.WIKI_NODE);
090
091 if (node != null) {
092 return;
093 }
094
095 ActionUtil.getFirstVisibleNode(renderRequest);
096 }
097
098 protected boolean isCheckMethodOnProcessAction() {
099 return false;
100 }
101
102 }