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.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    }