001    /**
002     * Copyright (c) 2000-present 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.layoutsadmin.action;
016    
017    import com.liferay.portal.NoSuchGroupException;
018    import com.liferay.portal.kernel.servlet.SessionErrors;
019    import com.liferay.portal.security.auth.PrincipalException;
020    import com.liferay.portal.struts.PortletAction;
021    import com.liferay.portlet.sites.action.ActionUtil;
022    
023    import javax.portlet.PortletConfig;
024    import javax.portlet.PortletContext;
025    import javax.portlet.PortletRequestDispatcher;
026    import javax.portlet.RenderRequest;
027    import javax.portlet.RenderResponse;
028    import javax.portlet.ResourceRequest;
029    import javax.portlet.ResourceResponse;
030    
031    import org.apache.struts.action.ActionForm;
032    import org.apache.struts.action.ActionForward;
033    import org.apache.struts.action.ActionMapping;
034    
035    /**
036     * @author Eduardo Garcia
037     */
038    public class MobileDeviceRulesAction 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.getGroup(renderRequest);
049                    }
050                    catch (Exception e) {
051                            if (e instanceof NoSuchGroupException ||
052                                    e instanceof PrincipalException) {
053    
054                                    SessionErrors.add(renderRequest, e.getClass());
055    
056                                    return actionMapping.findForward("portlet.layouts_admin.error");
057                            }
058                            else {
059                                    throw e;
060                            }
061                    }
062    
063                    return actionMapping.findForward("portlet.layouts_admin.edit_layouts");
064            }
065    
066            @Override
067            public void serveResource(
068                            ActionMapping actionMapping, ActionForm actionForm,
069                            PortletConfig portletConfig, ResourceRequest resourceRequest,
070                            ResourceResponse resourceResponse)
071                    throws Exception {
072    
073                    PortletContext portletContext = portletConfig.getPortletContext();
074    
075                    PortletRequestDispatcher portletRequestDispatcher =
076                            portletContext.getRequestDispatcher(
077                                    "/html/portlet/layouts_admin/layout/" +
078                                            "mobile_device_rules_rule_group_instances.jsp");
079    
080                    portletRequestDispatcher.include(resourceRequest, resourceResponse);
081            }
082    
083    }