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.IntegerWrapper;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.util.PwdGenerator;
023    
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.jsp.JspException;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class PanelFloatingContainerTag extends BaseBodyTagSupport {
031    
032            public int doStartTag() {
033                    HttpServletRequest request =
034                            (HttpServletRequest)pageContext.getRequest();
035    
036                    if (Validator.isNull(_id)) {
037                            _id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
038                    }
039    
040                    request.setAttribute(
041                            "liferay-ui:panel-floating-container:id", _id);
042                    request.setAttribute(
043                            "liferay-ui:panel-floating-container:trigger", _trigger);
044                    request.setAttribute(
045                            "liferay-ui:panel-floating-container:accordion",
046                            String.valueOf(_accordion));
047                    request.setAttribute(
048                            "liferay-ui:panel-floating-container:persistState",
049                            String.valueOf(_persistState));
050                    request.setAttribute(
051                            "liferay-ui:panel-floating-container:paging",
052                            String.valueOf(_paging));
053                    request.setAttribute(
054                            "liferay-ui:panel-floating-container:pagingElements",
055                            _pagingElements);
056                    request.setAttribute(
057                            "liferay-ui:panel-floating-container:resultsPerPage",
058                            String.valueOf(_resultsPerPage));
059                    request.setAttribute(
060                            "liferay-ui:panel-floating-container:width",
061                            String.valueOf(_width));
062                    request.setAttribute(
063                            "liferay-ui:panel-floating-container:extended", _extended);
064                    request.setAttribute(
065                            "liferay-ui:panel-floating-container:cssClass", _cssClass);
066                    request.setAttribute(
067                            "liferay-ui:panel-container:panelCount" + _id,
068                            new IntegerWrapper());
069    
070                    return EVAL_BODY_BUFFERED;
071            }
072    
073            public int doAfterBody() {
074                    HttpServletRequest request =
075                            (HttpServletRequest)pageContext.getRequest();
076    
077                    IntegerWrapper panelCount = (IntegerWrapper)request.getAttribute(
078                            "liferay-ui:panel-container:panelCount" + _id);
079    
080                    if ((panelCount != null) && (panelCount.getValue() == 1)) {
081    
082                            bodyContent.clearBody();
083    
084                            return EVAL_BODY_AGAIN;
085                    }
086                    else {
087                            return SKIP_BODY;
088                    }
089            }
090    
091            public int doEndTag() throws JspException {
092                    try {
093                            HttpServletRequest request =
094                                    (HttpServletRequest)pageContext.getRequest();
095    
096                            IntegerWrapper panelCount = (IntegerWrapper)request.getAttribute(
097                                    "liferay-ui:panel-container:panelCount" + _id);
098    
099                            request.removeAttribute(
100                                    "liferay-ui:panel-container:panelCount" + _id);
101    
102                            if ((panelCount != null) && (panelCount.getValue() >= 1)) {
103                                    PortalIncludeUtil.include(pageContext, getStartPage());
104                            }
105    
106                            writeBodyContent(pageContext.getOut());
107    
108                            if ((panelCount != null) && (panelCount.getValue() >= 1)) {
109                                    PortalIncludeUtil.include(pageContext, getEndPage());
110                            }
111    
112                            request.removeAttribute("liferay-ui:panel-floating-container:id");
113                            request.removeAttribute(
114                                    "liferay-ui:panel-floating-container:trigger");
115                            request.removeAttribute(
116                                    "liferay-ui:panel-floating-container:accordion");
117                            request.removeAttribute(
118                                    "liferay-ui:panel-floating-container:persistState");
119                            request.removeAttribute(
120                                    "liferay-ui:panel-floating-container:paging");
121                            request.removeAttribute(
122                                    "liferay-ui:panel-floating-container:pagingElements");
123                            request.removeAttribute(
124                                    "liferay-ui:panel-floating-container:resultsPerPage");
125                            request.removeAttribute(
126                                    "liferay-ui:panel-floating-container:width");
127                            request.removeAttribute(
128                                    "liferay-ui:panel-floating-container:extended");
129                            request.removeAttribute(
130                                    "liferay-ui:panel-floating-container:cssClass");
131    
132                            return EVAL_PAGE;
133                    }
134                    catch (Exception e) {
135                            throw new JspException(e);
136                    }
137            }
138    
139            public String getId() {
140                    return _id;
141            }
142    
143            protected String getStartPage() {
144                    if (Validator.isNull(_startPage)) {
145                            return _START_PAGE;
146                    }
147                    else {
148                            return _startPage;
149                    }
150            }
151    
152            public void setStartPage(String startPage) {
153                    _startPage = startPage;
154            }
155    
156            protected String getEndPage() {
157                    if (Validator.isNull(_endPage)) {
158                            return _END_PAGE;
159                    }
160                    else {
161                            return _endPage;
162                    }
163            }
164    
165            public void setEndPage(String endPage) {
166                    _endPage = endPage;
167            }
168    
169            public void setId(String id) {
170                    _id = id;
171            }
172    
173            public void setTrigger(String trigger) {
174                    _trigger = trigger;
175            }
176    
177            public void setAccordion(boolean accordion) {
178                    _accordion = accordion;
179            }
180    
181            public void setPersistState(boolean persistState) {
182                    _persistState = persistState;
183            }
184    
185            public void setPaging(boolean paging) {
186                    _paging = paging;
187            }
188    
189            public void setPagingElements(String pagingElements) {
190                    _pagingElements = pagingElements;
191            }
192    
193            public void setResultsPerPage(int resultsPerPage) {
194                    _resultsPerPage = resultsPerPage;
195            }
196    
197            public void setWidth(int width) {
198                    _width = width;
199            }
200    
201            public void setExtended(Boolean extended) {
202                    _extended = extended;
203            }
204    
205            public void setCssClass(String cssClass) {
206                    _cssClass = cssClass;
207            }
208    
209            private static final String _START_PAGE =
210                    "/html/taglib/ui/panel_floating_container/start.jsp";
211    
212            private static final String _END_PAGE =
213                    "/html/taglib/ui/panel_floating_container/end.jsp";
214    
215            private String _startPage;
216            private String _endPage;
217            private String _id;
218            private String _trigger;
219            private boolean _accordion;
220            private boolean _persistState;
221            private boolean _paging;
222            private String _pagingElements = "ul";
223            private int _resultsPerPage = 1;
224            private int _width = 300;
225            private Boolean _extended;
226            private String _cssClass = StringPool.BLANK;
227    
228    }