Skip to content

Commit

Permalink
LPS-27122 Simplify AssetRenderers (moving logic to the base)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliocamarero authored and brianchandotcom committed May 14, 2012
1 parent 23d6500 commit 4a11a9e
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 28 deletions.
Expand Up @@ -55,6 +55,11 @@ public LayoutRevisionAssetRenderer(LayoutRevision layoutRevision) {
}
}

@Override
public String getAssetRendererFactoryClassName() {
return LayoutRevisionAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
return _layoutRevision.getLayoutRevisionId();
}
Expand Down
Expand Up @@ -24,7 +24,6 @@
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;
Expand All @@ -50,6 +49,10 @@ public BlogsEntryAssetRenderer(BlogsEntry entry) {
_entry = entry;
}

public String getAssetRendererFactoryClassName() {
return BlogsEntryAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
return _entry.getEntryId();
}
Expand All @@ -70,7 +73,7 @@ public long getGroupId() {

@Override
public String getIconPath(ThemeDisplay themeDisplay) {
return getAssetRendererFactory().getIconPath(themeDisplay);
return themeDisplay.getPathThemeImages() + "/blogs/blogs.png";
}

public String getPortletId() {
Expand Down Expand Up @@ -185,18 +188,6 @@ public String render(
}
}

private BlogsEntryAssetRendererFactory getAssetRendererFactory() {
if (_factory == null) {
_factory = (BlogsEntryAssetRendererFactory)
AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(
BlogsEntryAssetRendererFactory.CLASS_NAME);
}

return _factory;
}

private BlogsEntry _entry;
private BlogsEntryAssetRendererFactory _factory;

}
Expand Up @@ -44,6 +44,11 @@ public BookmarksEntryAssetRenderer(BookmarksEntry entry) {
_entry = entry;
}

@Override
public String getAssetRendererFactoryClassName() {
return BookmarksEntryAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
return _entry.getEntryId();
}
Expand Down
Expand Up @@ -45,6 +45,11 @@ public CalEventAssetRenderer(CalEvent event) {
_event = event;
}

@Override
public String getAssetRendererFactoryClassName() {
return CalEventAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
return _event.getEventId();
}
Expand Down
Expand Up @@ -42,6 +42,11 @@ public UserAssetRenderer(User user) {
_user = user;
}

@Override
public String getAssetRendererFactoryClassName() {
return UserAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
return _user.getPrimaryKey();
}
Expand Down
Expand Up @@ -29,7 +29,6 @@
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;
Expand Down Expand Up @@ -58,6 +57,10 @@ public DLFileEntryAssetRenderer(
_fileVersion = fileVersion;
}

public String getAssetRendererFactoryClassName() {
return DLFileEntryAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
if (!_fileVersion.isApproved() &&
!_fileVersion.getVersion().equals(
Expand Down Expand Up @@ -86,7 +89,8 @@ public long getGroupId() {

@Override
public String getIconPath(ThemeDisplay themeDisplay) {
return getAssetRendererFactory().getIconPath(themeDisplay);
return themeDisplay.getPathThemeImages() + "/file_system/small/" +
_fileEntry.getIcon() + ".png";
}

public String getPortletId() {
Expand Down Expand Up @@ -219,18 +223,6 @@ public String render(
}
}

private DLFileEntryAssetRendererFactory getAssetRendererFactory() {
if (_factory == null) {
_factory = (DLFileEntryAssetRendererFactory)
AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(
DLFileEntryAssetRendererFactory.CLASS_NAME);
}

return _factory;
}

private DLFileEntryAssetRendererFactory _factory;
private FileEntry _fileEntry;
private FileVersion _fileVersion;

Expand Down
Expand Up @@ -60,6 +60,11 @@ public DDLRecordAssetRenderer(
}
}

@Override
public String getAssetRendererFactoryClassName() {
return DDLRecordAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
return _record.getRecordId();
}
Expand Down
Expand Up @@ -55,6 +55,11 @@ public JournalArticle getArticle() {
return _article;
}

@Override
public String getAssetRendererFactoryClassName() {
return JournalArticleAssetRendererFactory.CLASS_NAME;
}

@Override
public String[] getAvailableLocales() {
return _article.getAvailableLocales();
Expand Down
Expand Up @@ -48,6 +48,11 @@ public MBCategoryAssetRenderer(MBCategory category) {
_category = category;
}

@Override
public String getAssetRendererFactoryClassName() {
return MBCategoryAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
return _category.getCategoryId();
}
Expand Down
Expand Up @@ -48,6 +48,11 @@ public MBMessageAssetRenderer(MBMessage message) {
_message = message;
}

@Override
public String getAssetRendererFactoryClassName() {
return MBCategoryAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
return _message.getMessageId();
}
Expand Down
Expand Up @@ -47,6 +47,11 @@ public WikiPageAssetRenderer(WikiPage page) {
_page = page;
}

@Override
public String getAssetRendererFactoryClassName() {
return WikiPageAssetRendererFactory.CLASS_NAME;
}

public long getClassPK() {
if (!_page.isApproved() &&
(_page.getVersion() != WikiPageConstants.VERSION_DEFAULT)) {
Expand Down
Expand Up @@ -39,6 +39,8 @@ public interface AssetRenderer {

public static final String TEMPLATE_FULL_CONTENT = "full_content";

public String getAssetRendererFactoryClassName();

public String[] getAvailableLocales() throws Exception;

public long getClassPK();
Expand Down
Expand Up @@ -28,6 +28,7 @@
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;

import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;
Expand All @@ -41,6 +42,16 @@
*/
public abstract class BaseAssetRenderer implements AssetRenderer {

public AssetRendererFactory getAssetRendererFactory() {
if (_assetRendererFactory == null) {
_assetRendererFactory = AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(
getAssetRendererFactoryClassName());
}

return _assetRendererFactory;
}

public String[] getAvailableLocales() {
return _AVAILABLE_LOCALES;
}
Expand Down Expand Up @@ -192,6 +203,7 @@ protected String getURLViewInContext(
return sb.toString();
}

private AssetRendererFactory _assetRendererFactory;
private static final String[] _AVAILABLE_LOCALES = new String[0];

}

0 comments on commit 4a11a9e

Please sign in to comment.