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.wikidisplay.action;
16  
17  import com.liferay.portal.kernel.servlet.SessionErrors;
18  import com.liferay.portal.kernel.util.GetterUtil;
19  import com.liferay.portal.kernel.util.ParamUtil;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.security.auth.PrincipalException;
22  import com.liferay.portal.struts.PortletAction;
23  import com.liferay.portal.theme.ThemeDisplay;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.wiki.NoSuchNodeException;
26  import com.liferay.portlet.wiki.NoSuchPageException;
27  import com.liferay.portlet.wiki.model.WikiNode;
28  import com.liferay.portlet.wiki.model.WikiPage;
29  import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
30  import com.liferay.portlet.wiki.service.WikiNodeServiceUtil;
31  import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
32  
33  import javax.portlet.PortletConfig;
34  import javax.portlet.PortletPreferences;
35  import javax.portlet.RenderRequest;
36  import javax.portlet.RenderResponse;
37  
38  import org.apache.struts.action.ActionForm;
39  import org.apache.struts.action.ActionForward;
40  import org.apache.struts.action.ActionMapping;
41  
42  /**
43   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Brian Wing Shun Chan
46   */
47  public class ViewAction extends PortletAction {
48  
49      public ActionForward render(
50              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
51              RenderRequest renderRequest, RenderResponse renderResponse)
52          throws Exception {
53  
54          try {
55              PortletPreferences preferences = renderRequest.getPreferences();
56  
57              ThemeDisplay themeDisplay =
58                  (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
59  
60              long nodeId = GetterUtil.getLong(
61                  preferences.getValue("node-id", StringPool.BLANK));
62              String title = ParamUtil.getString(
63                  renderRequest, "title",
64                  preferences.getValue("title", WikiPageImpl.FRONT_PAGE));
65  
66              WikiNode node = WikiNodeServiceUtil.getNode(nodeId);
67  
68              if (node.getGroupId() != themeDisplay.getScopeGroupId()) {
69                  throw new NoSuchNodeException();
70              }
71  
72              WikiPage wikiPage = null;
73  
74              try {
75                  wikiPage = WikiPageServiceUtil.getPage(nodeId, title);
76              }
77              catch (NoSuchPageException nspe) {
78                  wikiPage = WikiPageServiceUtil.getPage(
79                      nodeId, WikiPageImpl.FRONT_PAGE);
80              }
81  
82              renderRequest.setAttribute(WebKeys.WIKI_NODE, node);
83              renderRequest.setAttribute(WebKeys.WIKI_PAGE, wikiPage);
84  
85              return mapping.findForward("portlet.wiki_display.view");
86          }
87          catch (NoSuchNodeException nsne) {
88              return mapping.findForward("/portal/portlet_not_setup");
89          }
90          catch (NoSuchPageException nsne) {
91              return mapping.findForward("/portal/portlet_not_setup");
92          }
93          catch (PrincipalException pe) {
94              SessionErrors.add(renderRequest, pe.getClass().getName());
95  
96              return mapping.findForward("portlet.wiki_display.error");
97          }
98      }
99  
100 }