001    /**
002     * Copyright (c) 2000-2010 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.taglib.util.IncludeTag;
018    
019    import javax.servlet.http.HttpServletRequest;
020    
021    /**
022     * @author Julio Camarero
023     * @author Jorge Ferrer
024     * @author Brian Wing Shun Chan
025     */
026    public class OptionTag extends IncludeTag {
027    
028            public void setCssClass(String cssClass) {
029                    _cssClass = cssClass;
030            }
031    
032            public void setLabel(Object label) {
033                    _label = String.valueOf(label);
034            }
035    
036            public void setSelected(boolean selected) {
037                    _selected = selected;
038            }
039    
040            public void setStyle(String style) {
041                    _style = style;
042            }
043    
044            public void setValue(Object value) {
045                    _value = String.valueOf(value);
046            }
047    
048            protected void cleanUp() {
049                    _cssClass = null;
050                    _label = null;
051                    _selected = false;
052                    _style = null;
053                    _value = null;
054            }
055    
056            protected String getEndPage() {
057                    return _END_PAGE;
058            }
059    
060            protected String getStartPage() {
061                    return _START_PAGE;
062            }
063    
064            protected boolean isCleanUpSetAttributes() {
065                    return _CLEAN_UP_SET_ATTRIBUTES;
066            }
067    
068            protected void setAttributes(HttpServletRequest request) {
069                    String value = _value;
070    
071                    if (value == null) {
072                            value = _label;
073                    }
074    
075                    request.setAttribute("aui:option:cssClass", _cssClass);
076                    request.setAttribute(
077                            "aui:option:dynamicAttributes", getDynamicAttributes());
078                    request.setAttribute("aui:option:label", _label);
079                    request.setAttribute(
080                            "aui:option:selected", String.valueOf(_selected));
081                    request.setAttribute("aui:option:style", _style);
082                    request.setAttribute("aui:option:value", value);
083            }
084    
085            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
086    
087            private static final String _END_PAGE = "/html/taglib/aui/option/end.jsp";
088    
089            private static final String _START_PAGE =
090                    "/html/taglib/aui/option/start.jsp";
091    
092            private String _cssClass;
093            private String _label;
094            private boolean _selected;
095            private String _style;
096            private String _value;
097    
098    }