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.ui;
016    
017    import com.liferay.portal.kernel.servlet.taglib.BaseBodyTagSupport;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.taglib.util.IncludeTag;
022    
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.jsp.JspException;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     * @author Shuyang Zhou
029     */
030    public class PanelTag extends IncludeTag {
031    
032            @Override
033            public int doStartTag() throws JspException {
034                    HttpServletRequest request =
035                            (HttpServletRequest)pageContext.getRequest();
036    
037                    if (Validator.isNull(_id)) {
038                            _id = StringUtil.randomId();
039                    }
040    
041                    if (Validator.isNull(_parentId)) {
042                            BaseBodyTagSupport baseBodyTagSupport =
043                                    (BaseBodyTagSupport)findAncestorWithClass(
044                                            this, BaseBodyTagSupport.class);
045    
046                            if (baseBodyTagSupport instanceof PanelContainerTag) {
047                                    PanelContainerTag panelContainerTag =
048                                            (PanelContainerTag)baseBodyTagSupport;
049    
050                                    _parentId = panelContainerTag.getId();
051                            }
052                    }
053    
054                    request.setAttribute("liferay-ui:panel:helpMessage", _helpMessage);
055                    request.setAttribute("liferay-ui:panel:iconCssClass", _iconCssClass);
056                    request.setAttribute("liferay-ui:panel:id", _id);
057                    request.setAttribute("liferay-ui:panel:parentId", _parentId);
058                    request.setAttribute("liferay-ui:panel:title", _title);
059                    request.setAttribute(
060                            "liferay-ui:panel:collapsible", String.valueOf(_collapsible));
061                    request.setAttribute("liferay-ui:panel:defaultState", _defaultState);
062                    request.setAttribute(
063                            "liferay-ui:panel:persistState", String.valueOf(_persistState));
064                    request.setAttribute("liferay-ui:panel:extended", _extended);
065                    request.setAttribute("liferay-ui:panel:cssClass", _cssClass);
066                    request.setAttribute("liferay-ui:panel:state", _state);
067    
068                    super.doStartTag();
069    
070                    return EVAL_BODY_INCLUDE;
071            }
072    
073            public void setCollapsible(boolean collapsible) {
074                    _collapsible = collapsible;
075            }
076    
077            public void setCssClass(String cssClass) {
078                    _cssClass = cssClass;
079            }
080    
081            public void setDefaultState(String defaultState) {
082                    _defaultState = defaultState;
083            }
084    
085            public void setEndPage(String endPage) {
086                    _endPage = endPage;
087            }
088    
089            public void setExtended(Boolean extended) {
090                    _extended = extended;
091            }
092    
093            public void setHelpMessage(String helpMessage) {
094                    _helpMessage = helpMessage;
095            }
096    
097            public void setIconCssClass(String iconCssClass) {
098                    _iconCssClass = iconCssClass;
099            }
100    
101            public void setId(String id) {
102                    _id = id;
103            }
104    
105            public void setParentId(String parentId) {
106                    _parentId = parentId;
107            }
108    
109            public void setPersistState(boolean persistState) {
110                    _persistState = persistState;
111            }
112    
113            public void setStartPage(String startPage) {
114                    _startPage = startPage;
115            }
116    
117            public void setState(String state) {
118                    _state = state;
119            }
120    
121            public void setTitle(String title) {
122                    _title = title;
123            }
124    
125            @Override
126            protected void cleanUp() {
127                    _collapsible = true;
128                    _cssClass = null;
129                    _defaultState = "open";
130                    _endPage = null;
131                    _extended = null;
132                    _helpMessage = null;
133                    _iconCssClass = null;
134                    _id = null;
135                    _parentId = StringPool.BLANK;
136                    _persistState = true;
137                    _startPage = null;
138                    _state = null;
139                    _title = null;
140            }
141    
142            @Override
143            protected String getEndPage() {
144                    if (Validator.isNull(_endPage)) {
145                            return _END_PAGE;
146                    }
147                    else {
148                            return _endPage;
149                    }
150            }
151    
152            @Override
153            protected String getStartPage() {
154                    if (Validator.isNull(_startPage)) {
155                            return _START_PAGE;
156                    }
157                    else {
158                            return _startPage;
159                    }
160            }
161    
162            private static final String _END_PAGE = "/html/taglib/ui/panel/end.jsp";
163    
164            private static final String _START_PAGE = "/html/taglib/ui/panel/start.jsp";
165    
166            private boolean _collapsible = true;
167            private String _cssClass;
168            private String _defaultState = "open";
169            private String _endPage;
170            private Boolean _extended;
171            private String _helpMessage;
172            private String _iconCssClass;
173            private String _id;
174            private String _parentId = StringPool.BLANK;
175            private boolean _persistState = true;
176            private String _startPage;
177            private String _state;
178            private String _title;
179    
180    }