1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.ui;
16  
17  import com.liferay.portal.kernel.language.LanguageUtil;
18  import com.liferay.portal.kernel.util.LocaleUtil;
19  import com.liferay.taglib.util.IncludeTag;
20  
21  import java.util.Locale;
22  
23  import javax.servlet.http.HttpServletRequest;
24  
25  /**
26   * <a href="LanguageTag.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class LanguageTag extends IncludeTag {
31  
32      public static final int LIST_ICON = 0;
33  
34      public static final int LIST_LONG_TEXT = 1;
35  
36      public static final int LIST_SHORT_TEXT = 2;
37  
38      public static final int SELECT_BOX = 3;
39  
40      public void setDisplayStyle(int displayStyle) {
41          _displayStyle = displayStyle;
42      }
43  
44      public void setFormAction(String formAction) {
45          _formAction = formAction;
46      }
47  
48      public void setFormName(String formName) {
49          _formName = formName;
50      }
51  
52      public void setLanguageIds(String[] languageIds) {
53          _languageIds = languageIds;
54      }
55  
56      public void setName(String name) {
57          _name = name;
58      }
59  
60      protected void cleanUp() {
61          _displayStyle = LIST_ICON;
62          _formAction = null;
63          _formName =  "fm";
64          _languageIds = null;
65          _name = "languageId";
66      }
67  
68      protected String getPage() {
69          return _PAGE;
70      }
71  
72      protected void setAttributes(HttpServletRequest request) {
73          request.setAttribute(
74              "liferay-ui:language:displayStyle", String.valueOf(_displayStyle));
75          request.setAttribute("liferay-ui:language:formAction", _formAction);
76          request.setAttribute("liferay-ui:language:formName", _formName);
77  
78          Locale[] locales = null;
79  
80          if ((_languageIds == null) || (_languageIds.length == 0)) {
81              locales = LanguageUtil.getAvailableLocales();
82          }
83          else {
84              locales = LocaleUtil.fromLanguageIds(_languageIds);
85          }
86  
87          request.setAttribute("liferay-ui:language:locales", locales);
88          request.setAttribute("liferay-ui:language:name", _name);
89      }
90  
91      private static final String _PAGE = "/html/taglib/ui/language/page.jsp";
92  
93      private int _displayStyle = LIST_ICON;
94      private String _formAction;
95      private String _formName = "fm";
96      private String[] _languageIds;
97      private String _name = "languageId";
98  
99  }