001    /**
002     * Copyright (c) 2000-2013 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.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    /**
035     * @author Raymond Aug??
036     */
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    }