001    /**
002     * Copyright (c) 2000-2012 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.util.Validator;
018    import com.liferay.taglib.aui.base.BasePanelTag;
019    import com.liferay.util.PwdGenerator;
020    
021    import java.util.ArrayList;
022    import java.util.List;
023    
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.jsp.JspException;
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            @Override
042            public int doEndTag() throws JspException {
043                    setCalledSetAttributes(false);
044    
045                    return super.doEndTag();
046            }
047    
048            public List<ToolTag> getToolTags() {
049                    return _toolTags;
050            }
051    
052            @Override
053            protected void cleanUp() {
054                    super.cleanUp();
055    
056                    if (_toolTags != null) {
057                            for (ToolTag toolTag : _toolTags) {
058                                    toolTag.cleanUp();
059                            }
060    
061                            _toolTags = null;
062                    }
063            }
064    
065            @Override
066            protected boolean isCleanUpSetAttributes() {
067                    return _CLEAN_UP_SET_ATTRIBUTES;
068            }
069    
070            @Override
071            protected void setAttributes(HttpServletRequest request) {
072                    super.setAttributes(request);
073    
074                    String id = getId();
075    
076                    if (Validator.isNull(id)) {
077                            id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
078                    }
079    
080                    setNamespacedAttribute(request, "id", id);
081                    setNamespacedAttribute(request, "toolTags", _toolTags);
082            }
083    
084            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
085    
086            private List<ToolTag> _toolTags;
087    
088    }