1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.wikidisplay.action;
24  
25  import com.liferay.portal.kernel.servlet.SessionErrors;
26  import com.liferay.portal.kernel.util.GetterUtil;
27  import com.liferay.portal.kernel.util.ParamUtil;
28  import com.liferay.portal.kernel.util.StringPool;
29  import com.liferay.portal.security.auth.PrincipalException;
30  import com.liferay.portal.struts.PortletAction;
31  import com.liferay.portal.util.WebKeys;
32  import com.liferay.portlet.wiki.NoSuchNodeException;
33  import com.liferay.portlet.wiki.NoSuchPageException;
34  import com.liferay.portlet.wiki.model.WikiNode;
35  import com.liferay.portlet.wiki.model.WikiPage;
36  import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
37  import com.liferay.portlet.wiki.service.WikiNodeServiceUtil;
38  import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
39  
40  import javax.portlet.PortletConfig;
41  import javax.portlet.PortletPreferences;
42  import javax.portlet.RenderRequest;
43  import javax.portlet.RenderResponse;
44  
45  import org.apache.struts.action.ActionForm;
46  import org.apache.struts.action.ActionForward;
47  import org.apache.struts.action.ActionMapping;
48  
49  /**
50   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
51   *
52   * @author Brian Wing Shun Chan
53   */
54  public class ViewAction extends PortletAction {
55  
56      public ActionForward render(
57              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
58              RenderRequest renderRequest, RenderResponse renderResponse)
59          throws Exception {
60  
61          try {
62              PortletPreferences prefs = renderRequest.getPreferences();
63  
64              long nodeId = GetterUtil.getLong(
65                  prefs.getValue("node-id", StringPool.BLANK));
66              String title = ParamUtil.getString(
67                  renderRequest, "title",
68                  prefs.getValue("title", WikiPageImpl.FRONT_PAGE));
69  
70              WikiNode node = WikiNodeServiceUtil.getNode(nodeId);
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 }