001    /**
002     * Copyright (c) 2000-2010 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.ServerDetector;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.taglib.util.IncludeTag;
020    
021    import javax.servlet.http.HttpServletRequest;
022    import javax.servlet.jsp.JspException;
023    
024    /**
025     * @author Raymond Augé
026     */
027    public class ToggleAreaTag extends IncludeTag {
028    
029            public int doStartTag() throws JspException {
030                    try {
031                            HttpServletRequest request =
032                                    (HttpServletRequest)pageContext.getRequest();
033    
034                            request.setAttribute("liferay-ui:toggle-area:id", _id);
035                            request.setAttribute(
036                                    "liferay-ui:toggle-area:showImage", _showImage);
037                            request.setAttribute(
038                                    "liferay-ui:toggle-area:hideImage", _hideImage);
039                            request.setAttribute(
040                                    "liferay-ui:toggle-area:showMessage", _showMessage);
041                            request.setAttribute(
042                                    "liferay-ui:toggle-area:hideMessage", _hideMessage);
043                            request.setAttribute(
044                                    "liferay-ui:toggle-area:defaultShowContent",
045                                    String.valueOf(_defaultShowContent));
046                            request.setAttribute("liferay-ui:toggle-area:stateVar", _stateVar);
047                            request.setAttribute("liferay-ui:toggle-area:align", _align);
048    
049                            include(getStartPage());
050    
051                            return EVAL_BODY_INCLUDE;
052                    }
053                    catch (Exception e) {
054                            throw new JspException(e);
055                    }
056            }
057    
058            public int doEndTag() throws JspException {
059                    try {
060                            include(getEndPage());
061    
062                            return EVAL_PAGE;
063                    }
064                    catch (Exception e) {
065                            throw new JspException(e);
066                    }
067                    finally {
068                            if (!ServerDetector.isResin()) {
069                                    _startPage = null;
070                                    _endPage = null;
071                                    _id = null;
072                                    _showMessage = null;
073                                    _hideMessage = null;
074                                    _defaultShowContent = true;
075                                    _stateVar = null;
076                                    _align = "left";
077                            }
078                    }
079            }
080    
081            protected String getStartPage() {
082                    if (Validator.isNull(_startPage)) {
083                            return _START_PAGE;
084                    }
085                    else {
086                            return _startPage;
087                    }
088            }
089    
090            public void setStartPage(String startPage) {
091                    _startPage = startPage;
092            }
093    
094            protected String getEndPage() {
095                    if (Validator.isNull(_endPage)) {
096                            return _END_PAGE;
097                    }
098                    else {
099                            return _endPage;
100                    }
101            }
102    
103            public void setEndPage(String endPage) {
104                    _endPage = endPage;
105            }
106    
107            public void setId(String id) {
108                    _id = id;
109            }
110    
111            public void setShowImage(String showImage) {
112                    _showImage = showImage;
113            }
114    
115            public void setHideImage(String hideImage) {
116                    _hideImage = hideImage;
117            }
118    
119            public void setShowMessage(String showMessage) {
120                    _showMessage = showMessage;
121            }
122    
123            public void setHideMessage(String hideMessage) {
124                    _hideMessage = hideMessage;
125            }
126    
127            public void setDefaultShowContent(boolean defaultShowContent) {
128                    _defaultShowContent = defaultShowContent;
129            }
130    
131            public void setStateVar(String stateVar) {
132                    _stateVar = stateVar;
133            }
134    
135            public void setAlign(String align) {
136                    _align = align;
137            }
138    
139            private static final String _START_PAGE =
140                    "/html/taglib/ui/toggle_area/start.jsp";
141    
142            private static final String _END_PAGE =
143                    "/html/taglib/ui/toggle_area/end.jsp";
144    
145            private String _startPage;
146            private String _endPage;
147            private String _id;
148            private String _showImage;
149            private String _hideImage;
150            private String _showMessage;
151            private String _hideMessage;
152            private boolean _defaultShowContent = true;
153            private String _stateVar;
154            private String _align = "left";
155    
156    }