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            @Override
058            protected void cleanUp() {
059                    super.cleanUp();
060    
061                    _autoFocus = false;
062                    _buttonLabel = null;
063                    _cssClass = null;
064                    _id = null;
065                    _name = null;
066                    _placeholder = null;
067                    _showButton = true;
068            }
069    
070            @Override
071            protected String getPage() {
072                    return _PAGE;
073            }
074    
075            @Override
076            protected void setAttributes(HttpServletRequest request) {
077                    String buttonLabel = _buttonLabel;
078    
079                    if (Validator.isNull(buttonLabel)) {
080                            buttonLabel = LanguageUtil.get(pageContext, "search");
081                    }
082    
083                    String cssClass = _cssClass;
084    
085                    if (Validator.isNull(cssClass)) {
086                            cssClass = "input-append";
087                    }
088    
089                    String name = _name;
090    
091                    if (Validator.isNull(name)) {
092                            name = DisplayTerms.KEYWORDS;
093                    }
094    
095                    String id = _id;
096    
097                    if (Validator.isNull(id)) {
098                            id = name;
099                    }
100    
101                    String placeholder = _placeholder;
102    
103                    if (Validator.isNull(placeholder)) {
104                            placeholder = buttonLabel;
105                    }
106    
107                    request.setAttribute(
108                            "liferay-ui:input-search:autoFocus", String.valueOf(_autoFocus));
109                    request.setAttribute(
110                            "liferay-ui:input-search:buttonLabel", buttonLabel);
111                    request.setAttribute("liferay-ui:input-search:cssClass", cssClass);
112                    request.setAttribute("liferay-ui:input-search:id", id);
113                    request.setAttribute("liferay-ui:input-search:name", name);
114                    request.setAttribute(
115                            "liferay-ui:input-search:placeholder", placeholder);
116                    request.setAttribute("liferay-ui:input-search:showButton", _showButton);
117            }
118    
119            private static final String _PAGE = "/html/taglib/ui/input_search/page.jsp";
120    
121            private boolean _autoFocus;
122            private String _buttonLabel;
123            private String _cssClass;
124            private String _id;
125            private String _name;
126            private String _placeholder;
127            private boolean _showButton = true;
128    
129    }