001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.StringUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.taglib.aui.base.BasePanelTag;
021    
022    import java.util.ArrayList;
023    import java.util.List;
024    
025    import javax.servlet.http.HttpServletRequest;
026    
027    /**
028     * @author Julio Camarero
029     * @author Brian Wing Shun Chan
030     */
031    public class PanelTag extends BasePanelTag {
032    
033            public void addToolTag(ToolTag toolTag) {
034                    if (_toolTags == null) {
035                            _toolTags = new ArrayList<ToolTag>();
036                    }
037    
038                    _toolTags.add(toolTag);
039            }
040    
041            public List<ToolTag> getToolTags() {
042                    return _toolTags;
043            }
044    
045            @Override
046            protected void cleanUp() {
047                    super.cleanUp();
048    
049                    if (_toolTags != null) {
050                            for (ToolTag toolTag : _toolTags) {
051                                    toolTag.cleanUp();
052                            }
053    
054                            _toolTags = null;
055                    }
056            }
057    
058            @Override
059            protected boolean isCleanUpSetAttributes() {
060                    return _CLEAN_UP_SET_ATTRIBUTES;
061            }
062    
063            @Override
064            protected void setAttributes(HttpServletRequest request) {
065                    super.setAttributes(request);
066    
067                    String id = getId();
068    
069                    if (Validator.isNull(id)) {
070                            id = StringUtil.randomId();
071                    }
072    
073                    setNamespacedAttribute(request, "id", id);
074                    setNamespacedAttribute(request, "toolTags", _toolTags);
075            }
076    
077            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
078    
079            private List<ToolTag> _toolTags;
080    
081    }