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.messageboards.asset;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
020    import com.liferay.portal.kernel.portlet.LiferayPortletURL;
021    import com.liferay.portal.util.PortletKeys;
022    import com.liferay.portlet.asset.model.AssetRenderer;
023    import com.liferay.portlet.messageboards.model.MBDiscussion;
024    import com.liferay.portlet.messageboards.model.MBMessage;
025    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
026    
027    import javax.portlet.PortletRequest;
028    import javax.portlet.PortletURL;
029    import javax.portlet.WindowState;
030    import javax.portlet.WindowStateException;
031    
032    /**
033     * @author Jorge Ferrer
034     */
035    public class MBDiscussionAssetRendererFactory
036            extends MBMessageAssetRendererFactory {
037    
038            public static final String TYPE = "discussion";
039    
040            @Override
041            public AssetRenderer getAssetRenderer(long classPK, int type)
042                    throws PortalException, SystemException {
043    
044                    MBMessage message = MBMessageLocalServiceUtil.getMessage(classPK);
045    
046                    MBDiscussionAssetRenderer mbDiscussionAssetRenderer =
047                            new MBDiscussionAssetRenderer(message);
048    
049                    mbDiscussionAssetRenderer.setAssetRendererType(type);
050    
051                    return mbDiscussionAssetRenderer;
052            }
053    
054            @Override
055            public String getClassName() {
056                    return MBDiscussion.class.getName();
057            }
058    
059            @Override
060            public String getType() {
061                    return TYPE;
062            }
063    
064            @Override
065            public PortletURL getURLView(
066                    LiferayPortletResponse liferayPortletResponse,
067                    WindowState windowState) {
068    
069                    LiferayPortletURL liferayPortletURL =
070                            liferayPortletResponse.createLiferayPortletURL(
071                                    PortletKeys.MESSAGE_BOARDS, PortletRequest.RENDER_PHASE);
072    
073                    try {
074                            liferayPortletURL.setWindowState(windowState);
075                    }
076                    catch (WindowStateException wse) {
077                    }
078    
079                    return liferayPortletURL;
080            }
081    
082            @Override
083            public boolean isSelectable() {
084                    return _SELECTABLE;
085            }
086    
087            private static final boolean _SELECTABLE = false;
088    
089    }