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.StringUtil;
018    import com.liferay.taglib.aui.base.BaseButtonTag;
019    
020    import javax.servlet.http.HttpServletRequest;
021    import javax.servlet.jsp.JspException;
022    import javax.servlet.jsp.tagext.BodyTag;
023    
024    /**
025     * @author Julio Camarero
026     * @author Jorge Ferrer
027     * @author Brian Wing Shun Chan
028     */
029    public class ButtonTag extends BaseButtonTag implements BodyTag {
030    
031            @Override
032            public int doStartTag() throws JspException {
033                    super.doStartTag();
034    
035                    return BodyTag.EVAL_BODY_BUFFERED;
036            }
037    
038            @Override
039            public void setIconAlign(String iconAlign) {
040                    if (iconAlign != null) {
041                            super.setIconAlign(StringUtil.toLowerCase(iconAlign));
042                    }
043            }
044    
045            @Override
046            protected boolean isCleanUpSetAttributes() {
047                    return _CLEAN_UP_SET_ATTRIBUTES;
048            }
049    
050            @Override
051            protected void setAttributes(HttpServletRequest request) {
052                    super.setAttributes(request);
053    
054                    String value = getValue();
055    
056                    if (value == null) {
057                            String type = getType();
058    
059                            if (type.equals("submit")) {
060                                    value = "save";
061                            }
062                            else if (type.equals("cancel")) {
063                                    value = "cancel";
064                            }
065                            else if (type.equals("reset")) {
066                                    value = "reset";
067                            }
068                    }
069    
070                    setNamespacedAttribute(request, "value", value);
071            }
072    
073            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
074    
075    }