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