001
014
015 package com.liferay.portlet.blogs.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.security.permission.ActionKeys;
022 import com.liferay.portal.security.permission.PermissionChecker;
023 import com.liferay.portal.theme.ThemeDisplay;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portal.util.WebKeys;
026 import com.liferay.portlet.PortletURLFactoryUtil;
027 import com.liferay.portlet.asset.model.AssetRenderer;
028 import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
029 import com.liferay.portlet.blogs.model.BlogsEntry;
030 import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
031 import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
032 import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
033 import com.liferay.portlet.blogs.service.permission.BlogsPermission;
034
035 import javax.portlet.PortletRequest;
036 import javax.portlet.PortletURL;
037
038 import javax.servlet.http.HttpServletRequest;
039
040
046 public class BlogsEntryAssetRendererFactory extends BaseAssetRendererFactory {
047
048 public static final String CLASS_NAME = BlogsEntry.class.getName();
049
050 public static final String TYPE = "blog";
051
052 @Override
053 public AssetRenderer getAssetRenderer(long classPK, int type)
054 throws PortalException, SystemException {
055
056 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
057
058 return new BlogsEntryAssetRenderer(entry);
059 }
060
061 @Override
062 public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
063 throws PortalException, SystemException {
064
065 BlogsEntry entry = BlogsEntryServiceUtil.getEntry(groupId, urlTitle);
066
067 return new BlogsEntryAssetRenderer(entry);
068 }
069
070 @Override
071 public String getClassName() {
072 return CLASS_NAME;
073 }
074
075 @Override
076 public String getType() {
077 return TYPE;
078 }
079
080 @Override
081 public PortletURL getURLAdd(
082 LiferayPortletRequest liferayPortletRequest,
083 LiferayPortletResponse liferayPortletResponse)
084 throws PortalException, SystemException {
085
086 HttpServletRequest request =
087 liferayPortletRequest.getHttpServletRequest();
088
089 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
090 WebKeys.THEME_DISPLAY);
091
092 if (!BlogsPermission.contains(
093 themeDisplay.getPermissionChecker(),
094 themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
095
096 return null;
097 }
098
099 PortletURL portletURL = PortletURLFactoryUtil.create(
100 request, PortletKeys.BLOGS, getControlPanelPlid(themeDisplay),
101 PortletRequest.RENDER_PHASE);
102
103 portletURL.setParameter("struts_action", "/blogs/edit_entry");
104
105 return portletURL;
106 }
107
108 @Override
109 public boolean hasPermission(
110 PermissionChecker permissionChecker, long classPK, String actionId)
111 throws Exception {
112
113 return BlogsEntryPermission.contains(
114 permissionChecker, classPK, actionId);
115 }
116
117 @Override
118 public boolean isLinkable() {
119 return _LINKABLE;
120 }
121
122 @Override
123 protected String getIconPath(ThemeDisplay themeDisplay) {
124 return themeDisplay.getPathThemeImages() + "/blogs/blogs.png";
125 }
126
127 private static final boolean _LINKABLE = true;
128
129 }