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