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.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    }