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.AssetCategory;
019    import com.liferay.portlet.asset.service.AssetCategoryServiceUtil;
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 AssetCategoriesAvailableTag<R> extends TagSupport {
031    
032            @Override
033            public int doStartTag() throws JspException {
034                    try {
035                            _assetCategories = AssetCategoryServiceUtil.getCategories(
036                                    _className, _classPK);
037    
038                            if (!_assetCategories.isEmpty()) {
039                                    return EVAL_BODY_INCLUDE;
040                            }
041    
042                            return SKIP_BODY;
043                    }
044                    catch (Exception e) {
045                            throw new JspException(e);
046                    }
047                    finally {
048                            if (!ServerDetector.isResin()) {
049                                    _className = null;
050                                    _classPK = 0;
051                            }
052                    }
053            }
054    
055            public List<AssetCategory> getAssetCategories() {
056                    return _assetCategories;
057            }
058    
059            public void setClassName(String className) {
060                    _className = className;
061            }
062    
063            public void setClassPK(long classPK) {
064                    _classPK = classPK;
065            }
066    
067            private List<AssetCategory> _assetCategories = new ArrayList<>();
068            private String _className;
069            private long _classPK;
070    
071    }