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