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