001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.asset.model.impl;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.util.ListUtil;
021    import com.liferay.portal.kernel.util.StringUtil;
022    import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
023    import com.liferay.portlet.asset.model.AssetCategory;
024    import com.liferay.portlet.asset.model.AssetRenderer;
025    import com.liferay.portlet.asset.model.AssetRendererFactory;
026    import com.liferay.portlet.asset.model.AssetTag;
027    import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
028    import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
029    
030    import java.util.List;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     * @author Juan Fernández
035     */
036    public class AssetEntryImpl extends AssetEntryBaseImpl {
037    
038            public AssetEntryImpl() {
039            }
040    
041            @Override
042            public AssetRenderer getAssetRenderer() {
043                    AssetRendererFactory assetRendererFactory =
044                            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
045                                    getClassName());
046    
047                    try {
048                            return assetRendererFactory.getAssetRenderer(getClassPK());
049                    }
050                    catch (Exception e) {
051                            if (_log.isWarnEnabled()) {
052                                    _log.warn("Unable to get asset renderer", e);
053                            }
054                    }
055    
056                    return null;
057            }
058    
059            @Override
060            public AssetRendererFactory getAssetRendererFactory() {
061                    return
062                            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
063                                    getClassName());
064            }
065    
066            @Override
067            public List<AssetCategory> getCategories() throws SystemException {
068                    return AssetCategoryLocalServiceUtil.getEntryCategories(getEntryId());
069            }
070    
071            @Override
072            public long[] getCategoryIds() throws SystemException {
073                    return StringUtil.split(
074                            ListUtil.toString(
075                                    getCategories(), AssetCategory.CATEGORY_ID_ACCESSOR), 0L);
076            }
077    
078            @Override
079            public String[] getTagNames() throws SystemException {
080                    return StringUtil.split(
081                            ListUtil.toString(getTags(), AssetTag.NAME_ACCESSOR));
082            }
083    
084            @Override
085            public List<AssetTag> getTags() throws SystemException {
086                    return AssetTagLocalServiceUtil.getEntryTags(getEntryId());
087            }
088    
089            private static Log _log = LogFactoryUtil.getLog(AssetEntryImpl.class);
090    
091    }