001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.asset;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.util.LocaleUtil;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.model.LayoutRevision;
021    import com.liferay.portal.model.LayoutSetBranch;
022    import com.liferay.portal.model.User;
023    import com.liferay.portal.service.LayoutRevisionLocalServiceUtil;
024    import com.liferay.portal.service.LayoutSetBranchLocalServiceUtil;
025    import com.liferay.portal.service.UserLocalServiceUtil;
026    import com.liferay.portal.theme.ThemeDisplay;
027    import com.liferay.portal.util.PortalUtil;
028    import com.liferay.portlet.asset.model.AssetEntry;
029    import com.liferay.portlet.asset.model.AssetRenderer;
030    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
031    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
032    
033    /**
034     * @author Raymond Aug??
035     */
036    public class LayoutRevisionAssetRendererFactory
037            extends BaseAssetRendererFactory {
038    
039            public static final String TYPE = "layout_revision";
040    
041            public LayoutRevisionAssetRendererFactory() {
042                    setCategorizable(false);
043                    setSelectable(false);
044            }
045    
046            @Override
047            public AssetEntry getAssetEntry(long assetEntryId) throws PortalException {
048                    return getAssetEntry(getClassName(), assetEntryId);
049            }
050    
051            @Override
052            public AssetEntry getAssetEntry(String className, long classPK)
053                    throws PortalException {
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(4);
078    
079                    sb.append(layoutRevision.getHTMLTitle(LocaleUtil.getSiteDefault()));
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 {
092    
093                    LayoutRevision layoutRevision =
094                            LayoutRevisionLocalServiceUtil.getLayoutRevision(layoutRevisionId);
095    
096                    LayoutRevisionAssetRenderer layoutRevisionAssetRenderer =
097                            new LayoutRevisionAssetRenderer(layoutRevision);
098    
099                    layoutRevisionAssetRenderer.setAssetRendererType(type);
100    
101                    return layoutRevisionAssetRenderer;
102            }
103    
104            @Override
105            public String getClassName() {
106                    return LayoutRevision.class.getName();
107            }
108    
109            @Override
110            public String getIconCssClass() {
111                    return "icon-file";
112            }
113    
114            @Override
115            public String getType() {
116                    return TYPE;
117            }
118    
119            @Override
120            protected String getIconPath(ThemeDisplay themeDisplay) {
121                    return themeDisplay.getPathThemeImages() + "/common/pages.png";
122            }
123    
124    }