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.trash;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.trash.BaseTrashRenderer;
019    import com.liferay.portal.kernel.util.HtmlUtil;
020    import com.liferay.portal.kernel.workflow.WorkflowConstants;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portal.util.PortletKeys;
023    import com.liferay.portal.util.WebKeys;
024    import com.liferay.portlet.messageboards.model.MBMessage;
025    import com.liferay.portlet.messageboards.model.MBMessageDisplay;
026    import com.liferay.portlet.messageboards.model.MBThread;
027    import com.liferay.portlet.messageboards.model.MBThreadConstants;
028    import com.liferay.portlet.messageboards.model.MBTreeWalker;
029    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
030    import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
031    
032    import java.util.Locale;
033    
034    import javax.portlet.PortletRequest;
035    import javax.portlet.PortletResponse;
036    import javax.portlet.RenderRequest;
037    import javax.portlet.RenderResponse;
038    
039    /**
040     * @author Zsolt Berentey
041     */
042    public class MBThreadTrashRenderer extends BaseTrashRenderer {
043    
044            public static final String TYPE = "message_thread";
045    
046            public MBThreadTrashRenderer(MBThread thread) throws PortalException {
047                    _thread = thread;
048    
049                    _rootMessage = MBMessageLocalServiceUtil.getMBMessage(
050                            thread.getRootMessageId());
051            }
052    
053            @Override
054            public String getClassName() {
055                    return MBThread.class.getName();
056            }
057    
058            @Override
059            public long getClassPK() {
060                    return _thread.getPrimaryKey();
061            }
062    
063            @Override
064            public String getIconCssClass() {
065                    return "icon-comments";
066            }
067    
068            @Override
069            public String getIconPath(ThemeDisplay themeDisplay) {
070                    return themeDisplay.getPathThemeImages() + "/common/conversation.png";
071            }
072    
073            @Override
074            public String getPortletId() {
075                    return PortletKeys.MESSAGE_BOARDS;
076            }
077    
078            @Override
079            public String getSummary(
080                    PortletRequest portletRequest, PortletResponse portletResponse) {
081    
082                    return null;
083            }
084    
085            @Override
086            public String getTitle(Locale locale) {
087                    return HtmlUtil.stripHtml(_rootMessage.getSubject());
088            }
089    
090            @Override
091            public String getType() {
092                    return TYPE;
093            }
094    
095            @Override
096            public String render(
097                            RenderRequest renderRequest, RenderResponse renderResponse,
098                            String template)
099                    throws Exception {
100    
101                    MBMessageDisplay messageDisplay =
102                            MBMessageServiceUtil.getMessageDisplay(
103                                    _rootMessage.getMessageId(), WorkflowConstants.STATUS_ANY,
104                                    MBThreadConstants.THREAD_VIEW_TREE, false);
105    
106                    renderRequest.setAttribute(
107                            WebKeys.MESSAGE_BOARDS_MESSAGE, messageDisplay);
108    
109                    MBTreeWalker treeWalker = messageDisplay.getTreeWalker();
110    
111                    renderRequest.setAttribute(
112                            WebKeys.MESSAGE_BOARDS_TREE_WALKER, treeWalker);
113                    renderRequest.setAttribute(
114                            WebKeys.MESSAGE_BOARDS_TREE_WALKER_CATEGORY,
115                            messageDisplay.getCategory());
116                    renderRequest.setAttribute(
117                            WebKeys.MESSAGE_BOARDS_TREE_WALKER_CUR_MESSAGE,
118                            treeWalker.getRoot());
119                    renderRequest.setAttribute(
120                            WebKeys.MESSAGE_BOARDS_TREE_WALKER_DEPTH, new Integer(0));
121                    renderRequest.setAttribute(
122                            WebKeys.MESSAGE_BOARDS_TREE_WALKER_LAST_NODE, Boolean.FALSE);
123                    renderRequest.setAttribute(
124                            WebKeys.MESSAGE_BOARDS_TREE_WALKER_SEL_MESSAGE, _rootMessage);
125                    renderRequest.setAttribute(
126                            WebKeys.MESSAGE_BOARDS_TREE_WALKER_THREAD,
127                            messageDisplay.getThread());
128    
129                    return "/html/portlet/message_boards/view_thread_tree.jsp";
130            }
131    
132            private final MBMessage _rootMessage;
133            private final MBThread _thread;
134    
135    }