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.taglib.ui;
016    
017    import com.liferay.portal.kernel.util.ServerDetector;
018    import com.liferay.portlet.asset.model.AssetTag;
019    import com.liferay.portlet.asset.service.AssetTagServiceUtil;
020    import com.liferay.taglib.TagSupport;
021    
022    import java.util.ArrayList;
023    import java.util.List;
024    
025    import javax.servlet.jsp.JspException;
026    
027    /**
028     * @author Sergio Gonz??lez
029     */
030    public class AssetTagsAvailableTag<R> extends TagSupport {
031    
032            @Override
033            public int doStartTag() throws JspException {
034                    try {
035                            _assetTags = AssetTagServiceUtil.getTags(_className, _classPK);
036    
037                            if (!_assetTags.isEmpty()) {
038                                    return EVAL_BODY_INCLUDE;
039                            }
040    
041                            return SKIP_BODY;
042                    }
043                    catch (Exception e) {
044                            throw new JspException(e);
045                    }
046                    finally {
047                            if (!ServerDetector.isResin()) {
048                                    _className = null;
049                                    _classPK = 0;
050                            }
051                    }
052            }
053    
054            public List<AssetTag> getAssetTags() {
055                    return _assetTags;
056            }
057    
058            public void setClassName(String className) {
059                    _className = className;
060            }
061    
062            public void setClassPK(long classPK) {
063                    _classPK = classPK;
064            }
065    
066            private List<AssetTag> _assetTags = new ArrayList<>();
067            private String _className;
068            private long _classPK;
069    
070    }