001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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 actionMapping, ActionForm actionForm,
042                            PortletConfig portletConfig, RenderRequest renderRequest,
043                            RenderResponse renderResponse)
044                    throws Exception {
045    
046                    try {
047                            String containerModelClassName = ParamUtil.getString(
048                                    renderRequest, "containerModelClassName");
049                            long containerModelId = ParamUtil.getLong(
050                                    renderRequest, "containerModelId");
051    
052                            TrashHandler trashHandler =
053                                    TrashHandlerRegistryUtil.getTrashHandler(
054                                            containerModelClassName);
055    
056                            ContainerModel containerModel = null;
057    
058                            if (containerModelId > 0) {
059                                    containerModel = trashHandler.getContainerModel(
060                                            containerModelId);
061                            }
062    
063                            renderRequest.setAttribute(
064                                    WebKeys.TRASH_CONTAINER_MODEL, containerModel);
065                    }
066                    catch (Exception e) {
067                            if (e instanceof PrincipalException) {
068                                    SessionErrors.add(renderRequest, e.getClass());
069    
070                                    return actionMapping.findForward("portlet.trash.error");
071                            }
072                            else {
073                                    throw e;
074                            }
075                    }
076    
077                    return actionMapping.findForward(
078                            getForward(renderRequest, "portlet.trash.view_container_model"));
079            }
080    
081    }