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.ui;
016    
017    import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
018    import com.liferay.portal.kernel.servlet.taglib.BaseBodyTagSupport;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.util.Validator;
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     */
029    public class PanelTag extends BaseBodyTagSupport {
030    
031            public int doStartTag() {
032                    HttpServletRequest request =
033                            (HttpServletRequest)pageContext.getRequest();
034    
035                    if (Validator.isNull(_id)) {
036                            _id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
037                    }
038    
039                    BaseBodyTagSupport parentTag =
040                            (BaseBodyTagSupport)findAncestorWithClass(
041                                    this, BaseBodyTagSupport.class);
042    
043                    String parentId = StringPool.BLANK;
044    
045                    try {
046                            PanelFloatingContainerTag panelFloatingContainerTag     =
047                                    (PanelFloatingContainerTag)parentTag;
048    
049                            parentId = panelFloatingContainerTag.getId();
050                    }
051                    catch (ClassCastException cce){
052                            try {
053                                    PanelContainerTag panelContainerTag     =
054                                            (PanelContainerTag)parentTag;
055    
056                                    parentId = panelContainerTag.getId();
057                            }
058                            catch (ClassCastException ccee) {
059                            }
060                    }
061    
062                    request.setAttribute("liferay-ui:panel:id", _id);
063                    request.setAttribute("liferay-ui:panel:parentId", parentId);
064                    request.setAttribute("liferay-ui:panel:title", _title);
065                    request.setAttribute(
066                            "liferay-ui:panel:collapsible", String.valueOf(_collapsible));
067                    request.setAttribute("liferay-ui:panel:defaultState", _defaultState);
068                    request.setAttribute(
069                            "liferay-ui:panel:persistState", String.valueOf(_persistState));
070                    request.setAttribute(
071                            "liferay-ui:panel:extended", String.valueOf(_extended));
072                    request.setAttribute("liferay-ui:panel:cssClass", _cssClass);
073    
074                    return EVAL_BODY_BUFFERED;
075            }
076    
077            public int doEndTag() throws JspException {
078                    try {
079                            PortalIncludeUtil.include(pageContext, getStartPage());
080    
081                            writeBodyContent(pageContext.getOut());
082    
083                            PortalIncludeUtil.include(pageContext, getEndPage());
084    
085                            return EVAL_PAGE;
086                    }
087                    catch (Exception e) {
088                            throw new JspException(e);
089                    }
090            }
091    
092            protected String getStartPage() {
093                    if (Validator.isNull(_startPage)) {
094                            return _START_PAGE;
095                    }
096                    else {
097                            return _startPage;
098                    }
099            }
100    
101            public void setStartPage(String startPage) {
102                    _startPage = startPage;
103            }
104    
105            protected String getEndPage() {
106                    if (Validator.isNull(_endPage)) {
107                            return _END_PAGE;
108                    }
109                    else {
110                            return _endPage;
111                    }
112            }
113    
114            public void setEndPage(String endPage) {
115                    _endPage = endPage;
116            }
117    
118            public void setId(String id) {
119                    _id = id;
120            }
121    
122            public void setTitle(String title) {
123                    _title = title;
124            }
125    
126            public void setCollapsible(boolean collapsible) {
127                    _collapsible = collapsible;
128            }
129    
130            public void setDefaultState(String defaultState) {
131                    _defaultState = defaultState;
132            }
133    
134            public void setPersistState(boolean persistState) {
135                    _persistState = persistState;
136            }
137    
138            public void setExtended(boolean extended) {
139                    _extended = extended;
140            }
141    
142            public void setCssClass(String cssClass) {
143                    _cssClass = cssClass;
144            }
145    
146            private static final String _START_PAGE = "/html/taglib/ui/panel/start.jsp";
147    
148            private static final String _END_PAGE = "/html/taglib/ui/panel/end.jsp";
149    
150            private String _startPage;
151            private String _endPage;
152            private String _id;
153            private String _title;
154            private boolean _collapsible = true;
155            private String _defaultState = "open";
156            private boolean _persistState = true;
157            private boolean _extended;
158            private String _cssClass = StringPool.BLANK;
159    
160    }