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.portlet.asset.model.impl;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.ListUtil;
020    import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
021    import com.liferay.portlet.asset.model.AssetCategory;
022    import com.liferay.portlet.asset.model.AssetRenderer;
023    import com.liferay.portlet.asset.model.AssetRendererFactory;
024    import com.liferay.portlet.asset.model.AssetTag;
025    import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
026    import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
027    
028    import java.util.List;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Juan Fern??ndez
033     */
034    public class AssetEntryImpl extends AssetEntryBaseImpl {
035    
036            public AssetEntryImpl() {
037            }
038    
039            @Override
040            public AssetRenderer getAssetRenderer() {
041                    AssetRendererFactory assetRendererFactory =
042                            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
043                                    getClassName());
044    
045                    try {
046                            return assetRendererFactory.getAssetRenderer(getClassPK());
047                    }
048                    catch (Exception e) {
049                            if (_log.isWarnEnabled()) {
050                                    _log.warn("Unable to get asset renderer", e);
051                            }
052                    }
053    
054                    return null;
055            }
056    
057            @Override
058            public AssetRendererFactory getAssetRendererFactory() {
059                    return
060                            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
061                                    getClassName());
062            }
063    
064            @Override
065            public List<AssetCategory> getCategories() {
066                    return AssetCategoryLocalServiceUtil.getEntryCategories(getEntryId());
067            }
068    
069            @Override
070            public long[] getCategoryIds() {
071                    return ListUtil.toLongArray(
072                            getCategories(), AssetCategory.CATEGORY_ID_ACCESSOR);
073            }
074    
075            @Override
076            public String[] getTagNames() {
077                    return ListUtil.toArray(getTags(), AssetTag.NAME_ACCESSOR);
078            }
079    
080            @Override
081            public List<AssetTag> getTags() {
082                    return AssetTagLocalServiceUtil.getEntryTags(getEntryId());
083            }
084    
085            private static final Log _log = LogFactoryUtil.getLog(AssetEntryImpl.class);
086    
087    }