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.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          long categoryId = ParamUtil.getLong(renderRequest, "categoryId");
49          String tag = ParamUtil.getString(renderRequest, "tag");
50  
51          if (categoryId > 0) {
52              return ViewNodeAction.viewNode(
53                  mapping, renderRequest, "portlet.wiki.view_categorized_pages");
54          }
55  
56          if (Validator.isNotNull(tag)) {
57              return ViewNodeAction.viewNode(
58                  mapping, renderRequest, "portlet.wiki.view_tagged_pages");
59          }
60  
61          try {
62              WikiNode node = ActionUtil.getNode(renderRequest);
63  
64              if (node == null) {
65                  ActionUtil.getFirstVisibleNode(renderRequest);
66              }
67  
68              ActionUtil.getPage(renderRequest);
69          }
70          catch (Exception e) {
71              if (e instanceof NoSuchNodeException ||
72                  e instanceof NoSuchPageException ||
73                  e instanceof PrincipalException) {
74  
75                  SessionErrors.add(renderRequest, e.getClass().getName());
76  
77                  return mapping.findForward("portlet.wiki.error");
78              }
79              else {
80                  throw e;
81              }
82          }
83  
84          return mapping.findForward(
85              getForward(renderRequest, "portlet.wiki.view_page"));
86      }
87  
88      protected void getNode(RenderRequest renderRequest) throws Exception {
89          ActionUtil.getNode(renderRequest);
90  
91          WikiNode node = (WikiNode)renderRequest.getAttribute(WebKeys.WIKI_NODE);
92  
93          if (node != null) {
94              return;
95          }
96  
97          ActionUtil.getFirstVisibleNode(renderRequest);
98      }
99  
100     protected boolean isCheckMethodOnProcessAction() {
101         return false;
102     }
103 
104 }