001    /**
002     * Copyright (c) 2000-2011 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.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class FindEntryAction extends FindAction {
030    
031            @Override
032            protected long getGroupId(long primaryKey) throws Exception {
033                    BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(primaryKey);
034    
035                    return entry.getGroupId();
036            }
037    
038            @Override
039            protected String getPrimaryKeyParameterName() {
040                    return "entryId";
041            }
042    
043            @Override
044            protected String getStrutsAction(
045                    HttpServletRequest request, String portletId) {
046    
047                    String strutsAction = StringPool.BLANK;
048    
049                    if (portletId.equals(PortletKeys.BLOGS_ADMIN)) {
050                            strutsAction = "/blogs_admin";
051                    }
052                    else if (portletId.equals(PortletKeys.BLOGS)) {
053                            strutsAction = "/blogs";
054                    }
055                    else {
056                            strutsAction = "/blogs_aggregator";
057                    }
058    
059                    boolean showAllEntries = ParamUtil.getBoolean(
060                            request, "showAllEntries");
061    
062                    if (showAllEntries) {
063                            strutsAction += "/view";
064                    }
065                    else {
066                            strutsAction += "/view_entry";
067                    }
068    
069                    return strutsAction;
070            }
071    
072            @Override
073            protected String[] initPortletIds() {
074    
075                    // Order is important. See LPS-23770.
076    
077                    return new String[] {
078                            PortletKeys.BLOGS_ADMIN, PortletKeys.BLOGS,
079                            PortletKeys.BLOGS_AGGREGATOR
080                    };
081            }
082    
083    }