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.portal.struts;
016    
017    import com.liferay.portal.kernel.portlet.BasePortletLayoutFinder;
018    import com.liferay.portal.kernel.portlet.PortletLayoutFinder;
019    import com.liferay.portal.kernel.struts.BaseStrutsAction;
020    
021    import javax.portlet.PortletURL;
022    
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.http.HttpServletResponse;
025    
026    /**
027     * @author Adolfo P??rez
028     */
029    public abstract class FindStrutsAction extends BaseStrutsAction {
030    
031            public FindStrutsAction() {
032                    _findActionHelper = new BaseStrutsPortletFindActionHelper() {
033    
034                            @Override
035                            public long getGroupId(long primaryKey) throws Exception {
036                                    return FindStrutsAction.this.getGroupId(primaryKey);
037                            }
038    
039                            @Override
040                            public String getPrimaryKeyParameterName() {
041                                    return FindStrutsAction.this.getPrimaryKeyParameterName();
042                            }
043    
044                            @Override
045                            public String getStrutsAction(
046                                    HttpServletRequest request, String portletId) {
047    
048                                    return FindStrutsAction.this.getStrutsAction(
049                                            request, portletId);
050                            }
051    
052                            @Override
053                            public PortletURL processPortletURL(
054                                            HttpServletRequest request, PortletURL portletURL)
055                                    throws Exception {
056    
057                                    return FindStrutsAction.this.processPortletURL(
058                                            request, portletURL);
059                            }
060    
061                            @Override
062                            public void setPrimaryKeyParameter(
063                                            PortletURL portletURL, long primaryKey)
064                                    throws Exception {
065    
066                                    FindStrutsAction.this.setPrimaryKeyParameter(
067                                            portletURL, primaryKey);
068                            }
069    
070                            @Override
071                            protected PortletLayoutFinder getPortletLayoutFinder() {
072                                    return FindStrutsAction.this._portletLayoutFinder;
073                            }
074    
075                    };
076            }
077    
078            @Override
079            public String execute(
080                            HttpServletRequest request, HttpServletResponse response)
081                    throws Exception {
082    
083                    _findActionHelper.execute(request, response);
084    
085                    return null;
086            }
087    
088            protected abstract long getGroupId(long primaryKey) throws Exception;
089    
090            protected abstract String getPrimaryKeyParameterName();
091    
092            protected abstract String getStrutsAction(
093                    HttpServletRequest request, String portletId);
094    
095            protected abstract String[] initPortletIds();
096    
097            protected PortletURL processPortletURL(
098                            HttpServletRequest request, PortletURL portletURL)
099                    throws Exception {
100    
101                    return portletURL;
102            }
103    
104            protected void setPrimaryKeyParameter(
105                            PortletURL portletURL, long primaryKey)
106                    throws Exception {
107    
108                    portletURL.setParameter(
109                            getPrimaryKeyParameterName(), String.valueOf(primaryKey));
110            }
111    
112            private final FindActionHelper _findActionHelper;
113    
114            private final PortletLayoutFinder _portletLayoutFinder =
115                    new BasePortletLayoutFinder() {
116    
117                            @Override
118                            protected String[] getPortletIds() {
119                                    return FindStrutsAction.this.initPortletIds();
120                            }
121    
122                    };
123    
124    }