001    /**
002     * Copyright (c) 2000-2013 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.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    }