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