001    /**
002     * Copyright (c) 2000-2013 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.blogs.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.struts.FindAction;
020    import com.liferay.portal.util.PortletKeys;
021    import com.liferay.portlet.blogs.model.BlogsEntry;
022    import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
023    
024    import javax.portlet.PortletURL;
025    
026    import javax.servlet.http.HttpServletRequest;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class FindEntryAction extends FindAction {
032    
033            @Override
034            protected long getGroupId(long primaryKey) throws Exception {
035                    BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(primaryKey);
036    
037                    return entry.getGroupId();
038            }
039    
040            @Override
041            protected String getPrimaryKeyParameterName() {
042                    return "entryId";
043            }
044    
045            @Override
046            protected String getStrutsAction(
047                    HttpServletRequest request, String portletId) {
048    
049                    String strutsAction = StringPool.BLANK;
050    
051                    if (portletId.equals(PortletKeys.BLOGS_ADMIN)) {
052                            strutsAction = "/blogs_admin";
053                    }
054                    else if (portletId.equals(PortletKeys.BLOGS)) {
055                            strutsAction = "/blogs";
056                    }
057                    else {
058                            strutsAction = "/blogs_aggregator";
059                    }
060    
061                    boolean showAllEntries = ParamUtil.getBoolean(
062                            request, "showAllEntries");
063    
064                    if (showAllEntries) {
065                            strutsAction += "/view";
066                    }
067                    else {
068                            strutsAction += "/view_entry";
069                    }
070    
071                    return strutsAction;
072            }
073    
074            @Override
075            protected String[] initPortletIds() {
076    
077                    // Order is important. See LPS-23770.
078    
079                    return new String[] {
080                            PortletKeys.BLOGS_ADMIN, PortletKeys.BLOGS,
081                            PortletKeys.BLOGS_AGGREGATOR
082                    };
083            }
084    
085            @Override
086            protected void setPrimaryKeyParameter(
087                            PortletURL portletURL, long primaryKey)
088                    throws Exception {
089    
090                    BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(primaryKey);
091    
092                    portletURL.setParameter("urlTitle", entry.getUrlTitle());
093            }
094    
095    }