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.wiki.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.struts.FindAction;
019    import com.liferay.portal.util.PortletKeys;
020    import com.liferay.portlet.wiki.model.WikiNode;
021    import com.liferay.portlet.wiki.model.WikiPageResource;
022    import com.liferay.portlet.wiki.service.WikiNodeLocalServiceUtil;
023    import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
024    
025    import javax.portlet.PortletURL;
026    
027    import javax.servlet.http.HttpServletRequest;
028    
029    /**
030     * @author Samuel Kong
031     */
032    public class FindPageAction extends FindAction {
033    
034            @Override
035            protected long getGroupId(long primaryKey) throws Exception {
036                    WikiPageResource pageResource =
037                            WikiPageResourceLocalServiceUtil.getPageResource(primaryKey);
038    
039                    WikiNode node = WikiNodeLocalServiceUtil.getNode(
040                            pageResource.getNodeId());
041    
042                    return node.getGroupId();
043            }
044    
045            @Override
046            protected String getPrimaryKeyParameterName() {
047                    return "pageResourcePrimKey";
048            }
049    
050            @Override
051            protected String getStrutsAction(
052                    HttpServletRequest request, String portletId) {
053    
054                    return "/wiki/view";
055            }
056    
057            @Override
058            protected String[] initPortletIds() {
059                    return new String[] {PortletKeys.WIKI, PortletKeys.WIKI_DISPLAY};
060            }
061    
062            @Override
063            protected PortletURL processPortletURL(
064                            HttpServletRequest request, PortletURL portletURL)
065                    throws Exception {
066    
067                    long pageResourcePrimKey = ParamUtil.getLong(
068                            request, getPrimaryKeyParameterName());
069    
070                    WikiPageResource pageResource =
071                            WikiPageResourceLocalServiceUtil.getPageResource(
072                                    pageResourcePrimKey);
073    
074                    WikiNode node = WikiNodeLocalServiceUtil.getNode(
075                            pageResource.getNodeId());
076    
077                    portletURL.setParameter("nodeName", node.getName());
078                    portletURL.setParameter("title", pageResource.getTitle());
079    
080                    return portletURL;
081            }
082    
083    }