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