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.security.auth.PrincipalException;
19  import com.liferay.portal.struts.PortletAction;
20  import com.liferay.portal.util.WebKeys;
21  import com.liferay.portlet.wiki.NoSuchNodeException;
22  import com.liferay.portlet.wiki.NoSuchPageException;
23  import com.liferay.portlet.wiki.model.WikiNode;
24  
25  import javax.portlet.PortletConfig;
26  import javax.portlet.RenderRequest;
27  import javax.portlet.RenderResponse;
28  
29  import org.apache.struts.action.ActionForm;
30  import org.apache.struts.action.ActionForward;
31  import org.apache.struts.action.ActionMapping;
32  
33  /**
34   * <a href="ViewPageAction.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   * @author Jorge Ferrer
38   */
39  public class ViewPageAction extends PortletAction {
40  
41      public ActionForward render(
42              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
43              RenderRequest renderRequest, RenderResponse renderResponse)
44          throws Exception {
45  
46          try {
47              WikiNode node = ActionUtil.getNode(renderRequest);
48  
49              if (node == null) {
50                  ActionUtil.getFirstVisibleNode(renderRequest);
51              }
52  
53              ActionUtil.getPage(renderRequest);
54          }
55          catch (Exception e) {
56              if (e instanceof NoSuchNodeException ||
57                  e instanceof NoSuchPageException ||
58                  e instanceof PrincipalException) {
59  
60                  SessionErrors.add(renderRequest, e.getClass().getName());
61  
62                  return mapping.findForward("portlet.wiki.error");
63              }
64              else {
65                  throw e;
66              }
67          }
68  
69          return mapping.findForward(
70              getForward(renderRequest, "portlet.wiki.view_page"));
71      }
72  
73      protected void getNode(RenderRequest renderRequest) throws Exception {
74          ActionUtil.getNode(renderRequest);
75  
76          WikiNode node = (WikiNode)renderRequest.getAttribute(WebKeys.WIKI_NODE);
77  
78          if (node != null) {
79              return;
80          }
81  
82          ActionUtil.getFirstVisibleNode(renderRequest);
83      }
84  
85      protected boolean isCheckMethodOnProcessAction() {
86          return false;
87      }
88  
89  }