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