com.liferay.portlet.documentlibrary.action.ViewAction.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.portlet.documentlibrary.action.ViewAction.java

Source

/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.portlet.documentlibrary.action;

import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.struts.PortletAction;
import com.liferay.portlet.documentlibrary.NoSuchFolderException;

import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * @author Brian Wing Shun Chan
 * @author Sergio Gonzlez
 */
public class ViewAction extends PortletAction {

    @Override
    public void serveResource(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
            ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {

        PortletContext portletContext = portletConfig.getPortletContext();

        PortletRequestDispatcher portletRequestDispatcher = portletContext
                .getRequestDispatcher("/html/portlet/document_library/view_resources.jsp");

        portletRequestDispatcher.include(resourceRequest, resourceResponse);
    }

    @Override
    public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
            RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

        try {
            ActionUtil.getFolder(renderRequest);
        } catch (Exception e) {
            if (e instanceof NoSuchFolderException || e instanceof PrincipalException) {

                SessionErrors.add(renderRequest, e.getClass().getName());

                return mapping.findForward("portlet.document_library.error");
            } else {
                throw e;
            }
        }

        return mapping.findForward("portlet.document_library.view");
    }

}