001
014
015 package com.liferay.portal.asset;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.util.LocaleUtil;
020 import com.liferay.portal.kernel.util.StringBundler;
021 import com.liferay.portal.model.LayoutRevision;
022 import com.liferay.portal.model.LayoutSetBranch;
023 import com.liferay.portal.model.User;
024 import com.liferay.portal.service.LayoutRevisionLocalServiceUtil;
025 import com.liferay.portal.service.LayoutSetBranchLocalServiceUtil;
026 import com.liferay.portal.service.UserLocalServiceUtil;
027 import com.liferay.portal.theme.ThemeDisplay;
028 import com.liferay.portal.util.PortalUtil;
029 import com.liferay.portlet.asset.model.AssetEntry;
030 import com.liferay.portlet.asset.model.AssetRenderer;
031 import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
032 import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
033
034
037 public class LayoutRevisionAssetRendererFactory
038 extends BaseAssetRendererFactory {
039
040 public static final String CLASS_NAME = LayoutRevision.class.getName();
041
042 public static final String TYPE = "layout_revision";
043
044 @Override
045 public AssetEntry getAssetEntry(long assetEntryId)
046 throws PortalException, SystemException {
047
048 return getAssetEntry(getClassName(), assetEntryId);
049 }
050
051 @Override
052 public AssetEntry getAssetEntry(String className, long classPK)
053 throws PortalException, SystemException {
054
055 LayoutRevision layoutRevision =
056 LayoutRevisionLocalServiceUtil.getLayoutRevision(classPK);
057
058 LayoutSetBranch layoutSetBranch =
059 LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(
060 layoutRevision.getLayoutSetBranchId());
061
062 User user = UserLocalServiceUtil.getUserById(
063 layoutRevision.getUserId());
064
065 AssetEntry assetEntry = AssetEntryLocalServiceUtil.createAssetEntry(
066 classPK);
067
068 assetEntry.setGroupId(layoutRevision.getGroupId());
069 assetEntry.setCompanyId(user.getCompanyId());
070 assetEntry.setUserId(user.getUserId());
071 assetEntry.setUserName(user.getFullName());
072 assetEntry.setCreateDate(layoutRevision.getCreateDate());
073 assetEntry.setClassNameId(
074 PortalUtil.getClassNameId(LayoutRevision.class.getName()));
075 assetEntry.setClassPK(layoutRevision.getLayoutRevisionId());
076
077 StringBundler sb = new StringBundler();
078
079 sb.append(layoutRevision.getHTMLTitle(LocaleUtil.getDefault()));
080 sb.append(" [");
081 sb.append(layoutSetBranch.getName());
082 sb.append("]");
083
084 assetEntry.setTitle(sb.toString());
085
086 return assetEntry;
087 }
088
089 @Override
090 public AssetRenderer getAssetRenderer(long layoutRevisionId, int type)
091 throws PortalException, SystemException {
092
093 LayoutRevision layoutRevision =
094 LayoutRevisionLocalServiceUtil.getLayoutRevision(layoutRevisionId);
095
096 return new LayoutRevisionAssetRenderer(layoutRevision);
097 }
098
099 @Override
100 public String getClassName() {
101 return CLASS_NAME;
102 }
103
104 @Override
105 public String getType() {
106 return TYPE;
107 }
108
109 @Override
110 public boolean isCategorizable() {
111 return false;
112 }
113
114 @Override
115 public boolean isSelectable() {
116 return _SELECTABLE;
117 }
118
119 @Override
120 protected String getIconPath(ThemeDisplay themeDisplay) {
121 return themeDisplay.getPathThemeImages() + "/common/pages.png";
122 }
123
124 private static final boolean _SELECTABLE = false;
125
126 }