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