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