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.LiferayPortletRequest;
020    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021    import com.liferay.portal.kernel.util.HtmlUtil;
022    import com.liferay.portal.security.permission.ActionKeys;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portal.util.PortletKeys;
026    import com.liferay.portal.util.WebKeys;
027    import com.liferay.portlet.asset.model.AssetRendererFactory;
028    import com.liferay.portlet.asset.model.BaseAssetRenderer;
029    import com.liferay.portlet.messageboards.model.MBCategory;
030    import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
031    
032    import java.util.Locale;
033    
034    import javax.portlet.PortletRequest;
035    import javax.portlet.PortletURL;
036    import javax.portlet.RenderRequest;
037    import javax.portlet.RenderResponse;
038    import javax.portlet.WindowState;
039    
040    /**
041     * @author Julio Camarero
042     * @author Juan Fern??ndez
043     * @author Sergio Gonz??lez
044     * @author Jonathan Lee
045     */
046    public class MBCategoryAssetRenderer extends BaseAssetRenderer {
047    
048            public MBCategoryAssetRenderer(MBCategory category) {
049                    _category = category;
050            }
051    
052            @Override
053            public String getClassName() {
054                    return MBCategory.class.getName();
055            }
056    
057            @Override
058            public long getClassPK() {
059                    return _category.getCategoryId();
060            }
061    
062            @Override
063            public long getGroupId() {
064                    return _category.getGroupId();
065            }
066    
067            @Override
068            public int getStatus() {
069                    return _category.getStatus();
070            }
071    
072            @Override
073            public String getSummary(Locale locale) {
074                    return HtmlUtil.stripHtml(_category.getDescription());
075            }
076    
077            @Override
078            public String getTitle(Locale locale) {
079                    return _category.getName();
080            }
081    
082            @Override
083            public PortletURL getURLEdit(
084                            LiferayPortletRequest liferayPortletRequest,
085                            LiferayPortletResponse liferayPortletResponse)
086                    throws Exception {
087    
088                    PortletURL portletURL = liferayPortletResponse.createLiferayPortletURL(
089                            getControlPanelPlid(liferayPortletRequest),
090                            PortletKeys.MESSAGE_BOARDS, PortletRequest.RENDER_PHASE);
091    
092                    portletURL.setParameter(
093                            "struts_action", "/message_boards/edit_category");
094                    portletURL.setParameter(
095                            "mbCategoryId", String.valueOf(_category.getCategoryId()));
096    
097                    return portletURL;
098            }
099    
100            @Override
101            public PortletURL getURLView(
102                            LiferayPortletResponse liferayPortletResponse,
103                            WindowState windowState)
104                    throws Exception {
105    
106                    AssetRendererFactory assetRendererFactory = getAssetRendererFactory();
107    
108                    PortletURL portletURL = assetRendererFactory.getURLView(
109                            liferayPortletResponse, windowState);
110    
111                    portletURL.setParameter("struts_action", "/message_boards/view");
112                    portletURL.setParameter(
113                            "mbCategoryId", String.valueOf(_category.getCategoryId()));
114                    portletURL.setWindowState(windowState);
115    
116                    return portletURL;
117            }
118    
119            @Override
120            public String getURLViewInContext(
121                    LiferayPortletRequest liferayPortletRequest,
122                    LiferayPortletResponse liferayPortletResponse,
123                    String noSuchEntryRedirect) {
124    
125                    return getURLViewInContext(
126                            liferayPortletRequest, noSuchEntryRedirect,
127                            "/message_boards/find_category", "mbCategoryId",
128                            _category.getCategoryId());
129            }
130    
131            @Override
132            public long getUserId() {
133                    return _category.getUserId();
134            }
135    
136            @Override
137            public String getUserName() {
138                    return _category.getUserName();
139            }
140    
141            @Override
142            public String getUuid() {
143                    return _category.getUuid();
144            }
145    
146            @Override
147            public boolean hasEditPermission(PermissionChecker permissionChecker)
148                    throws PortalException, SystemException {
149    
150                    return MBCategoryPermission.contains(
151                            permissionChecker, _category, ActionKeys.UPDATE);
152            }
153    
154            @Override
155            public boolean hasViewPermission(PermissionChecker permissionChecker)
156                    throws PortalException, SystemException {
157    
158                    return MBCategoryPermission.contains(
159                            permissionChecker, _category, ActionKeys.VIEW);
160            }
161    
162            @Override
163            public String render(
164                            RenderRequest renderRequest, RenderResponse renderResponse,
165                            String template)
166                    throws Exception {
167    
168                    if (template.equals(TEMPLATE_ABSTRACT) ||
169                            template.equals(TEMPLATE_FULL_CONTENT)) {
170    
171                            renderRequest.setAttribute(
172                                    WebKeys.MESSAGE_BOARDS_CATEGORY, _category);
173    
174                            return "/html/portlet/message_boards/asset/" + template + ".jsp";
175                    }
176                    else {
177                            return null;
178                    }
179            }
180    
181            @Override
182            protected String getIconPath(ThemeDisplay themeDisplay) {
183                    return themeDisplay.getPathThemeImages() + "/common/conversation.png";
184            }
185    
186            private MBCategory _category;
187    
188    }