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.dao.search.DisplayTerms;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.taglib.util.IncludeTag;
020    
021    import javax.servlet.http.HttpServletRequest;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class SearchToggleTag extends IncludeTag {
027    
028            public void setAutoFocus(boolean autoFocus) {
029                    _autoFocus = autoFocus;
030            }
031    
032            public void setButtonLabel(String buttonLabel) {
033                    _buttonLabel = buttonLabel;
034            }
035    
036            public void setDisplayTerms(DisplayTerms displayTerms) {
037                    _displayTerms = displayTerms;
038            }
039    
040            public void setId(String id) {
041                    _id = id;
042            }
043    
044            public void setMarkupView(String markupView) {
045                    _markupView = markupView;
046            }
047    
048            @Override
049            protected void cleanUp() {
050                    _autoFocus = false;
051                    _buttonLabel = null;
052                    _displayTerms = null;
053                    _id = null;
054                    _markupView = null;
055            }
056    
057            @Override
058            protected String getEndPage() {
059                    if (Validator.isNotNull(_markupView)) {
060                            return "/html/taglib/ui/search_toggle/" + _markupView + "/end.jsp";
061                    }
062    
063                    return "/html/taglib/ui/search_toggle/end.jsp";
064            }
065    
066            @Override
067            protected String getStartPage() {
068                    if (Validator.isNotNull(_markupView)) {
069                            return
070                                    "/html/taglib/ui/search_toggle/" + _markupView + "/start.jsp";
071                    }
072    
073                    return "/html/taglib/ui/search_toggle/start.jsp";
074            }
075    
076            @Override
077            protected void setAttributes(HttpServletRequest request) {
078                    request.setAttribute(
079                            "liferay-ui:search-toggle:autoFocus", String.valueOf(_autoFocus));
080                    request.setAttribute(
081                            "liferay-ui:search-toggle:buttonLabel", _buttonLabel);
082                    request.setAttribute(
083                            "liferay-ui:search-toggle:displayTerms", _displayTerms);
084                    request.setAttribute("liferay-ui:search-toggle:id", _id);
085            }
086    
087            private boolean _autoFocus;
088            private String _buttonLabel;
089            private DisplayTerms _displayTerms;
090            private String _id;
091            private String _markupView;
092    
093    }