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.util.JavaConstants;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.taglib.util.IncludeTag;
20  
21  import javax.portlet.PortletResponse;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.jsp.JspException;
25  
26  /**
27   * <a href="SectionTag.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class SectionTag extends IncludeTag {
32  
33      public int doStartTag() throws JspException {
34          try {
35              _tabsTag = (TabsTag)findAncestorWithClass(this, TabsTag.class);
36  
37              if (_tabsTag == null) {
38                  throw new JspException();
39              }
40  
41              HttpServletRequest request =
42                  (HttpServletRequest)pageContext.getRequest();
43  
44              PortletResponse portletResponse =
45                  (PortletResponse)request.getAttribute(
46                      JavaConstants.JAVAX_PORTLET_RESPONSE);
47  
48              String namespace = StringPool.BLANK;
49  
50              if (portletResponse != null) {
51                  namespace = portletResponse.getNamespace();
52              }
53  
54              String sectionParam = _tabsTag.getParam();
55              String sectionName = _tabsTag.getSectionName();
56              _sectionSelected = Boolean.valueOf(_tabsTag.getSectionSelected());
57              String sectionScroll = namespace + sectionParam + "TabsScroll";
58              String sectionRedirectParams =
59                  "&scroll=" + sectionScroll + "&" + sectionParam + "=" +
60                      sectionName;
61  
62              _tabsTag.incrementSection();
63  
64              request.setAttribute("liferay-ui:section:param", sectionParam);
65              request.setAttribute("liferay-ui:section:name", sectionName);
66              request.setAttribute(
67                  "liferay-ui:section:selected", _sectionSelected);
68              request.setAttribute("liferay-ui:section:scroll", sectionScroll);
69  
70              pageContext.setAttribute("sectionSelected", _sectionSelected);
71              pageContext.setAttribute("sectionParam", sectionParam);
72              pageContext.setAttribute("sectionName", sectionName);
73              pageContext.setAttribute("sectionScroll", sectionScroll);
74              pageContext.setAttribute(
75                  "sectionRedirectParams", sectionRedirectParams);
76  
77              if (!_tabsTag.isRefresh() || _sectionSelected.booleanValue()) {
78                  if (!_tabsTag.isRefresh()) {
79                      include(getStartPage());
80                  }
81  
82                  return EVAL_BODY_INCLUDE;
83              }
84              else {
85                  return EVAL_PAGE;
86              }
87          }
88          catch (Exception e) {
89              throw new JspException(e);
90          }
91      }
92  
93      protected String getStartPage() {
94          return _START_PAGE;
95      }
96  
97      protected String getEndPage() {
98          return _END_PAGE;
99      }
100 
101     private static final String _START_PAGE =
102         "/html/taglib/ui/section/start.jsp";
103 
104     private static final String _END_PAGE = "/html/taglib/ui/section/end.jsp";
105 
106     private TabsTag _tabsTag = null;
107     private Boolean _sectionSelected = Boolean.FALSE;
108 
109 }