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.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.portal.model.ModelHintsConstants;
020    import com.liferay.taglib.util.IncludeTag;
021    
022    import java.util.Locale;
023    
024    import javax.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Julio Camarero
028     */
029    public class InputLocalizedTag extends IncludeTag {
030    
031            public Locale[] getAvailableLocales() {
032                    return _availableLocales;
033            }
034    
035            public void setAutoFocus(boolean autoFocus) {
036                    _autoFocus = autoFocus;
037            }
038    
039            public void setAutoSize(boolean autoSize) {
040                    _autoSize = autoSize;
041            }
042    
043            public void setAvailableLocales(Locale[] availableLocales) {
044                    _availableLocales = availableLocales;
045            }
046    
047            public void setCssClass(String cssClass) {
048                    _cssClass = cssClass;
049            }
050    
051            public void setDefaultLanguageId(String defaultLanguageId) {
052                    _defaultLanguageId = defaultLanguageId;
053            }
054    
055            public void setDisabled(boolean disabled) {
056                    _disabled = disabled;
057            }
058    
059            public void setDisplayWidth(String displayWidth) {
060                    _displayWidth = displayWidth;
061            }
062    
063            public void setFormName(String formName) {
064                    _formName = formName;
065            }
066    
067            public void setId(String id) {
068                    _id = id;
069            }
070    
071            public void setIgnoreRequestValue(boolean ignoreRequestValue) {
072                    _ignoreRequestValue = ignoreRequestValue;
073            }
074    
075            public void setLanguageId(String languageId) {
076                    _languageId = languageId;
077            }
078    
079            public void setMaxLength(String maxLength) {
080                    _maxLength = maxLength;
081            }
082    
083            public void setName(String name) {
084                    _name = name;
085            }
086    
087            public void setType(String type) {
088                    _type = type;
089            }
090    
091            public void setXml(String xml) {
092                    _xml = xml;
093            }
094    
095            @Override
096            protected void cleanUp() {
097                    _autoFocus = false;
098                    _autoSize = false;
099                    _cssClass = null;
100                    _disabled = false;
101                    _displayWidth = ModelHintsConstants.TEXT_DISPLAY_WIDTH;
102                    _formName = null;
103                    _id = null;
104                    _ignoreRequestValue = false;
105                    _languageId = null;
106                    _maxLength = null;
107                    _name = null;
108                    _type = "input";
109                    _xml = null;
110            }
111    
112            @Override
113            protected String getPage() {
114                    return _PAGE;
115            }
116    
117            @Override
118            protected void setAttributes(HttpServletRequest request) {
119                    Locale[] availableLocales = _availableLocales;
120    
121                    if (availableLocales == null) {
122                            availableLocales = LanguageUtil.getAvailableLocales();
123                    }
124    
125                    String formName = _formName;
126    
127                    if (Validator.isNull(formName)) {
128                            formName = "fm";
129                    }
130    
131                    String id = _id;
132    
133                    if (Validator.isNull(id)) {
134                            id = _name;
135                    }
136    
137                    request.setAttribute(
138                            "liferay-ui:input-localized:autoFocus", String.valueOf(_autoFocus));
139                    request.setAttribute(
140                            "liferay-ui:input-localized:autoSize", String.valueOf(_autoSize));
141                    request.setAttribute(
142                            "liferay-ui:input-localized:availableLocales", availableLocales);
143                    request.setAttribute("liferay-ui:input-localized:cssClass", _cssClass);
144                    request.setAttribute(
145                            "liferay-ui:input-localized:defaultLanguageId", _defaultLanguageId);
146                    request.setAttribute(
147                            "liferay-ui:input-localized:displayWidth", _displayWidth);
148                    request.setAttribute(
149                            "liferay-ui:input-localized:disabled", String.valueOf(_disabled));
150                    request.setAttribute(
151                            "liferay-ui:input-localized:dynamicAttributes",
152                            getDynamicAttributes());
153                    request.setAttribute("liferay-ui:input-localized:formName", formName);
154                    request.setAttribute("liferay-ui:input-localized:id", id);
155                    request.setAttribute(
156                            "liferay-ui:input-localized:ignoreRequestValue",
157                            String.valueOf(_ignoreRequestValue));
158                    request.setAttribute(
159                            "liferay-ui:input-localized:languageId", _languageId);
160                    request.setAttribute(
161                            "liferay-ui:input-localized:maxLength", _maxLength);
162                    request.setAttribute("liferay-ui:input-localized:name", _name);
163                    request.setAttribute("liferay-ui:input-localized:type", _type);
164                    request.setAttribute("liferay-ui:input-localized:xml", _xml);
165            }
166    
167            private static final String _PAGE =
168                    "/html/taglib/ui/input_localized/page.jsp";
169    
170            private boolean _autoFocus;
171            private boolean _autoSize;
172            private Locale[] _availableLocales;
173            private String _cssClass;
174            private String _defaultLanguageId;
175            private boolean _disabled;
176            private String _displayWidth = ModelHintsConstants.TEXT_DISPLAY_WIDTH;
177            private String _formName;
178            private String _id;
179            private boolean _ignoreRequestValue;
180            private String _languageId;
181            private String _maxLength;
182            private String _name;
183            private String _type = "input";
184            private String _xml;
185    
186    }