001    /**
002     * Copyright (c) 2000-present 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.messageboards.asset;
016    
017    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
018    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
019    import com.liferay.portal.theme.ThemeDisplay;
020    import com.liferay.portal.util.PortletKeys;
021    import com.liferay.portal.util.WebKeys;
022    import com.liferay.portlet.PortletURLFactoryUtil;
023    import com.liferay.portlet.messageboards.model.MBMessage;
024    
025    import javax.portlet.PortletRequest;
026    import javax.portlet.PortletResponse;
027    import javax.portlet.PortletURL;
028    
029    import javax.servlet.http.HttpServletRequest;
030    
031    /**
032     * @author Jorge Ferrer
033     * @author Sergio Gonz??lez
034     */
035    public class MBDiscussionAssetRenderer extends MBMessageAssetRenderer {
036    
037            public MBDiscussionAssetRenderer(MBMessage message) {
038                    super(message);
039    
040                    _message = message;
041            }
042    
043            @Override
044            public PortletURL getURLEdit(
045                            LiferayPortletRequest liferayPortletRequest,
046                            LiferayPortletResponse liferayPortletResponse)
047                    throws Exception {
048    
049                    HttpServletRequest request =
050                            liferayPortletRequest.getHttpServletRequest();
051    
052                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
053                            WebKeys.THEME_DISPLAY);
054    
055                    PortletURL editPortletURL = PortletURLFactoryUtil.create(
056                            request, PortletKeys.MESSAGE_BOARDS,
057                            getControlPanelPlid(themeDisplay), PortletRequest.RENDER_PHASE);
058    
059                    editPortletURL.setParameter(
060                            "struts_action", "/message_boards/edit_discussion");
061                    editPortletURL.setParameter(
062                            "messageId", String.valueOf(_message.getMessageId()));
063    
064                    return editPortletURL;
065            }
066    
067            @Override
068            public String getURLViewInContext(
069                    LiferayPortletRequest liferayPortletRequest,
070                    LiferayPortletResponse liferayPortletResponse,
071                    String noSuchEntryRedirect) {
072    
073                    return null;
074            }
075    
076            @Override
077            public String render(
078                            PortletRequest portletRequest, PortletResponse portletResponse,
079                            String template)
080                    throws Exception {
081    
082                    if (template.equals(TEMPLATE_ABSTRACT) ||
083                            template.equals(TEMPLATE_FULL_CONTENT)) {
084    
085                            portletRequest.setAttribute(
086                                    WebKeys.MESSAGE_BOARDS_MESSAGE, _message);
087    
088                            return
089                                    "/html/portlet/message_boards/asset/discussion_" + template +
090                                            ".jsp";
091                    }
092                    else {
093                            return null;
094                    }
095            }
096    
097            private final MBMessage _message;
098    
099    }