001    /**
002     * Copyright (c) 2000-2010 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.util.Validator;
018    import com.liferay.taglib.util.IncludeTag;
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    
026    /**
027     * @author Julio Camarero
028     * @author Brian Wing Shun Chan
029     */
030    public class PanelTag extends IncludeTag {
031    
032            public void addToolTag(ToolTag toolTag) {
033                    if (_toolTags == null) {
034                            _toolTags = new ArrayList<ToolTag>();
035                    }
036    
037                    _toolTags.add(toolTag);
038            }
039    
040            public List<ToolTag> getToolTags() {
041                    return _toolTags;
042            }
043    
044            public void setCollapsible(boolean collapsible) {
045                    _collapsible = collapsible;
046            }
047    
048            public void setId(String id) {
049                    _id = id;
050            }
051    
052            public void setLabel(String label) {
053                    _label = label;
054            }
055    
056            protected void cleanUp() {
057                    _collapsible = false;
058                    _id = null;
059                    _label = null;
060    
061                    if (_toolTags != null) {
062                            for (ToolTag toolTag : _toolTags) {
063                                    toolTag.cleanUp();
064                            }
065    
066                            _toolTags = null;
067                    }
068            }
069    
070            protected String getEndPage() {
071                    return _END_PAGE;
072            }
073    
074            protected String getStartPage() {
075                    return _START_PAGE;
076            }
077    
078            protected boolean isCleanUpSetAttributes() {
079                    return _CLEAN_UP_SET_ATTRIBUTES;
080            }
081    
082            protected void setAttributes(HttpServletRequest request) {
083                    String id = _id;
084    
085                    if (Validator.isNull(id)) {
086                            id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
087                    }
088    
089                    request.setAttribute(
090                            "aui:panel:collapsible", String.valueOf(_collapsible));
091                    request.setAttribute("aui:panel:id", id);
092                    request.setAttribute("aui:panel:label", _label);
093                    request.setAttribute("aui:panel:toolTags", _toolTags);
094            }
095    
096            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
097    
098            private static final String _END_PAGE = "/html/taglib/aui/panel/end.jsp";
099    
100            private static final String _START_PAGE =
101                    "/html/taglib/aui/panel/start.jsp";
102    
103            private boolean _collapsible;
104            private String _id;
105            private String _label;
106            private List<ToolTag> _toolTags;
107    
108    }