1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.portlet.wiki.NoSuchNodeException;
21  import com.liferay.portlet.wiki.model.WikiNode;
22  
23  import javax.portlet.PortletConfig;
24  import javax.portlet.RenderRequest;
25  import javax.portlet.RenderResponse;
26  
27  import org.apache.struts.action.ActionForm;
28  import org.apache.struts.action.ActionForward;
29  import org.apache.struts.action.ActionMapping;
30  
31  /**
32   * <a href="ViewNodeAction.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Jorge Ferrer
35   */
36  public class ViewNodeAction extends PortletAction {
37  
38      public static ActionForward viewNode(
39              ActionMapping mapping, RenderRequest renderRequest,
40              String defaultForward)
41          throws Exception {
42  
43          try {
44              WikiNode node = ActionUtil.getNode(renderRequest);
45  
46              if (node == null) {
47                  ActionUtil.getFirstVisibleNode(renderRequest);
48              }
49          }
50          catch (Exception e) {
51              if (e instanceof NoSuchNodeException ||
52                  e instanceof PrincipalException) {
53  
54                  SessionErrors.add(renderRequest, e.getClass().getName());
55  
56                  return mapping.findForward("portlet.wiki.error");
57              }
58              else {
59                  throw e;
60              }
61          }
62  
63          return mapping.findForward(defaultForward);
64      }
65  
66      public ActionForward render(
67              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
68              RenderRequest renderRequest, RenderResponse renderResponse)
69          throws Exception {
70  
71          return viewNode(
72              mapping, renderRequest,
73              getForward(renderRequest, "portlet.wiki.view_node"));
74      }
75  
76  }