From 23d65008605e486aa54605537b36567a7f05a5a6 Mon Sep 17 00:00:00 2001 From: Zsolt Berentey Date: Fri, 4 May 2012 18:01:49 +0200 Subject: [PATCH] LPS-27122 Create a TrashRenderer interface and implement it for all supported models --- .../blogs/asset/BlogsEntryAssetRenderer.java | 37 +++++++++++-- .../asset/DLFileEntryAssetRenderer.java | 40 ++++++++++++-- .../service/impl/TrashEntryServiceImpl.java | 30 ++++------ .../portal/kernel/trash/BaseTrashHandler.java | 23 +++++--- .../portal/kernel/trash/TrashHandler.java | 29 ++++------ .../portal/kernel/trash/TrashRenderer.java | 53 ++++++++++++++++++ portal-web/docroot/WEB-INF/struts-config.xml | 2 +- portal-web/docroot/WEB-INF/tiles-defs.xml | 4 ++ .../docroot/html/portlet/trash/init.jsp | 5 +- .../docroot/html/portlet/trash/view.jsp | 35 ++++++------ .../html/portlet/trash/view_content.jsp | 55 +++++++++++++++++++ 11 files changed, 235 insertions(+), 78 deletions(-) create mode 100644 portal-service/src/com/liferay/portal/kernel/trash/TrashRenderer.java create mode 100644 portal-web/docroot/html/portlet/trash/view_content.jsp diff --git a/portal-impl/src/com/liferay/portlet/blogs/asset/BlogsEntryAssetRenderer.java b/portal-impl/src/com/liferay/portlet/blogs/asset/BlogsEntryAssetRenderer.java index 37780be8512acc..25e9a00a371fde 100644 --- a/portal-impl/src/com/liferay/portlet/blogs/asset/BlogsEntryAssetRenderer.java +++ b/portal-impl/src/com/liferay/portlet/blogs/asset/BlogsEntryAssetRenderer.java @@ -16,6 +16,7 @@ import com.liferay.portal.kernel.portlet.LiferayPortletRequest; import com.liferay.portal.kernel.portlet.LiferayPortletResponse; +import com.liferay.portal.kernel.trash.TrashRenderer; import com.liferay.portal.kernel.util.HtmlUtil; import com.liferay.portal.security.permission.ActionKeys; import com.liferay.portal.security.permission.PermissionChecker; @@ -23,6 +24,7 @@ import com.liferay.portal.util.PortletKeys; import com.liferay.portal.util.PropsValues; import com.liferay.portal.util.WebKeys; +import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil; import com.liferay.portlet.asset.model.BaseAssetRenderer; import com.liferay.portlet.blogs.model.BlogsEntry; import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission; @@ -39,8 +41,10 @@ * @author Jorge Ferrer * @author Juan Fernández * @author Sergio González + * @author Zsolt Berentey */ -public class BlogsEntryAssetRenderer extends BaseAssetRenderer { +public class BlogsEntryAssetRenderer extends BaseAssetRenderer + implements TrashRenderer { public BlogsEntryAssetRenderer(BlogsEntry entry) { _entry = entry; @@ -64,6 +68,15 @@ public long getGroupId() { return _entry.getGroupId(); } + @Override + public String getIconPath(ThemeDisplay themeDisplay) { + return getAssetRendererFactory().getIconPath(themeDisplay); + } + + public String getPortletId() { + return getAssetRendererFactory().getPortletId(); + } + public String getSummary(Locale locale) { return HtmlUtil.stripHtml(_entry.getDescription()); } @@ -72,6 +85,10 @@ public String getTitle(Locale locale) { return _entry.getTitle(); } + public String getType() { + return BlogsEntryAssetRendererFactory.TYPE; + } + @Override public PortletURL getURLEdit( LiferayPortletRequest liferayPortletRequest, @@ -129,6 +146,11 @@ public String getUuid() { return _entry.getUuid(); } + public boolean hasDeletePermission(PermissionChecker permissionChecker) { + return BlogsEntryPermission.contains( + permissionChecker, _entry, ActionKeys.DELETE); + } + @Override public boolean hasEditPermission(PermissionChecker permissionChecker) { return BlogsEntryPermission.contains( @@ -163,11 +185,18 @@ public String render( } } - @Override - protected String getIconPath(ThemeDisplay themeDisplay) { - return themeDisplay.getPathThemeImages() + "/blogs/blogs.png"; + private BlogsEntryAssetRendererFactory getAssetRendererFactory() { + if (_factory == null) { + _factory = (BlogsEntryAssetRendererFactory) + AssetRendererFactoryRegistryUtil. + getAssetRendererFactoryByClassName( + BlogsEntryAssetRendererFactory.CLASS_NAME); + } + + return _factory; } private BlogsEntry _entry; + private BlogsEntryAssetRendererFactory _factory; } \ No newline at end of file diff --git a/portal-impl/src/com/liferay/portlet/documentlibrary/asset/DLFileEntryAssetRenderer.java b/portal-impl/src/com/liferay/portlet/documentlibrary/asset/DLFileEntryAssetRenderer.java index 0b1a81ff5c1018..8a8106d63de1a8 100644 --- a/portal-impl/src/com/liferay/portlet/documentlibrary/asset/DLFileEntryAssetRenderer.java +++ b/portal-impl/src/com/liferay/portlet/documentlibrary/asset/DLFileEntryAssetRenderer.java @@ -20,6 +20,7 @@ import com.liferay.portal.kernel.portlet.LiferayPortletResponse; import com.liferay.portal.kernel.repository.model.FileEntry; import com.liferay.portal.kernel.repository.model.FileVersion; +import com.liferay.portal.kernel.trash.TrashRenderer; import com.liferay.portal.kernel.util.HtmlUtil; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.security.permission.ActionKeys; @@ -28,6 +29,7 @@ import com.liferay.portal.util.PortletKeys; import com.liferay.portal.util.PropsValues; import com.liferay.portal.util.WebKeys; +import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil; import com.liferay.portlet.asset.model.BaseAssetRenderer; import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants; import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission; @@ -44,8 +46,10 @@ * @author Julio Camarero * @author Juan Fernández * @author Sergio González + * @author Zsolt Berentey */ -public class DLFileEntryAssetRenderer extends BaseAssetRenderer { +public class DLFileEntryAssetRenderer extends BaseAssetRenderer + implements TrashRenderer { public DLFileEntryAssetRenderer( FileEntry fileEntry, FileVersion fileVersion) { @@ -80,6 +84,15 @@ public long getGroupId() { return _fileEntry.getGroupId(); } + @Override + public String getIconPath(ThemeDisplay themeDisplay) { + return getAssetRendererFactory().getIconPath(themeDisplay); + } + + public String getPortletId() { + return getAssetRendererFactory().getPortletId(); + } + public String getSummary(Locale locale) { return HtmlUtil.stripHtml(_fileEntry.getDescription()); } @@ -88,6 +101,10 @@ public String getTitle(Locale locale) { return _fileVersion.getTitle(); } + public String getType() { + return DLFileEntryAssetRendererFactory.TYPE; + } + @Override public String getURLDownload(ThemeDisplay themeDisplay) { return DLUtil.getPreviewURL( @@ -149,6 +166,13 @@ public String getUuid() { return _fileEntry.getUuid(); } + public boolean hasDeletePermission(PermissionChecker permissionChecker) + throws PortalException, SystemException { + + return DLFileEntryPermission.contains( + permissionChecker, _fileEntry.getFileEntryId(), ActionKeys.DELETE); + } + @Override public boolean hasEditPermission(PermissionChecker permissionChecker) throws PortalException, SystemException { @@ -195,12 +219,18 @@ public String render( } } - @Override - protected String getIconPath(ThemeDisplay themeDisplay) { - return themeDisplay.getPathThemeImages() + "/file_system/small/" + - _fileEntry.getIcon() + ".png"; + private DLFileEntryAssetRendererFactory getAssetRendererFactory() { + if (_factory == null) { + _factory = (DLFileEntryAssetRendererFactory) + AssetRendererFactoryRegistryUtil. + getAssetRendererFactoryByClassName( + DLFileEntryAssetRendererFactory.CLASS_NAME); + } + + return _factory; } + private DLFileEntryAssetRendererFactory _factory; private FileEntry _fileEntry; private FileVersion _fileVersion; diff --git a/portal-impl/src/com/liferay/portlet/trash/service/impl/TrashEntryServiceImpl.java b/portal-impl/src/com/liferay/portlet/trash/service/impl/TrashEntryServiceImpl.java index 6e069b2ea0a269..b039ff5827914a 100644 --- a/portal-impl/src/com/liferay/portlet/trash/service/impl/TrashEntryServiceImpl.java +++ b/portal-impl/src/com/liferay/portlet/trash/service/impl/TrashEntryServiceImpl.java @@ -18,13 +18,11 @@ import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.trash.TrashHandler; import com.liferay.portal.kernel.trash.TrashHandlerRegistryUtil; +import com.liferay.portal.kernel.trash.TrashRenderer; import com.liferay.portal.kernel.util.OrderByComparator; import com.liferay.portal.security.auth.PrincipalException; -import com.liferay.portal.security.permission.ActionKeys; import com.liferay.portal.security.permission.PermissionChecker; import com.liferay.portal.util.PropsValues; -import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil; -import com.liferay.portlet.asset.model.AssetRendererFactory; import com.liferay.portlet.trash.model.TrashEntry; import com.liferay.portlet.trash.service.base.TrashEntryServiceBaseImpl; @@ -59,24 +57,20 @@ public void deleteEntries(long groupId) String className = entry.getClassName(); long classPK = entry.getClassPK(); - AssetRendererFactory assetRendererFactory = - AssetRendererFactoryRegistryUtil. - getAssetRendererFactoryByClassName(className); - try { - if (assetRendererFactory.hasPermission( - permissionChecker, classPK, ActionKeys.DELETE)) { + TrashHandler trashHandler = + TrashHandlerRegistryUtil.getTrashHandler(className); - TrashHandler trashHandler = - TrashHandlerRegistryUtil.getTrashHandler(className); + TrashRenderer trashRenderer = trashHandler.getTrashRenderer( + classPK); + if (trashRenderer.hasDeletePermission(permissionChecker)) { trashHandler.deleteTrashEntry(classPK); } } catch (Exception e) { } } - } /** @@ -124,14 +118,14 @@ public Object[] getEntries( String className = entry.getClassName(); long classPK = entry.getClassPK(); - AssetRendererFactory assetRendererFactory = - AssetRendererFactoryRegistryUtil. - getAssetRendererFactoryByClassName(className); - try { - if (assetRendererFactory.hasPermission( - permissionChecker, classPK, ActionKeys.VIEW)) { + TrashHandler trashHandler = + TrashHandlerRegistryUtil.getTrashHandler(className); + + TrashRenderer trashRenderer = trashHandler.getTrashRenderer( + classPK); + if (trashRenderer.hasViewPermission(permissionChecker)) { filteredEntries.add(entry); } } diff --git a/portal-service/src/com/liferay/portal/kernel/trash/BaseTrashHandler.java b/portal-service/src/com/liferay/portal/kernel/trash/BaseTrashHandler.java index 4949a33cf09a8c..1805751b8187ae 100644 --- a/portal-service/src/com/liferay/portal/kernel/trash/BaseTrashHandler.java +++ b/portal-service/src/com/liferay/portal/kernel/trash/BaseTrashHandler.java @@ -37,6 +37,7 @@ * * * @author Alexander Chow + * @author Zsolt Berentey */ public abstract class BaseTrashHandler implements TrashHandler { @@ -46,22 +47,21 @@ public void deleteTrashEntry(long classPK) deleteTrashEntries(new long[] {classPK}); } - public AssetRenderer getAssetRenderer(long classPK) + public TrashRenderer getTrashRenderer(long classPK) throws PortalException, SystemException { AssetRendererFactory assetRendererFactory = getAssetRendererFactory(); if (assetRendererFactory != null) { - return assetRendererFactory.getAssetRenderer(classPK); - } - else { - return null; + AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer( + classPK); + + if (assetRenderer instanceof TrashRenderer) { + return (TrashRenderer)assetRenderer; + } } - } - public AssetRendererFactory getAssetRendererFactory() { - return AssetRendererFactoryRegistryUtil. - getAssetRendererFactoryByClassName(getClassName()); + return null; } public void restoreTrashEntry(long classPK) @@ -70,4 +70,9 @@ public void restoreTrashEntry(long classPK) restoreTrashEntries(new long[] {classPK}); } + private AssetRendererFactory getAssetRendererFactory() { + return AssetRendererFactoryRegistryUtil. + getAssetRendererFactoryByClassName(getClassName()); + } + } \ No newline at end of file diff --git a/portal-service/src/com/liferay/portal/kernel/trash/TrashHandler.java b/portal-service/src/com/liferay/portal/kernel/trash/TrashHandler.java index a53db7e512296a..6efd333617778b 100644 --- a/portal-service/src/com/liferay/portal/kernel/trash/TrashHandler.java +++ b/portal-service/src/com/liferay/portal/kernel/trash/TrashHandler.java @@ -16,8 +16,6 @@ import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; -import com.liferay.portlet.asset.model.AssetRenderer; -import com.liferay.portlet.asset.model.AssetRendererFactory; /** * Represents the interface to manage the basic operations of the Recycle Bin. @@ -76,31 +74,24 @@ public void deleteTrashEntry(long classPK) throws PortalException, SystemException; /** - * Returns the asset renderer associated to the trash entry. + * Returns the class name of the entry. + * + * @return the class name of the entry + */ + public String getClassName(); + + /** + * Returns the trash renderer associated to the trash entry. * * @param classPK the primary key of the trash entry - * @return the asset renderer associated to the trash entry + * @return the trash renderer associated to the trash entry * @throws PortalException if an entry with the primary key could not be * found * @throws SystemException if a system exception occurred */ - public AssetRenderer getAssetRenderer(long classPK) + public TrashRenderer getTrashRenderer(long classPK) throws PortalException, SystemException; - /** - * Returns the asset renderer factory for the entry entity - * - * @return the asset renderer factory for the entry entity - */ - public AssetRendererFactory getAssetRendererFactory(); - - /** - * Returns the class name of the entry. - * - * @return the class name of the entry - */ - public String getClassName(); - /** * Restores all entries with the primary keys. * diff --git a/portal-service/src/com/liferay/portal/kernel/trash/TrashRenderer.java b/portal-service/src/com/liferay/portal/kernel/trash/TrashRenderer.java new file mode 100644 index 00000000000000..7e06c3a822c62c --- /dev/null +++ b/portal-service/src/com/liferay/portal/kernel/trash/TrashRenderer.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.kernel.trash; + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.security.permission.PermissionChecker; + +import java.util.Locale; + +import javax.portlet.PortletRequest; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +/** + * @author Zsolt Berentey + */ +public interface TrashRenderer { + + public static final String TEMPLATE_DEFAULT = "default"; + + public String getIconPath(PortletRequest portletRequest); + + public String getPortletId(); + + public String getTitle(Locale locale); + + public String getType(); + + public boolean hasDeletePermission(PermissionChecker permissionChecker) + throws PortalException, SystemException; + + public boolean hasViewPermission(PermissionChecker permissionChecker) + throws PortalException, SystemException; + + public String render( + RenderRequest renderRequest, RenderResponse renderResponse, + String template) + throws Exception; + +} \ No newline at end of file diff --git a/portal-web/docroot/WEB-INF/struts-config.xml b/portal-web/docroot/WEB-INF/struts-config.xml index 0e8dc2230cd833..a890a92f60b3f2 100644 --- a/portal-web/docroot/WEB-INF/struts-config.xml +++ b/portal-web/docroot/WEB-INF/struts-config.xml @@ -1861,7 +1861,7 @@ - + diff --git a/portal-web/docroot/WEB-INF/tiles-defs.xml b/portal-web/docroot/WEB-INF/tiles-defs.xml index df715eec95c69d..31d9aed94117b8 100644 --- a/portal-web/docroot/WEB-INF/tiles-defs.xml +++ b/portal-web/docroot/WEB-INF/tiles-defs.xml @@ -1549,6 +1549,10 @@ + + + + diff --git a/portal-web/docroot/html/portlet/trash/init.jsp b/portal-web/docroot/html/portlet/trash/init.jsp index d714501cd580b3..0f8aac85b11da5 100644 --- a/portal-web/docroot/html/portlet/trash/init.jsp +++ b/portal-web/docroot/html/portlet/trash/init.jsp @@ -18,12 +18,11 @@ <%@ page import="com.liferay.portal.kernel.trash.TrashHandler" %><%@ page import="com.liferay.portal.kernel.trash.TrashHandlerRegistryUtil" %><%@ -page import="com.liferay.portlet.asset.model.AssetEntry" %><%@ +page import="com.liferay.portal.kernel.trash.TrashRenderer" %><%@ page import="com.liferay.portlet.asset.model.AssetRenderer" %><%@ -page import="com.liferay.portlet.asset.model.AssetRendererFactory" %><%@ -page import="com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil" %><%@ page import="com.liferay.portlet.trash.model.TrashEntry" %><%@ page import="com.liferay.portlet.trash.search.EntrySearch" %><%@ +page import="com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil" %><%@ page import="com.liferay.portlet.trash.service.TrashEntryServiceUtil" %> <%@ include file="/html/portlet/trash/init-ext.jsp" %> diff --git a/portal-web/docroot/html/portlet/trash/view.jsp b/portal-web/docroot/html/portlet/trash/view.jsp index 0f46ce17386712..981916ef57c99a 100644 --- a/portal-web/docroot/html/portlet/trash/view.jsp +++ b/portal-web/docroot/html/portlet/trash/view.jsp @@ -81,39 +81,36 @@ portletURL.setParameter("tabs1", tabs1); <% TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entry.getClassName()); - PortletURL viewFullContentURL = renderResponse.createRenderURL(); + TrashRenderer trashRenderer = trashHandler.getTrashRenderer(entry.getClassPK()); - viewFullContentURL.setParameter("struts_action", "/trash/view_content"); - viewFullContentURL.setParameter("redirect", currentURL); + String viewContentURL = null; - AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(entry.getClassName(), entry.getClassPK()); + if (trashRenderer != null) { + PortletURL portletURL = renderResponse.createRenderURL(); - viewFullContentURL.setParameter("assetEntryId", String.valueOf(assetEntry.getEntryId())); + portletURL.setParameter("struts_action", "/trash/view_content"); + portletURL.setParameter("redirect", currentURL); + portletURL.setParameter("type", trashRenderer.getType()); + portletURL.setParameter("entryId", String.valueOf(entry.getEntryId())); + portletURL.setParameter("showActions", String.valueOf(Boolean.FALSE)); + portletURL.setParameter("showAssetMetadata", String.valueOf(Boolean.TRUE)); + portletURL.setParameter("showEditURL", String.valueOf(Boolean.FALSE)); - AssetRendererFactory assetRendererFactory = trashHandler.getAssetRendererFactory(); - - viewFullContentURL.setParameter("type", assetRendererFactory.getType()); - viewFullContentURL.setParameter("showActions", String.valueOf(Boolean.FALSE)); - viewFullContentURL.setParameter("showAssetMetadata", String.valueOf(Boolean.TRUE)); - viewFullContentURL.setParameter("showEditURL", String.valueOf(Boolean.FALSE)); + viewContentURL = portletURL.toString(); + } %> - - <% - AssetRenderer assetRenderer = trashHandler.getAssetRenderer(entry.getClassPK()); - %> - - + + +<%@ include file="/html/portlet/trash/init.jsp" %> + +
+ + <% + long entryId = ParamUtil.getLong(request, "entryId"); + + TrashEntry trashEntry = TrashEntryLocalServiceUtil.getEntry(entryId); + + TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(trashEntry.getClassName()); + + TrashRenderer trashRenderer = trashHandler.getTrashRenderer(trashEntry.getClassPK()); + + String template = null; + + if (trashRenderer instanceof AssetRenderer) { + template = AssetRenderer.TEMPLATE_FULL_CONTENT; + } + else { + template = TrashRenderer.TEMPLATE_DEFAULT; + } + + String path = trashRenderer.render(renderRequest, renderResponse, template); + String redirect = ParamUtil.getString(request, "redirect"); + String title = trashRenderer.getTitle(locale); + %> + + + + + + + + +
\ No newline at end of file