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 boolean isUseDialog() {
058                    return _useDialog;
059            }
060    
061            public void setAddDisplayPageParameter(boolean addDisplayPageParameter) {
062                    _addDisplayPageParameter = addDisplayPageParameter;
063            }
064    
065            public void setAllAssetCategoryIds(long[] allAssetCategoryIds) {
066                    _allAssetCategoryIds = allAssetCategoryIds;
067            }
068    
069            public void setAllAssetTagNames(String[] allAssetTagNames) {
070                    _allAssetTagNames = allAssetTagNames;
071            }
072    
073            public void setClassNameIds(long[] classNameIds) {
074                    _classNameIds = classNameIds;
075            }
076    
077            public void setClassTypeIds(long[] classTypeIds) {
078                    _classTypeIds = classTypeIds;
079            }
080    
081            public void setGroupIds(long[] groupIds) {
082                    _groupIds = groupIds;
083            }
084    
085            public void setRedirect(String redirect) {
086                    _redirect = redirect;
087            }
088    
089            public void setUseDialog(boolean useDialog) {
090                    _useDialog = useDialog;
091            }
092    
093            @Override
094            protected void cleanUp() {
095                    _addDisplayPageParameter = false;
096                    _allAssetCategoryIds = null;
097                    _allAssetTagNames = null;
098                    _classNameIds = null;
099                    _classTypeIds = null;
100                    _groupIds = null;
101                    _redirect = null;
102                    _useDialog = true;
103            }
104    
105            @Override
106            protected String getPage() {
107                    return _PAGE;
108            }
109    
110            @Override
111            protected void setAttributes(HttpServletRequest request) {
112                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
113                            WebKeys.THEME_DISPLAY);
114    
115                    request.setAttribute(
116                            "liferay-ui:asset-add-button:addDisplayPageParameter",
117                            _addDisplayPageParameter);
118                    request.setAttribute(
119                            "liferay-ui:asset-add-button:allAssetCategoryIds",
120                            _allAssetCategoryIds);
121                    request.setAttribute(
122                            "liferay-ui:asset-add-button:allAssetTagNames", _allAssetTagNames);
123    
124                    long[] classNameIds = _classNameIds;
125    
126                    if (classNameIds == null) {
127                            classNameIds = AssetRendererFactoryRegistryUtil.getClassNameIds(
128                                    themeDisplay.getCompanyId());
129                    }
130    
131                    request.setAttribute(
132                            "liferay-ui:asset-add-button:classNameIds", classNameIds);
133    
134                    request.setAttribute(
135                            "liferay-ui:asset-add-button:classTypeIds", _classTypeIds);
136    
137                    long[] groupIds = _groupIds;
138    
139                    if (groupIds == null) {
140                            groupIds = new long[] {themeDisplay.getScopeGroupId()};
141                    }
142    
143                    request.setAttribute("liferay-ui:asset-add-button:groupIds", groupIds);
144    
145                    request.setAttribute("liferay-ui:asset-add-button:redirect", _redirect);
146                    request.setAttribute(
147                            "liferay-ui:asset-add-button:useDialog", _useDialog);
148            }
149    
150            private static final String _PAGE =
151                    "/html/taglib/ui/asset_add_button/page.jsp";
152    
153            private boolean _addDisplayPageParameter;
154            private long[] _allAssetCategoryIds;
155            private String[] _allAssetTagNames;
156            private long[] _classNameIds;
157            private long[] _classTypeIds;
158            private long[] _groupIds;
159            private String _redirect;
160            private boolean _useDialog;
161    
162    }