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            @Override
037            public AssetRenderer<?> getAssetRenderer() {
038                    AssetRendererFactory<?> assetRendererFactory =
039                            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
040                                    getClassName());
041    
042                    try {
043                            return assetRendererFactory.getAssetRenderer(getClassPK());
044                    }
045                    catch (Exception e) {
046                            if (_log.isWarnEnabled()) {
047                                    _log.warn("Unable to get asset renderer", e);
048                            }
049                    }
050    
051                    return null;
052            }
053    
054            @Override
055            public AssetRendererFactory<?> getAssetRendererFactory() {
056                    return
057                            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
058                                    getClassName());
059            }
060    
061            @Override
062            public List<AssetCategory> getCategories() {
063                    return AssetCategoryLocalServiceUtil.getEntryCategories(getEntryId());
064            }
065    
066            @Override
067            public long[] getCategoryIds() {
068                    return ListUtil.toLongArray(
069                            getCategories(), AssetCategory.CATEGORY_ID_ACCESSOR);
070            }
071    
072            @Override
073            public String[] getTagNames() {
074                    return ListUtil.toArray(getTags(), AssetTag.NAME_ACCESSOR);
075            }
076    
077            @Override
078            public List<AssetTag> getTags() {
079                    return AssetTagLocalServiceUtil.getEntryTags(getEntryId());
080            }
081    
082            private static final Log _log = LogFactoryUtil.getLog(AssetEntryImpl.class);
083    
084    }