001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.action;
016    
017    import com.liferay.portal.kernel.servlet.SessionErrors;
018    import com.liferay.portal.security.auth.PrincipalException;
019    import com.liferay.portal.struts.PortletAction;
020    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
021    
022    import javax.portlet.PortletConfig;
023    import javax.portlet.PortletContext;
024    import javax.portlet.PortletRequestDispatcher;
025    import javax.portlet.RenderRequest;
026    import javax.portlet.RenderResponse;
027    import javax.portlet.ResourceRequest;
028    import javax.portlet.ResourceResponse;
029    
030    import org.apache.struts.action.ActionForm;
031    import org.apache.struts.action.ActionForward;
032    import org.apache.struts.action.ActionMapping;
033    
034    /**
035     * @author Brian Wing Shun Chan
036     * @author Sergio González
037     */
038    public class ViewAction extends PortletAction {
039    
040            @Override
041            public void serveResource(
042                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
043                            ResourceRequest resourceRequest, ResourceResponse resourceResponse)
044                    throws Exception {
045    
046                    PortletContext portletContext = portletConfig.getPortletContext();
047    
048                    PortletRequestDispatcher portletRequestDispatcher =
049                            portletContext.getRequestDispatcher(
050                                    "/html/portlet/document_library/view_resources.jsp");
051    
052                    portletRequestDispatcher.include(resourceRequest, resourceResponse);
053            }
054    
055            @Override
056            public ActionForward render(
057                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
058                            RenderRequest renderRequest, RenderResponse renderResponse)
059                    throws Exception {
060    
061                    try {
062                            ActionUtil.getFolder(renderRequest);
063                    }
064                    catch (Exception e) {
065                            if (e instanceof NoSuchFolderException ||
066                                    e instanceof PrincipalException) {
067    
068                                    SessionErrors.add(renderRequest, e.getClass().getName());
069    
070                                    return mapping.findForward("portlet.document_library.error");
071                            }
072                            else {
073                                    throw e;
074                            }
075                    }
076    
077                    return mapping.findForward("portlet.document_library.view");
078            }
079    
080    }