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