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