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.servlet.taglib.ui.AssetAddonEntry;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.kernel.util.WebKeys;
021    import com.liferay.portal.util.PortalUtil;
022    import com.liferay.taglib.util.IncludeTag;
023    
024    import java.util.List;
025    
026    import javax.servlet.http.HttpServletRequest;
027    
028    /**
029     * @author Julio Camarero
030     */
031    public class AssetAddonEntrySelectorTag extends IncludeTag {
032    
033            public void setAssetAddonEntries(List<AssetAddonEntry> assetAddonEntries) {
034                    _assetAddonEntries = assetAddonEntries;
035            }
036    
037            public void setHiddenInput(String hiddenInput) {
038                    _hiddenInput = hiddenInput;
039            }
040    
041            public void setId(String id) {
042                    _id = id;
043            }
044    
045            public void setSelectedAssetAddonEntries(
046                    List<AssetAddonEntry> selectedAssetAddonEntries) {
047    
048                    _selectedAssetAddonEntries = selectedAssetAddonEntries;
049            }
050    
051            public void setTitle(String title) {
052                    _title = title;
053            }
054    
055            @Override
056            protected void cleanUp() {
057                    _assetAddonEntries = null;
058                    _hiddenInput = null;
059                    _id = null;
060                    _selectedAssetAddonEntries = null;
061                    _title = "select-entries";
062            }
063    
064            protected String getId() {
065                    if (Validator.isNotNull(_id)) {
066                            return _id;
067                    }
068    
069                    String id = PortalUtil.generateRandomKey(
070                            request, "taglib_ui_asset_addon_entry_selector_page");
071    
072                    return id + StringPool.UNDERLINE;
073            }
074    
075            @Override
076            protected String getPage() {
077                    return _PAGE;
078            }
079    
080            @Override
081            protected void setAttributes(HttpServletRequest request) {
082                    request.setAttribute(WebKeys.ASSET_ADDON_ENTRIES, _assetAddonEntries);
083                    request.setAttribute(
084                            "liferay-ui:asset-addon-entry-selector:hiddenInput", _hiddenInput);
085                    request.setAttribute(
086                            "liferay-ui:asset-addon-entry-selector:id", getId());
087                    request.setAttribute(
088                            "liferay-ui:asset-addon-entry-selector:selectedAssetAddonEntries",
089                            _selectedAssetAddonEntries);
090                    request.setAttribute(
091                            "liferay-ui:asset-addon-entry-selector:title", _title);
092            }
093    
094            private static final String _PAGE =
095                    "/html/taglib/ui/asset_addon_entry_selector/page.jsp";
096    
097            private List<AssetAddonEntry> _assetAddonEntries;
098            private String _hiddenInput;
099            private String _id;
100            private List<AssetAddonEntry> _selectedAssetAddonEntries;
101            private String _title = "select-entries";
102    
103    }