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 TYPE = "layout_revision";
041    
042            @Override
043            public AssetEntry getAssetEntry(long assetEntryId)
044                    throws PortalException, SystemException {
045    
046                    return getAssetEntry(getClassName(), assetEntryId);
047            }
048    
049            @Override
050            public AssetEntry getAssetEntry(String className, long classPK)
051                    throws PortalException, SystemException {
052    
053                    LayoutRevision layoutRevision =
054                            LayoutRevisionLocalServiceUtil.getLayoutRevision(classPK);
055    
056                    LayoutSetBranch layoutSetBranch =
057                            LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(
058                                    layoutRevision.getLayoutSetBranchId());
059    
060                    User user = UserLocalServiceUtil.getUserById(
061                            layoutRevision.getUserId());
062    
063                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.createAssetEntry(
064                            classPK);
065    
066                    assetEntry.setGroupId(layoutRevision.getGroupId());
067                    assetEntry.setCompanyId(user.getCompanyId());
068                    assetEntry.setUserId(user.getUserId());
069                    assetEntry.setUserName(user.getFullName());
070                    assetEntry.setCreateDate(layoutRevision.getCreateDate());
071                    assetEntry.setClassNameId(
072                            PortalUtil.getClassNameId(LayoutRevision.class.getName()));
073                    assetEntry.setClassPK(layoutRevision.getLayoutRevisionId());
074    
075                    StringBundler sb = new StringBundler();
076    
077                    sb.append(layoutRevision.getHTMLTitle(LocaleUtil.getDefault()));
078                    sb.append(" [");
079                    sb.append(layoutSetBranch.getName());
080                    sb.append("]");
081    
082                    assetEntry.setTitle(sb.toString());
083    
084                    return assetEntry;
085            }
086    
087            public AssetRenderer getAssetRenderer(long layoutRevisionId, int type)
088                    throws PortalException, SystemException {
089    
090                    LayoutRevision layoutRevision =
091                            LayoutRevisionLocalServiceUtil.getLayoutRevision(layoutRevisionId);
092    
093                    LayoutRevisionAssetRenderer layoutRevisionAssetRenderer =
094                            new LayoutRevisionAssetRenderer(layoutRevision);
095    
096                    layoutRevisionAssetRenderer.setAssetRendererType(type);
097    
098                    return layoutRevisionAssetRenderer;
099            }
100    
101            public String getClassName() {
102                    return LayoutRevision.class.getName();
103            }
104    
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    }