1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.wiki.action;
16  
17  import com.liferay.portal.kernel.servlet.SessionErrors;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.portal.security.auth.PrincipalException;
21  import com.liferay.portal.struts.PortletAction;
22  import com.liferay.portal.util.WebKeys;
23  import com.liferay.portlet.wiki.NoSuchNodeException;
24  import com.liferay.portlet.wiki.NoSuchPageException;
25  import com.liferay.portlet.wiki.model.WikiNode;
26  
27  import javax.portlet.PortletConfig;
28  import javax.portlet.RenderRequest;
29  import javax.portlet.RenderResponse;
30  
31  import org.apache.struts.action.ActionForm;
32  import org.apache.struts.action.ActionForward;
33  import org.apache.struts.action.ActionMapping;
34  
35  /**
36   * <a href="ViewPageAction.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   * @author Jorge Ferrer
40   */
41  public class ViewPageAction extends PortletAction {
42  
43      public ActionForward render(
44              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
45              RenderRequest renderRequest, RenderResponse renderResponse)
46          throws Exception {
47  
48          String tag = ParamUtil.getString(renderRequest, "tag");
49  
50          if (Validator.isNotNull(tag)) {
51              return ViewNodeAction.viewNode(
52                  mapping, renderRequest, "portlet.wiki.view_node");
53          }
54  
55          try {
56              ActionUtil.getNode(renderRequest);
57              ActionUtil.getPage(renderRequest);
58          }
59          catch (Exception e) {
60              if (e instanceof NoSuchNodeException ||
61                  e instanceof NoSuchPageException ||
62                  e instanceof PrincipalException) {
63  
64                  SessionErrors.add(renderRequest, e.getClass().getName());
65  
66                  return mapping.findForward("portlet.wiki.error");
67              }
68              else {
69                  throw e;
70              }
71          }
72  
73          return mapping.findForward(
74              getForward(renderRequest, "portlet.wiki.view_page"));
75      }
76  
77      protected void getNode(RenderRequest renderRequest) throws Exception {
78          ActionUtil.getNode(renderRequest);
79  
80          WikiNode node = (WikiNode)renderRequest.getAttribute(WebKeys.WIKI_NODE);
81  
82          if (node != null) {
83              return;
84          }
85  
86          ActionUtil.getFirstVisibleNode(renderRequest);
87      }
88  
89      protected boolean isCheckMethodOnProcessAction() {
90          return false;
91      }
92  
93  }