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.aui;
016    
017    import com.liferay.portal.kernel.servlet.taglib.aui.ToolTag;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.util.PortalUtil;
021    import com.liferay.taglib.aui.base.BasePanelTag;
022    
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    import javax.servlet.http.HttpServletRequest;
027    
028    /**
029     * @author Julio Camarero
030     * @author Brian Wing Shun Chan
031     */
032    public class PanelTag extends BasePanelTag {
033    
034            public void addToolTag(ToolTag toolTag) {
035                    if (_toolTags == null) {
036                            _toolTags = new ArrayList<>();
037                    }
038    
039                    _toolTags.add(toolTag);
040            }
041    
042            public List<ToolTag> getToolTags() {
043                    return _toolTags;
044            }
045    
046            @Override
047            protected void cleanUp() {
048                    super.cleanUp();
049    
050                    if (_toolTags != null) {
051                            for (ToolTag toolTag : _toolTags) {
052                                    toolTag.cleanUp();
053                            }
054    
055                            _toolTags = null;
056                    }
057            }
058    
059            @Override
060            protected boolean isCleanUpSetAttributes() {
061                    return _CLEAN_UP_SET_ATTRIBUTES;
062            }
063    
064            @Override
065            protected void setAttributes(HttpServletRequest request) {
066                    super.setAttributes(request);
067    
068                    String id = getId();
069    
070                    if (Validator.isNull(id)) {
071                            id = PortalUtil.getUniqueElementId(
072                                    request, StringPool.BLANK, AUIUtil.normalizeId("panel"));
073                    }
074    
075                    setNamespacedAttribute(request, "id", id);
076                    setNamespacedAttribute(request, "toolTags", _toolTags);
077            }
078    
079            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
080    
081            private List<ToolTag> _toolTags;
082    
083    }