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.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                    if (portletId.equals(PortletKeys.WIKI_ADMIN)) {
055                            return "/wiki_admin/view";
056                    }
057                    else if (portletId.equals(PortletKeys.WIKI)) {
058                            return "/wiki/view";
059                    }
060                    else {
061                            return "/wiki_display/view";
062                    }
063            }
064    
065            @Override
066            protected String[] initPortletIds() {
067    
068                    // Order is important. See LPS-23770.
069    
070                    return new String[] {
071                            PortletKeys.WIKI_ADMIN, PortletKeys.WIKI, PortletKeys.WIKI_DISPLAY
072                    };
073            }
074    
075            @Override
076            protected PortletURL processPortletURL(
077                            HttpServletRequest request, PortletURL portletURL)
078                    throws Exception {
079    
080                    long pageResourcePrimKey = ParamUtil.getLong(
081                            request, getPrimaryKeyParameterName());
082    
083                    WikiPageResource pageResource =
084                            WikiPageResourceLocalServiceUtil.getPageResource(
085                                    pageResourcePrimKey);
086    
087                    WikiNode node = WikiNodeLocalServiceUtil.getNode(
088                            pageResource.getNodeId());
089    
090                    portletURL.setParameter("nodeName", node.getName());
091                    portletURL.setParameter("title", pageResource.getTitle());
092    
093                    return portletURL;
094            }
095    
096    }