001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.taglib.aui;
016    
017    import com.liferay.portal.kernel.util.JavaConstants;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.util.PortalUtil;
021    import com.liferay.taglib.aui.base.BaseFieldsetTag;
022    
023    import javax.portlet.PortletResponse;
024    
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.jsp.JspException;
027    
028    /**
029     * @author Julio Camarero
030     * @author Jorge Ferrer
031     * @author Brian Wing Shun Chan
032     */
033    public class FieldsetTag extends BaseFieldsetTag {
034    
035            @Override
036            public int doStartTag() throws JspException {
037                    FieldsetGroupTag fieldsetGroupTag =
038                            (FieldsetGroupTag)findAncestorWithClass(
039                                    this, FieldsetGroupTag.class);
040    
041                    if (Validator.isNull(getMarkupView()) && (fieldsetGroupTag != null)) {
042                            setMarkupView(fieldsetGroupTag.getMarkupView());
043                    }
044    
045                    return super.doStartTag();
046            }
047    
048            @Override
049            protected String getEndPage() {
050                    if (Validator.isNotNull(getMarkupView())) {
051                            return "/html/taglib/aui/fieldset/" + getMarkupView() + "/end.jsp";
052                    }
053    
054                    return "/html/taglib/aui/fieldset/end.jsp";
055            }
056    
057            @Override
058            protected String getStartPage() {
059                    if (Validator.isNotNull(getMarkupView())) {
060                            return "/html/taglib/aui/fieldset/" + getMarkupView() +
061                                    "/start.jsp";
062                    }
063    
064                    return "/html/taglib/aui/fieldset/start.jsp";
065            }
066    
067            @Override
068            protected boolean isCleanUpSetAttributes() {
069                    return _CLEAN_UP_SET_ATTRIBUTES;
070            }
071    
072            @Override
073            protected void setAttributes(HttpServletRequest request) {
074                    super.setAttributes(request);
075    
076                    String panelId = StringPool.BLANK;
077    
078                    if (Validator.isNotNull(getLabel()) && getCollapsible()) {
079                            panelId = PortalUtil.getUniqueElementId(
080                                    request, _getNamespace(), AUIUtil.normalizeId(getLabel()));
081                    }
082    
083                    setNamespacedAttribute(request, "panelId", panelId);
084            }
085    
086            private String _getNamespace() {
087                    HttpServletRequest request =
088                            (HttpServletRequest)pageContext.getRequest();
089    
090                    PortletResponse portletResponse = (PortletResponse)request.getAttribute(
091                            JavaConstants.JAVAX_PORTLET_RESPONSE);
092    
093                    if (portletResponse != null) {
094                            return portletResponse.getNamespace();
095                    }
096    
097                    return StringPool.BLANK;
098            }
099    
100            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
101    
102    }