001    /**
002     * Copyright (c) 2000-2013 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.HashMap;
022    import java.util.List;
023    import java.util.Map;
024    
025    import javax.portlet.PortletURL;
026    
027    import javax.servlet.http.HttpServletRequest;
028    
029    /**
030     * @author Julio Camarero
031     * @author Jorge Ferrer
032     * @author Brian Wing Shun Chan
033     */
034    public class FormTag extends BaseFormTag {
035    
036            @Override
037            public String getAction() {
038                    return super.getAction();
039            }
040    
041            public void setAction(PortletURL portletURL) {
042                    if (portletURL != null) {
043                            setAction(portletURL.toString());
044                    }
045            }
046    
047            @Override
048            protected void cleanUp() {
049                    super.cleanUp();
050    
051                    if (_validatorTagsMap != null) {
052                            for (List<ValidatorTag> validatorTags :
053                                            _validatorTagsMap.values()) {
054    
055                                    for (ValidatorTag validatorTag : validatorTags) {
056                                            validatorTag.cleanUp();
057                                    }
058                            }
059    
060                            _validatorTagsMap.clear();
061                    }
062            }
063    
064            @Override
065            protected boolean isCleanUpSetAttributes() {
066                    return _CLEAN_UP_SET_ATTRIBUTES;
067            }
068    
069            @Override
070            protected void setAttributes(HttpServletRequest request) {
071                    super.setAttributes(request);
072    
073                    if (getEscapeXml()) {
074                            String action = getAction();
075    
076                            super.setAction(HtmlUtil.escape(action));
077                    }
078    
079                    request.setAttribute("aui:form:validatorTagsMap", _validatorTagsMap);
080            }
081    
082            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
083    
084            private Map<String, List<ValidatorTag>> _validatorTagsMap =
085                    new HashMap<String, List<ValidatorTag>>();
086    
087    }