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.servlet.taglib.aui.ValidatorTag;
018    import com.liferay.portal.kernel.util.HtmlUtil;
019    import com.liferay.taglib.aui.base.BaseFormTag;
020    
021    import java.util.ArrayList;
022    import java.util.HashMap;
023    import java.util.List;
024    import java.util.Map;
025    
026    import javax.portlet.PortletURL;
027    
028    import javax.servlet.http.HttpServletRequest;
029    
030    /**
031     * @author Julio Camarero
032     * @author Jorge Ferrer
033     * @author Brian Wing Shun Chan
034     */
035    public class FormTag extends BaseFormTag {
036    
037            @Override
038            public String getAction() {
039                    return super.getAction();
040            }
041    
042            public void setAction(PortletURL portletURL) {
043                    if (portletURL != null) {
044                            setAction(portletURL.toString());
045                    }
046            }
047    
048            @Override
049            protected void cleanUp() {
050                    super.cleanUp();
051    
052                    _checkboxNames.clear();
053    
054                    if (_validatorTagsMap != null) {
055                            for (List<ValidatorTag> validatorTags :
056                                            _validatorTagsMap.values()) {
057    
058                                    for (ValidatorTag validatorTag : validatorTags) {
059                                            validatorTag.cleanUp();
060                                    }
061                            }
062    
063                            _validatorTagsMap.clear();
064                    }
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                    if (getEscapeXml()) {
077                            String action = getAction();
078    
079                            super.setAction(HtmlUtil.escape(action));
080                    }
081    
082                    request.setAttribute(
083                            "LIFERAY_SHARED_aui:form:checkboxNames", _checkboxNames);
084                    request.setAttribute("aui:form:validatorTagsMap", _validatorTagsMap);
085            }
086    
087            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
088    
089            private final List<String> _checkboxNames = new ArrayList<>();
090            private final Map<String, List<ValidatorTag>> _validatorTagsMap =
091                    new HashMap<>();
092    
093    }