001    package net.sf.jolene.dom;
002    
003    import net.sf.jolene.constants.Tags;
004    
005    /**
006     * A button in a html document using the button - not the input tag.
007     *
008     * @author Dan Howard
009     * @since Nov 16, 2003
010     */
011    public final class Button extends HTMLElement {
012    
013        /**
014         * Construct a button with the specified name.
015         *
016         * @param name name of the button.
017         */
018        public Button(String name) {
019            this();
020            setName(name);
021        }
022    
023        /**
024         * Default constructor.
025         */
026        public Button() {
027            tag = Tags.button;
028        }
029    
030        /**
031         * Returns a clone of the button object.
032         *
033         * @return Button object.
034         */
035        @Override
036        public Button clone() {
037            return (Button) super.clone();
038        }
039    
040        /**
041         * Sets the name of the button.
042         *
043         * @param name name of the button.
044         */
045        @Override
046        public void setName(String name) {
047            super.setName(name);
048            setAttribute("name", name);
049        }
050    
051        /**
052         * Sets the value of the button.
053         *
054         * @param value value of the button.
055         */
056        @Override
057        public void setValue(String value) {
058            super.setValue(value);
059            setAttribute("value", value);
060        }
061    
062        /**
063         * Renders the button.
064         *
065         * @return The button as a html string.
066         */
067        @Override
068        public String toString() {
069            if (swapWith != null) {
070                return swapWith.toString();
071            }
072    
073            if (!isRenderable() && !log.isDebugEnabled()) {
074                return "";
075            }
076    
077            return super.toString() + getContent() + "</" + tag + '>';
078        }
079    }