001    /**
002     * Copyright (c) 2000-present 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.util.StringPool;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.taglib.BaseBodyTagSupport;
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                                    _accordion = panelContainerTag.isAccordion();
051                                    _parentId = panelContainerTag.getId();
052                            }
053                    }
054    
055                    request.setAttribute(
056                            "liferay-ui:panel:accordion", String.valueOf(_accordion));
057                    request.setAttribute("liferay-ui:panel:helpMessage", _helpMessage);
058                    request.setAttribute("liferay-ui:panel:iconCssClass", _iconCssClass);
059                    request.setAttribute("liferay-ui:panel:id", _id);
060                    request.setAttribute("liferay-ui:panel:parentId", _parentId);
061                    request.setAttribute("liferay-ui:panel:title", _title);
062                    request.setAttribute(
063                            "liferay-ui:panel:collapsible", String.valueOf(_collapsible));
064                    request.setAttribute("liferay-ui:panel:defaultState", _defaultState);
065                    request.setAttribute(
066                            "liferay-ui:panel:persistState", String.valueOf(_persistState));
067                    request.setAttribute("liferay-ui:panel:extended", _extended);
068                    request.setAttribute("liferay-ui:panel:cssClass", _cssClass);
069                    request.setAttribute("liferay-ui:panel:state", _state);
070    
071                    super.doStartTag();
072    
073                    return EVAL_BODY_INCLUDE;
074            }
075    
076            public void setCollapsible(boolean collapsible) {
077                    _collapsible = collapsible;
078            }
079    
080            public void setCssClass(String cssClass) {
081                    _cssClass = cssClass;
082            }
083    
084            public void setDefaultState(String defaultState) {
085                    _defaultState = defaultState;
086            }
087    
088            public void setEndPage(String endPage) {
089                    _endPage = endPage;
090            }
091    
092            public void setExtended(Boolean extended) {
093                    _extended = extended;
094            }
095    
096            public void setHelpMessage(String helpMessage) {
097                    _helpMessage = helpMessage;
098            }
099    
100            public void setIconCssClass(String iconCssClass) {
101                    _iconCssClass = iconCssClass;
102            }
103    
104            public void setId(String id) {
105                    _id = id;
106            }
107    
108            public void setMarkupView(String markupView) {
109                    _markupView = markupView;
110            }
111    
112            public void setParentId(String parentId) {
113                    _parentId = parentId;
114            }
115    
116            public void setPersistState(boolean persistState) {
117                    _persistState = persistState;
118            }
119    
120            public void setStartPage(String startPage) {
121                    _startPage = startPage;
122            }
123    
124            public void setState(String state) {
125                    _state = state;
126            }
127    
128            public void setTitle(String title) {
129                    _title = title;
130            }
131    
132            @Override
133            protected void cleanUp() {
134                    _accordion = false;
135                    _collapsible = true;
136                    _cssClass = null;
137                    _defaultState = "open";
138                    _endPage = null;
139                    _extended = null;
140                    _helpMessage = null;
141                    _iconCssClass = null;
142                    _id = null;
143                    _markupView = null;
144                    _parentId = StringPool.BLANK;
145                    _persistState = true;
146                    _startPage = null;
147                    _state = null;
148                    _title = null;
149            }
150    
151            @Override
152            protected String getEndPage() {
153                    if (Validator.isNull(_endPage)) {
154                            if (Validator.isNotNull(_markupView)) {
155                                    return "/html/taglib/ui/panel/" + _markupView + "/end.jsp";
156                            }
157    
158                            return "/html/taglib/ui/panel/end.jsp";
159                    }
160                    else {
161                            return _endPage;
162                    }
163            }
164    
165            @Override
166            protected String getStartPage() {
167                    if (Validator.isNull(_startPage)) {
168                            if (Validator.isNotNull(_markupView)) {
169                                    return "/html/taglib/ui/panel/" + _markupView + "/start.jsp";
170                            }
171    
172                            return "/html/taglib/ui/panel/start.jsp";
173                    }
174                    else {
175                            return _startPage;
176                    }
177            }
178    
179            private boolean _accordion;
180            private boolean _collapsible = true;
181            private String _cssClass;
182            private String _defaultState = "open";
183            private String _endPage;
184            private Boolean _extended;
185            private String _helpMessage;
186            private String _iconCssClass;
187            private String _id;
188            private String _markupView;
189            private String _parentId = StringPool.BLANK;
190            private boolean _persistState = true;
191            private String _startPage;
192            private String _state;
193            private String _title;
194    
195    }