001    /**
002     * Copyright (c) 2000-2013 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.language.LanguageUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.taglib.util.IncludeTag;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Roberto D??az
026     */
027    public class InputSearchTag extends IncludeTag {
028    
029            public void setAutoFocus(boolean autoFocus) {
030                    _autoFocus = autoFocus;
031            }
032    
033            public void setButtonLabel(String buttonLabel) {
034                    _buttonLabel = buttonLabel;
035            }
036    
037            public void setCssClass(String cssClass) {
038                    _cssClass = cssClass;
039            }
040    
041            public void setId(String id) {
042                    _id = id;
043            }
044    
045            public void setName(String name) {
046                    _name = name;
047            }
048    
049            public void setPlaceholder(String placeholder) {
050                    _placeholder = placeholder;
051            }
052    
053            public void setShowButton(boolean showButton) {
054                    _showButton = showButton;
055            }
056    
057            public void setTitle(String title) {
058                    _title = title;
059            }
060    
061            public void setUseNamespace(boolean useNamespace) {
062                    _useNamespace = useNamespace;
063            }
064    
065            @Override
066            protected void cleanUp() {
067                    super.cleanUp();
068    
069                    _autoFocus = false;
070                    _buttonLabel = null;
071                    _cssClass = null;
072                    _id = null;
073                    _name = null;
074                    _placeholder = null;
075                    _showButton = true;
076                    _title = null;
077                    _useNamespace = true;
078            }
079    
080            @Override
081            protected String getPage() {
082                    return _PAGE;
083            }
084    
085            @Override
086            protected void setAttributes(HttpServletRequest request) {
087                    String buttonLabel = _buttonLabel;
088    
089                    if (Validator.isNull(buttonLabel)) {
090                            buttonLabel = LanguageUtil.get(pageContext, "search");
091                    }
092    
093                    String cssClass = _cssClass;
094    
095                    if (Validator.isNull(cssClass)) {
096                            cssClass = "input-append";
097                    }
098    
099                    String name = _name;
100    
101                    if (Validator.isNull(name)) {
102                            name = DisplayTerms.KEYWORDS;
103                    }
104    
105                    String id = _id;
106    
107                    if (Validator.isNull(id)) {
108                            id = name;
109                    }
110    
111                    String placeholder = _placeholder;
112    
113                    if (Validator.isNull(placeholder)) {
114                            placeholder = buttonLabel;
115                    }
116    
117                    request.setAttribute(
118                            "liferay-ui:input-search:autoFocus", String.valueOf(_autoFocus));
119                    request.setAttribute(
120                            "liferay-ui:input-search:buttonLabel", buttonLabel);
121                    request.setAttribute("liferay-ui:input-search:cssClass", cssClass);
122                    request.setAttribute("liferay-ui:input-search:id", id);
123                    request.setAttribute("liferay-ui:input-search:name", name);
124                    request.setAttribute(
125                            "liferay-ui:input-search:placeholder", placeholder);
126                    request.setAttribute("liferay-ui:input-search:showButton", _showButton);
127                    request.setAttribute("liferay-ui:input-search:title", _title);
128                    request.setAttribute(
129                            "liferay-ui:input-search:useNamespace", _useNamespace);
130            }
131    
132            private static final String _PAGE = "/html/taglib/ui/input_search/page.jsp";
133    
134            private boolean _autoFocus;
135            private String _buttonLabel;
136            private String _cssClass;
137            private String _id;
138            private String _name;
139            private String _placeholder;
140            private boolean _showButton = true;
141            private String _title;
142            private boolean _useNamespace = true;
143    
144    }