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.aui;
16  
17  import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
18  import com.liferay.portal.kernel.util.ServerDetector;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.taglib.util.IncludeTag;
21  import com.liferay.util.TextFormatter;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.jsp.JspException;
28  import javax.servlet.jsp.tagext.DynamicAttributes;
29  
30  /**
31   * <a href="SelectTag.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Julio Camarero
34   * @author Jorge Ferrer
35   * @author Brian Wing Shun Chan
36   */
37  public class SelectTag extends IncludeTag implements DynamicAttributes {
38  
39      public int doEndTag() throws JspException {
40          try{
41              PortalIncludeUtil.include(pageContext, getEndPage());
42  
43              return EVAL_PAGE;
44          }
45          catch (Exception e) {
46              throw new JspException(e);
47          }
48          finally {
49              if (!ServerDetector.isResin()) {
50                  _bean = null;
51                  _changesContext = false;
52                  _cssClass = null;
53                  _dynamicAttributes.clear();
54                  _endPage = null;
55                  _first = false;
56                  _helpMessage = null;
57                  _inlineField = false;
58                  _inlineLabel = null;
59                  _id = null;
60                  _label = null;
61                  _last = false;
62                  _listType = null;
63                  _name = null;
64                  _prefix = null;
65                  _showEmptyOption = false;
66                  _startPage = null;
67                  _suffix = null;
68                  _title = null;
69              }
70          }
71      }
72  
73      public int doStartTag() throws JspException {
74          try{
75              HttpServletRequest request =
76                  (HttpServletRequest)pageContext.getRequest();
77  
78              if (_bean == null) {
79                  _bean = pageContext.getAttribute("aui:model-context:bean");
80              }
81  
82              if (Validator.isNull(_id)) {
83                  _id = _name;
84              }
85  
86              if (_label == null) {
87                  _label = TextFormatter.format(_name, TextFormatter.K);
88              }
89  
90              request.setAttribute("aui:select:bean", _bean);
91              request.setAttribute(
92                  "aui:select:changesContext", String.valueOf(_changesContext));
93              request.setAttribute("aui:select:cssClass", _cssClass);
94              request.setAttribute(
95                  "aui:select:disabled", String.valueOf(_disabled));
96              request.setAttribute(
97                  "aui:select:dynamicAttributes", _dynamicAttributes);
98              request.setAttribute("aui:select:first", String.valueOf(_first));
99              request.setAttribute("aui:select:helpMessage", _helpMessage);
100             request.setAttribute(
101                 "aui:select:inlineField", String.valueOf(_inlineField));
102             request.setAttribute("aui:select:inlineLabel", _inlineLabel);
103             request.setAttribute("aui:select:id", _id);
104             request.setAttribute("aui:select:label", _label);
105             request.setAttribute("aui:select:last", String.valueOf(_last));
106             request.setAttribute("aui:select:listType", _listType);
107             request.setAttribute("aui:select:name", _name);
108             request.setAttribute("aui:select:prefix", _prefix);
109             request.setAttribute(
110                 "aui:select:showEmptyOption", String.valueOf(_showEmptyOption));
111             request.setAttribute("aui:select:suffix", _suffix);
112             request.setAttribute("aui:select:title", _title);
113 
114             PortalIncludeUtil.include(pageContext, getStartPage());
115 
116             return EVAL_BODY_INCLUDE;
117         }
118         catch (Exception e) {
119             throw new JspException(e);
120         }
121     }
122 
123     public String getEndPage() {
124         if (Validator.isNull(_endPage)) {
125             return _END_PAGE;
126         }
127         else {
128             return _endPage;
129         }
130     }
131 
132     public String getStartPage() {
133         if (Validator.isNull(_startPage)) {
134             return _START_PAGE;
135         }
136         else {
137             return _startPage;
138         }
139     }
140 
141     public void setBean(Object bean) {
142         _bean = bean;
143     }
144 
145     public void setChangesContext(boolean changesContext) {
146         _changesContext = changesContext;
147     }
148 
149     public void setCssClass(String cssClass) {
150         _cssClass = cssClass;
151     }
152 
153     public void setDisabled(boolean disabled) {
154         _disabled = disabled;
155     }
156 
157     public void setDynamicAttribute(
158         String uri, String localName, Object value) {
159 
160         _dynamicAttributes.put(localName, value);
161     }
162 
163     public void setEndPage(String endPage) {
164         _endPage = endPage;
165     }
166 
167     public void setFirst(boolean first) {
168         _first = first;
169     }
170 
171     public void setHelpMessage(String helpMessage) {
172         _helpMessage = helpMessage;
173     }
174 
175     public void setId(String id) {
176         _id = id;
177     }
178 
179     public void setInlineField(boolean inlineField) {
180         _inlineField = inlineField;
181     }
182 
183     public void setInlineLabel(String inlineLabel) {
184         _inlineLabel = inlineLabel;
185     }
186 
187     public void setLabel(String label) {
188         _label = label;
189     }
190 
191     public void setLast(boolean last) {
192         _last = last;
193     }
194 
195     public void setListType(String listType) {
196         _listType = listType;
197     }
198 
199     public void setName(String name) {
200         _name = name;
201     }
202 
203     public void setPrefix(String prefix) {
204         _prefix = prefix;
205     }
206 
207     public void setShowEmptyOption(boolean showEmptyOption) {
208         _showEmptyOption = showEmptyOption;
209     }
210 
211     public void setStartPage(String startPage) {
212         _startPage = startPage;
213     }
214 
215     public void setTitle(String title) {
216         _title = title;
217     }
218 
219     public void setSuffix(String suffix) {
220         _suffix = suffix;
221     }
222 
223     private static final String _END_PAGE = "/html/taglib/aui/select/end.jsp";
224 
225     private static final String _START_PAGE =
226         "/html/taglib/aui/select/start.jsp";
227 
228     private Object _bean;
229     private boolean _changesContext;
230     private String _cssClass;
231     private boolean _disabled;
232     private Map<String, Object> _dynamicAttributes =
233         new HashMap<String, Object>();
234     private String _endPage;
235     private boolean _first;
236     private String _helpMessage;
237     private String _id;
238     private boolean _inlineField;
239     private String _inlineLabel;
240     private String _label;
241     private boolean _last;
242     private String _listType;
243     private String _name;
244     private String _prefix;
245     private boolean _showEmptyOption;
246     private String _startPage;
247     private String _suffix;
248     private String _title;
249 
250 }