001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.taglib.ui;
016    
017    import com.liferay.portal.kernel.util.JavaConstants;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.taglib.util.IncludeTag;
020    
021    import javax.portlet.PortletResponse;
022    
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.jsp.JspException;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class SectionTag extends IncludeTag {
030    
031            public int doStartTag() throws JspException {
032                    try {
033                            _tabsTag = (TabsTag)findAncestorWithClass(this, TabsTag.class);
034    
035                            if (_tabsTag == null) {
036                                    throw new JspException();
037                            }
038    
039                            HttpServletRequest request =
040                                    (HttpServletRequest)pageContext.getRequest();
041    
042                            PortletResponse portletResponse =
043                                    (PortletResponse)request.getAttribute(
044                                            JavaConstants.JAVAX_PORTLET_RESPONSE);
045    
046                            String namespace = StringPool.BLANK;
047    
048                            if (portletResponse != null) {
049                                    namespace = portletResponse.getNamespace();
050                            }
051    
052                            String sectionParam = _tabsTag.getParam();
053                            String sectionName = _tabsTag.getSectionName();
054                            _sectionSelected = Boolean.valueOf(_tabsTag.getSectionSelected());
055                            String sectionScroll = namespace + sectionParam + "TabsScroll";
056                            String sectionRedirectParams =
057                                    "&scroll=" + sectionScroll + "&" + sectionParam + "=" +
058                                            sectionName;
059    
060                            _tabsTag.incrementSection();
061    
062                            request.setAttribute("liferay-ui:section:param", sectionParam);
063                            request.setAttribute("liferay-ui:section:name", sectionName);
064                            request.setAttribute(
065                                    "liferay-ui:section:selected", _sectionSelected);
066                            request.setAttribute("liferay-ui:section:scroll", sectionScroll);
067    
068                            pageContext.setAttribute("sectionSelected", _sectionSelected);
069                            pageContext.setAttribute("sectionParam", sectionParam);
070                            pageContext.setAttribute("sectionName", sectionName);
071                            pageContext.setAttribute("sectionScroll", sectionScroll);
072                            pageContext.setAttribute(
073                                    "sectionRedirectParams", sectionRedirectParams);
074    
075                            if (!_tabsTag.isRefresh() || _sectionSelected.booleanValue()) {
076                                    if (!_tabsTag.isRefresh()) {
077                                            include(getStartPage());
078                                    }
079    
080                                    return EVAL_BODY_INCLUDE;
081                            }
082                            else {
083                                    return EVAL_PAGE;
084                            }
085                    }
086                    catch (Exception e) {
087                            throw new JspException(e);
088                    }
089            }
090    
091            protected String getStartPage() {
092                    return _START_PAGE;
093            }
094    
095            protected String getEndPage() {
096                    return _END_PAGE;
097            }
098    
099            private static final String _START_PAGE =
100                    "/html/taglib/ui/section/start.jsp";
101    
102            private static final String _END_PAGE = "/html/taglib/ui/section/end.jsp";
103    
104            private TabsTag _tabsTag = null;
105            private Boolean _sectionSelected = Boolean.FALSE;
106    
107    }