001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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)) {
050                            strutsAction = "/blogs";
051                    }
052                    else {
053                            strutsAction = "/blogs_aggregator";
054                    }
055    
056                    boolean showAllEntries = ParamUtil.getBoolean(
057                            request, "showAllEntries");
058    
059                    if (showAllEntries) {
060                            strutsAction += "/view";
061                    }
062                    else {
063                            strutsAction += "/view_entry";
064                    }
065    
066                    return strutsAction;
067            }
068    
069            @Override
070            protected String[] initPortletIds() {
071                    return new String[] {PortletKeys.BLOGS, PortletKeys.BLOGS_AGGREGATOR};
072            }
073    
074    }