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.imagegallery.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.imagegallery.NoSuchFolderException;
21  
22  import javax.portlet.PortletConfig;
23  import javax.portlet.RenderRequest;
24  import javax.portlet.RenderResponse;
25  
26  import org.apache.struts.action.ActionForm;
27  import org.apache.struts.action.ActionForward;
28  import org.apache.struts.action.ActionMapping;
29  
30  /**
31   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class ViewAction extends PortletAction {
36  
37      public ActionForward render(
38              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
39              RenderRequest renderRequest, RenderResponse renderResponse)
40          throws Exception {
41  
42          try {
43              ActionUtil.getFolder(renderRequest);
44          }
45          catch (Exception e) {
46              if (e instanceof NoSuchFolderException ||
47                  e instanceof PrincipalException) {
48  
49                  SessionErrors.add(renderRequest, e.getClass().getName());
50  
51                  return mapping.findForward("portlet.image_gallery.error");
52              }
53              else {
54                  throw e;
55              }
56          }
57  
58          return mapping.findForward("portlet.image_gallery.view");
59      }
60  
61  }