1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.taglib.ui;
24  
25  import com.liferay.portal.kernel.util.JavaConstants;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.taglib.util.ParamAncestorTagImpl;
29  
30  import javax.portlet.RenderResponse;
31  
32  import javax.servlet.ServletRequest;
33  import javax.servlet.jsp.JspException;
34  
35  /**
36   * <a href="SectionTag.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class SectionTag extends ParamAncestorTagImpl {
42  
43      public int doStartTag() throws JspException {
44          _tabsTag = (TabsTag)findAncestorWithClass(this, TabsTag.class);
45  
46          if (_tabsTag == null) {
47              throw new JspException();
48          }
49  
50          try {
51              ServletRequest req = pageContext.getRequest();
52  
53              RenderResponse renderResponse = (RenderResponse)req.getAttribute(
54                  JavaConstants.JAVAX_PORTLET_RESPONSE);
55  
56              String namespace = StringPool.BLANK;
57  
58              if (renderResponse != null) {
59                  namespace = renderResponse.getNamespace();
60              }
61  
62              String sectionParam = _tabsTag.getParam();
63              String sectionName = _tabsTag.getSectionName();
64              _sectionSelected = Boolean.valueOf(_tabsTag.getSectionSelected());
65              String sectionScroll = namespace + sectionParam + "TabsScroll";
66              String sectionRedirectParams =
67                  "&scroll=" + sectionScroll + "&" + sectionParam + "=" +
68                      sectionName;
69  
70              _tabsTag.incrementSection();
71  
72              req.setAttribute("liferay-ui:section:param", sectionParam);
73              req.setAttribute("liferay-ui:section:name", sectionName);
74              req.setAttribute("liferay-ui:section:selected", _sectionSelected);
75              req.setAttribute("liferay-ui:section:scroll", sectionScroll);
76  
77              pageContext.setAttribute("sectionSelected", _sectionSelected);
78              pageContext.setAttribute("sectionParam", sectionParam);
79              pageContext.setAttribute("sectionName", sectionName);
80              pageContext.setAttribute("sectionScroll", sectionScroll);
81              pageContext.setAttribute(
82                  "sectionRedirectParams", sectionRedirectParams);
83  
84              if (!_tabsTag.isRefresh() || _sectionSelected.booleanValue()) {
85                  if (!_tabsTag.isRefresh()) {
86                      include(getStartPage());
87                  }
88  
89                  return EVAL_BODY_INCLUDE;
90              }
91              else {
92                  return EVAL_PAGE;
93              }
94          }
95          catch (Exception e) {
96              throw new JspException(e);
97          }
98      }
99  
100     public int doEndTag() throws JspException {
101         try {
102             if (!_tabsTag.isRefresh() || _sectionSelected.booleanValue()) {
103                 if (!_tabsTag.isRefresh()) {
104                     include(getEndPage());
105                 }
106 
107                 return EVAL_BODY_INCLUDE;
108             }
109             else {
110                 return EVAL_PAGE;
111             }
112         }
113         catch (Exception e) {
114             throw new JspException(e);
115         }
116     }
117 
118     public String getStartPage() {
119         if (Validator.isNull(_startPage)) {
120             return _START_PAGE;
121         }
122         else {
123             return _startPage;
124         }
125     }
126 
127     public void setStartPage(String startPage) {
128         _startPage = startPage;
129     }
130 
131     public String getEndPage() {
132         if (Validator.isNull(_endPage)) {
133             return _END_PAGE;
134         }
135         else {
136             return _endPage;
137         }
138     }
139 
140     public void setEndPage(String endPage) {
141         _endPage = endPage;
142     }
143 
144     private static final String _START_PAGE =
145         "/html/taglib/ui/section/start.jsp";
146 
147     private static final String _END_PAGE = "/html/taglib/ui/section/end.jsp";
148 
149     private String _startPage;
150     private String _endPage;
151     private TabsTag _tabsTag = null;
152     private Boolean _sectionSelected = Boolean.FALSE;
153 
154 }