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.WebKeys;
018    import com.liferay.portal.theme.ThemeDisplay;
019    import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
020    import com.liferay.taglib.util.IncludeTag;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Eudaldo Alonso
026     */
027    public class AssetAddButtonTag extends IncludeTag {
028    
029            public long[] getAllAssetCategoryIds() {
030                    return _allAssetCategoryIds;
031            }
032    
033            public String[] getAllAssetTagNames() {
034                    return _allAssetTagNames;
035            }
036    
037            public long[] getClassNameIds() {
038                    return _classNameIds;
039            }
040    
041            public long[] getClassTypeIds() {
042                    return _classTypeIds;
043            }
044    
045            public long[] getGroupIds() {
046                    return _groupIds;
047            }
048    
049            public String getRedirect() {
050                    return _redirect;
051            }
052    
053            public boolean isAddDisplayPageParameter() {
054                    return _addDisplayPageParameter;
055            }
056    
057            public void setAddDisplayPageParameter(boolean addDisplayPageParameter) {
058                    _addDisplayPageParameter = addDisplayPageParameter;
059            }
060    
061            public void setAllAssetCategoryIds(long[] allAssetCategoryIds) {
062                    _allAssetCategoryIds = allAssetCategoryIds;
063            }
064    
065            public void setAllAssetTagNames(String[] allAssetTagNames) {
066                    _allAssetTagNames = allAssetTagNames;
067            }
068    
069            public void setClassNameIds(long[] classNameIds) {
070                    _classNameIds = classNameIds;
071            }
072    
073            public void setClassTypeIds(long[] classTypeIds) {
074                    _classTypeIds = classTypeIds;
075            }
076    
077            public void setGroupIds(long[] groupIds) {
078                    _groupIds = groupIds;
079            }
080    
081            public void setRedirect(String redirect) {
082                    _redirect = redirect;
083            }
084    
085            @Override
086            protected void cleanUp() {
087                    _addDisplayPageParameter = false;
088                    _allAssetCategoryIds = null;
089                    _allAssetTagNames = null;
090                    _classNameIds = null;
091                    _classTypeIds = null;
092                    _groupIds = null;
093                    _redirect = null;
094            }
095    
096            @Override
097            protected String getPage() {
098                    return _PAGE;
099            }
100    
101            @Override
102            protected void setAttributes(HttpServletRequest request) {
103                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
104                            WebKeys.THEME_DISPLAY);
105    
106                    request.setAttribute(
107                            "liferay-ui:asset-add-button:addDisplayPageParameter",
108                            _addDisplayPageParameter);
109                    request.setAttribute(
110                            "liferay-ui:asset-add-button:allAssetCategoryIds",
111                            _allAssetCategoryIds);
112                    request.setAttribute(
113                            "liferay-ui:asset-add-button:allAssetTagNames", _allAssetTagNames);
114    
115                    long[] classNameIds = _classNameIds;
116    
117                    if (classNameIds == null) {
118                            classNameIds = AssetRendererFactoryRegistryUtil.getClassNameIds(
119                                    themeDisplay.getCompanyId());
120                    }
121    
122                    request.setAttribute(
123                            "liferay-ui:asset-add-button:classNameIds", classNameIds);
124    
125                    request.setAttribute(
126                            "liferay-ui:asset-add-button:classTypeIds", _classTypeIds);
127    
128                    long[] groupIds = _groupIds;
129    
130                    if (groupIds == null) {
131                            groupIds = new long[] {themeDisplay.getScopeGroupId()};
132                    }
133    
134                    request.setAttribute("liferay-ui:asset-add-button:groupIds", groupIds);
135    
136                    request.setAttribute("liferay-ui:asset-add-button:redirect", _redirect);
137            }
138    
139            private static final String _PAGE =
140                    "/html/taglib/ui/asset_add_button/page.jsp";
141    
142            private boolean _addDisplayPageParameter;
143            private long[] _allAssetCategoryIds;
144            private String[] _allAssetTagNames;
145            private long[] _classNameIds;
146            private long[] _classTypeIds;
147            private long[] _groupIds;
148            private String _redirect;
149    
150    }