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 ActionForward render(
042                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
043                            RenderRequest renderRequest, RenderResponse renderResponse)
044                    throws Exception {
045    
046                    try {
047                            ActionUtil.getFolder(renderRequest);
048                    }
049                    catch (Exception e) {
050                            if (e instanceof NoSuchFolderException ||
051                                    e instanceof PrincipalException) {
052    
053                                    SessionErrors.add(renderRequest, e.getClass().getName());
054    
055                                    return mapping.findForward("portlet.document_library.error");
056                            }
057                            else {
058                                    throw e;
059                            }
060                    }
061    
062                    return mapping.findForward("portlet.document_library.view");
063            }
064    
065            @Override
066            public void serveResource(
067                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
068                            ResourceRequest resourceRequest, ResourceResponse resourceResponse)
069                    throws Exception {
070    
071                    PortletContext portletContext = portletConfig.getPortletContext();
072    
073                    PortletRequestDispatcher portletRequestDispatcher =
074                            portletContext.getRequestDispatcher(
075                                    "/html/portlet/document_library/view_resources.jsp");
076    
077                    portletRequestDispatcher.include(resourceRequest, resourceResponse);
078            }
079    
080    }