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.trash.action;
016    
017    import com.liferay.portal.kernel.servlet.SessionErrors;
018    import com.liferay.portal.kernel.trash.TrashHandler;
019    import com.liferay.portal.kernel.trash.TrashHandlerRegistryUtil;
020    import com.liferay.portal.kernel.util.ParamUtil;
021    import com.liferay.portal.model.ContainerModel;
022    import com.liferay.portal.security.auth.PrincipalException;
023    import com.liferay.portal.struts.PortletAction;
024    import com.liferay.portal.util.WebKeys;
025    
026    import javax.portlet.PortletConfig;
027    import javax.portlet.RenderRequest;
028    import javax.portlet.RenderResponse;
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 Zsolt Berentey
036     */
037    public class ContainerModelAction extends PortletAction {
038    
039            @Override
040            public ActionForward render(
041                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
042                            RenderRequest renderRequest, RenderResponse renderResponse)
043                    throws Exception {
044    
045                    try {
046                            String containerModelClassName = ParamUtil.getString(
047                                    renderRequest, "containerModelClassName");
048                            long containerModelId = ParamUtil.getLong(
049                                    renderRequest, "containerModelId");
050    
051                            TrashHandler trashHandler =
052                                    TrashHandlerRegistryUtil.getTrashHandler(
053                                            containerModelClassName);
054    
055                            ContainerModel containerModel = null;
056    
057                            if (containerModelId > 0) {
058                                    containerModel = trashHandler.getContainerModel(
059                                            containerModelId);
060                            }
061    
062                            renderRequest.setAttribute(
063                                    WebKeys.TRASH_CONTAINER_MODEL, containerModel);
064                    }
065                    catch (Exception e) {
066                            if (e instanceof PrincipalException) {
067                                    SessionErrors.add(renderRequest, e.getClass());
068    
069                                    return mapping.findForward("portlet.trash.error");
070                            }
071                            else {
072                                    throw e;
073                            }
074                    }
075    
076                    return mapping.findForward(
077                            getForward(renderRequest, "portlet.trash.view_container_model"));
078            }
079    
080    }