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.model.Layout;
020    import com.liferay.portal.model.User;
021    import com.liferay.portal.service.LayoutLocalServiceUtil;
022    import com.liferay.portal.service.UserLocalServiceUtil;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portal.util.PortalUtil;
025    import com.liferay.portlet.asset.model.AssetEntry;
026    import com.liferay.portlet.asset.model.AssetRenderer;
027    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
028    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
029    
030    /**
031     * @author Eduardo Garcia
032     */
033    public class LayoutAssetRendererFactory extends BaseAssetRendererFactory {
034    
035            public static final String TYPE = "layout";
036    
037            @Override
038            public AssetEntry getAssetEntry(long assetEntryId) throws PortalException {
039                    return getAssetEntry(getClassName(), assetEntryId);
040            }
041    
042            @Override
043            public AssetEntry getAssetEntry(String className, long classPK)
044                    throws PortalException {
045    
046                    Layout layout = LayoutLocalServiceUtil.getLayout(classPK);
047    
048                    User user = UserLocalServiceUtil.getUserById(layout.getUserId());
049    
050                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.createAssetEntry(
051                            classPK);
052    
053                    assetEntry.setGroupId(layout.getGroupId());
054                    assetEntry.setCompanyId(user.getCompanyId());
055                    assetEntry.setUserId(user.getUserId());
056                    assetEntry.setUserName(user.getFullName());
057                    assetEntry.setCreateDate(layout.getCreateDate());
058                    assetEntry.setClassNameId(
059                            PortalUtil.getClassNameId(Layout.class.getName()));
060                    assetEntry.setClassPK(layout.getLayoutId());
061                    assetEntry.setTitle(layout.getHTMLTitle(LocaleUtil.getSiteDefault()));
062    
063                    return assetEntry;
064            }
065    
066            @Override
067            public AssetRenderer getAssetRenderer(long plid, int type)
068                    throws PortalException {
069    
070                    Layout layout = LayoutLocalServiceUtil.getLayout(plid);
071    
072                    LayoutAssetRenderer layoutAssetRenderer = new LayoutAssetRenderer(
073                            layout);
074    
075                    layoutAssetRenderer.setAssetRendererType(type);
076    
077                    return layoutAssetRenderer;
078            }
079    
080            @Override
081            public String getClassName() {
082                    return Layout.class.getName();
083            }
084    
085            @Override
086            public String getType() {
087                    return TYPE;
088            }
089    
090            @Override
091            public boolean isSelectable() {
092                    return _SELECTABLE;
093            }
094    
095            @Override
096            protected String getIconPath(ThemeDisplay themeDisplay) {
097                    return themeDisplay.getPathThemeImages() + "/common/pages.png";
098            }
099    
100            private static final boolean _SELECTABLE = false;
101    
102    }