1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.taglib.ui;
16  
17  import com.liferay.portal.kernel.util.ParamUtil;
18  import com.liferay.portal.kernel.util.ServerDetector;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.kernel.util.StringUtil;
21  import com.liferay.portal.kernel.util.Validator;
22  import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
23  
24  import javax.portlet.PortletURL;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.jsp.JspException;
28  
29  /**
30   * <a href="TabsTag.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class TabsTag extends ParamAndPropertyAncestorTagImpl {
35  
36      public int doStartTag() throws JspException {
37          try {
38              HttpServletRequest request = getServletRequest();
39  
40              request.setAttribute("liferay-ui:tabs:names", _names);
41  
42              if ((_tabsValues == null) || (_tabsValues.length < _names.length)) {
43                  _tabsValues = _names;
44              }
45  
46              request.setAttribute("liferay-ui:tabs:values", _tabsValues);
47  
48              request.setAttribute("liferay-ui:tabs:formName", _formName);
49              request.setAttribute("liferay-ui:tabs:param", _param);
50  
51              if (_value == null) {
52                  if (_tabsValues.length > 0) {
53                      _value = ParamUtil.getString(
54                          request, _param, _tabsValues[0]);
55                  }
56              }
57  
58              if (Validator.isNull(_value)) {
59                  if (_tabsValues.length > 0) {
60                      _value = _tabsValues[0];
61                  }
62                  else {
63                      _value = StringPool.BLANK;
64                  }
65              }
66  
67              boolean match = false;
68  
69              for (int i = 0; i < _tabsValues.length; i++) {
70                  if (_value.equals(_tabsValues[i])) {
71                      match = true;
72                  }
73              }
74  
75              if (!match) {
76                  if (_tabsValues.length > 0) {
77                      _value = _tabsValues[0];
78                  }
79                  else {
80                      _value = StringPool.BLANK;
81                  }
82              }
83  
84              request.setAttribute("liferay-ui:tabs:value", _value);
85              request.setAttribute("liferay-ui:tabs:portletURL", _portletURL);
86              request.setAttribute("liferay-ui:tabs:url", _url);
87  
88              if (_url0 != null) {
89                  request.setAttribute("liferay-ui:tabs:url0", _url0);
90              }
91  
92              if (_url1 != null) {
93                  request.setAttribute("liferay-ui:tabs:url1", _url1);
94              }
95  
96              if (_url2 != null) {
97                  request.setAttribute("liferay-ui:tabs:url2", _url2);
98              }
99  
100             if (_url3 != null) {
101                 request.setAttribute("liferay-ui:tabs:url3", _url3);
102             }
103 
104             if (_url4 != null) {
105                 request.setAttribute("liferay-ui:tabs:url4", _url4);
106             }
107 
108             if (_url5 != null) {
109                 request.setAttribute("liferay-ui:tabs:url5", _url5);
110             }
111 
112             if (_url6 != null) {
113                 request.setAttribute("liferay-ui:tabs:url6", _url6);
114             }
115 
116             if (_url7 != null) {
117                 request.setAttribute("liferay-ui:tabs:url7", _url7);
118             }
119 
120             if (_url8 != null) {
121                 request.setAttribute("liferay-ui:tabs:url8", _url8);
122             }
123 
124             if (_url9 != null) {
125                 request.setAttribute("liferay-ui:tabs:url9", _url9);
126             }
127 
128             request.setAttribute("liferay-ui:tabs:backURL", _backURL);
129             request.setAttribute(
130                 "liferay-ui:tabs:refresh", String.valueOf(_refresh));
131             request.setAttribute(
132                 "liferay-ui:tabs:onClick", String.valueOf(_onClick));
133 
134             include(getStartPage());
135 
136             return EVAL_BODY_INCLUDE;
137         }
138         catch (Exception e) {
139             throw new JspException(e);
140         }
141     }
142 
143     public int doEndTag() throws JspException {
144         try {
145             HttpServletRequest request =
146                 (HttpServletRequest)pageContext.getRequest();
147 
148             include(getEndPage());
149 
150             request.removeAttribute("liferay-ui:tabs:names");
151             request.removeAttribute("liferay-ui:tabs:values");
152             request.removeAttribute("liferay-ui:tabs:formName");
153             request.removeAttribute("liferay-ui:tabs:param");
154             request.removeAttribute("liferay-ui:tabs:value");
155             request.removeAttribute("liferay-ui:tabs:portletURL");
156             request.removeAttribute("liferay-ui:tabs:url");
157             request.removeAttribute("liferay-ui:tabs:url0");
158             request.removeAttribute("liferay-ui:tabs:url1");
159             request.removeAttribute("liferay-ui:tabs:url2");
160             request.removeAttribute("liferay-ui:tabs:url3");
161             request.removeAttribute("liferay-ui:tabs:url4");
162             request.removeAttribute("liferay-ui:tabs:url5");
163             request.removeAttribute("liferay-ui:tabs:url6");
164             request.removeAttribute("liferay-ui:tabs:url7");
165             request.removeAttribute("liferay-ui:tabs:url8");
166             request.removeAttribute("liferay-ui:tabs:url9");
167             request.removeAttribute("liferay-ui:tabs:backURL");
168             request.removeAttribute("liferay-ui:tabs:refresh");
169             request.removeAttribute("liferay-ui:tabs:onClick");
170 
171             return EVAL_PAGE;
172         }
173         catch (Exception e) {
174             throw new JspException(e);
175         }
176         finally {
177             if (!ServerDetector.isResin()) {
178                 _startPage = null;
179                 _endPage = null;
180                 _names = null;
181                 _namesPos = 0;
182                 _tabsValues = null;
183                 _formName = StringPool.BLANK;
184                 _param = "tabs1";
185                 _value = null;
186                 _portletURL = null;
187                 _url = null;
188                 _url0 = null;
189                 _url1 = null;
190                 _url2 = null;
191                 _url3 = null;
192                 _url4 = null;
193                 _url5 = null;
194                 _url6 = null;
195                 _url7 = null;
196                 _url8 = null;
197                 _url9 = null;
198                 _backURL = null;
199                 _refresh = true;
200                 _onClick = null;
201             }
202         }
203     }
204 
205     public String getStartPage() {
206         if (Validator.isNull(_startPage)) {
207             return _START_PAGE;
208         }
209         else {
210             return _startPage;
211         }
212     }
213 
214     public void setStartPage(String startPage) {
215         _startPage = startPage;
216     }
217 
218     public String getEndPage() {
219         if (Validator.isNull(_endPage)) {
220             return _END_PAGE;
221         }
222         else {
223             return _endPage;
224         }
225     }
226 
227     public void setEndPage(String endPage) {
228         _endPage = endPage;
229     }
230 
231     public void setNames(String names) {
232         _names = StringUtil.split(names);
233     }
234 
235     public void setTabsValues(String tabsValues) {
236         _tabsValues = StringUtil.split(tabsValues);
237     }
238 
239     public void setFormName(String formName) {
240         _formName = formName;
241     }
242 
243     public String getParam() {
244         return _param;
245     }
246 
247     public void setParam(String param) {
248         _param = param;
249     }
250 
251     public void setValue(String value) {
252         _value = value;
253     }
254 
255     public void setPortletURL(PortletURL portletURL) {
256         _portletURL = portletURL;
257     }
258 
259     public void setUrl(String url) {
260         _url = url;
261     }
262 
263     public void setUrl0(String url0) {
264         _url0 = url0;
265     }
266 
267     public void setUrl1(String url1) {
268         _url1 = url1;
269     }
270 
271     public void setUrl2(String url2) {
272         _url2 = url2;
273     }
274 
275     public void setUrl3(String url3) {
276         _url3 = url3;
277     }
278 
279     public void setUrl4(String url4) {
280         _url4 = url4;
281     }
282 
283     public void setUrl5(String url5) {
284         _url5 = url5;
285     }
286 
287     public void setUrl6(String url6) {
288         _url6 = url6;
289     }
290 
291     public void setUrl7(String url7) {
292         _url7 = url7;
293     }
294 
295     public void setUrl8(String url8) {
296         _url8 = url8;
297     }
298 
299     public void setUrl9(String url9) {
300         _url9 = url9;
301     }
302 
303     public void setBackURL(String backURL) {
304         _backURL = backURL;
305     }
306 
307     public boolean isRefresh() {
308         return _refresh;
309     }
310 
311     public void setRefresh(boolean refresh) {
312         _refresh = refresh;
313     }
314 
315     public String getOnClick() {
316         return _onClick;
317     }
318 
319     public void setOnClick(String onClick) {
320         _onClick = onClick;
321     }
322 
323     public String getSectionName() {
324         if (_names.length > _namesPos) {
325             return _names[_namesPos];
326         }
327         else {
328             return StringPool.BLANK;
329         }
330     }
331 
332     public boolean getSectionSelected() {
333         if ((_names.length == 0) ||
334             ((_names.length > _namesPos) &&
335                 (_names[_namesPos].equals(_value)))) {
336 
337             return true;
338         }
339         else {
340             return false;
341         }
342     }
343 
344     public void incrementSection() {
345         _namesPos++;
346     }
347 
348     private static final String _START_PAGE = "/html/taglib/ui/tabs/start.jsp";
349 
350     private static final String _END_PAGE = "/html/taglib/ui/tabs/end.jsp";
351 
352     private String _startPage;
353     private String _endPage;
354     private String[] _names;
355     private int _namesPos;
356     private String[] _tabsValues;
357     private String _formName;
358     private String _param = "tabs1";
359     private String _value;
360     private PortletURL _portletURL;
361     private String _url;
362     private String _url0;
363     private String _url1;
364     private String _url2;
365     private String _url3;
366     private String _url4;
367     private String _url5;
368     private String _url6;
369     private String _url7;
370     private String _url8;
371     private String _url9;
372     private String _backURL;
373     private boolean _refresh = true;
374     private String _onClick;
375 
376 }