001    /**
002     * Copyright (c) 2000-2011 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.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.Validator;
020    import com.liferay.taglib.util.IncludeTag;
021    import com.liferay.util.PwdGenerator;
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 = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
039                    }
040    
041                    BaseBodyTagSupport baseBodyTagSupport =
042                            (BaseBodyTagSupport)findAncestorWithClass(
043                                    this, BaseBodyTagSupport.class);
044    
045                    String parentId = StringPool.BLANK;
046    
047                    if (baseBodyTagSupport instanceof PanelContainerTag) {
048                            PanelContainerTag panelContainerTag =
049                                    (PanelContainerTag)baseBodyTagSupport;
050    
051                            parentId = panelContainerTag.getId();
052                    }
053                    else if (baseBodyTagSupport instanceof PanelFloatingContainerTag) {
054                            PanelFloatingContainerTag panelFloatingContainerTag =
055                                    (PanelFloatingContainerTag)baseBodyTagSupport;
056    
057                            parentId = panelFloatingContainerTag.getId();
058                    }
059    
060                    request.setAttribute("liferay-ui:panel:helpMessage", _helpMessage);
061                    request.setAttribute("liferay-ui:panel:id", _id);
062                    request.setAttribute("liferay-ui:panel:parentId", parentId);
063                    request.setAttribute("liferay-ui:panel:title", _title);
064                    request.setAttribute(
065                            "liferay-ui:panel:collapsible", String.valueOf(_collapsible));
066                    request.setAttribute("liferay-ui:panel:defaultState", _defaultState);
067                    request.setAttribute(
068                            "liferay-ui:panel:persistState", String.valueOf(_persistState));
069                    request.setAttribute(
070                            "liferay-ui:panel:extended", String.valueOf(_extended));
071                    request.setAttribute("liferay-ui:panel:cssClass", _cssClass);
072    
073                    super.doStartTag();
074    
075                    return EVAL_BODY_INCLUDE;
076            }
077    
078            @Override
079            protected String getStartPage() {
080                    if (Validator.isNull(_startPage)) {
081                            return _START_PAGE;
082                    }
083                    else {
084                            return _startPage;
085                    }
086            }
087    
088            public void setStartPage(String startPage) {
089                    _startPage = startPage;
090            }
091    
092            @Override
093            protected String getEndPage() {
094                    if (Validator.isNull(_endPage)) {
095                            return _END_PAGE;
096                    }
097                    else {
098                            return _endPage;
099                    }
100            }
101    
102            public void setEndPage(String endPage) {
103                    _endPage = endPage;
104            }
105    
106            public void setHelpMessage(String helpMessage) {
107                    _helpMessage = helpMessage;
108            }
109    
110            public void setId(String id) {
111                    _id = id;
112            }
113    
114            public void setTitle(String title) {
115                    _title = title;
116            }
117    
118            public void setCollapsible(boolean collapsible) {
119                    _collapsible = collapsible;
120            }
121    
122            public void setDefaultState(String defaultState) {
123                    _defaultState = defaultState;
124            }
125    
126            public void setPersistState(boolean persistState) {
127                    _persistState = persistState;
128            }
129    
130            public void setExtended(boolean extended) {
131                    _extended = extended;
132            }
133    
134            public void setCssClass(String cssClass) {
135                    _cssClass = cssClass;
136            }
137    
138            private static final String _START_PAGE = "/html/taglib/ui/panel/start.jsp";
139    
140            private static final String _END_PAGE = "/html/taglib/ui/panel/end.jsp";
141    
142            private String _startPage;
143            private String _endPage;
144            private String _helpMessage;
145            private String _id;
146            private String _title;
147            private boolean _collapsible = true;
148            private String _defaultState = "open";
149            private boolean _persistState = true;
150            private boolean _extended;
151            private String _cssClass = StringPool.BLANK;
152    
153    }