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.getSiteDefault()));
078                    sb.append(" [");
079                    sb.append(layoutSetBranch.getName());
080                    sb.append("]");
081    
082                    assetEntry.setTitle(sb.toString());
083    
084                    return assetEntry;
085            }
086    
087            @Override
088            public AssetRenderer getAssetRenderer(long layoutRevisionId, int type)
089                    throws PortalException, SystemException {
090    
091                    LayoutRevision layoutRevision =
092                            LayoutRevisionLocalServiceUtil.getLayoutRevision(layoutRevisionId);
093    
094                    LayoutRevisionAssetRenderer layoutRevisionAssetRenderer =
095                            new LayoutRevisionAssetRenderer(layoutRevision);
096    
097                    layoutRevisionAssetRenderer.setAssetRendererType(type);
098    
099                    return layoutRevisionAssetRenderer;
100            }
101    
102            @Override
103            public String getClassName() {
104                    return LayoutRevision.class.getName();
105            }
106    
107            @Override
108            public String getType() {
109                    return TYPE;
110            }
111    
112            @Override
113            public boolean isCategorizable() {
114                    return false;
115            }
116    
117            @Override
118            public boolean isSelectable() {
119                    return _SELECTABLE;
120            }
121    
122            @Override
123            protected String getIconPath(ThemeDisplay themeDisplay) {
124                    return themeDisplay.getPathThemeImages() + "/common/pages.png";
125            }
126    
127            private static final boolean _SELECTABLE = false;
128    
129    }