01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.tags.rendering;
20:
21: import org.apache.beehive.netui.tags.html.HtmlConstants;
22:
23: import java.util.HashMap;
24:
25: /**
26: * Render the HTML <button> element. In HTML 4.01 the start and end tags are required.
27: *
28: * <p>This renderer is just used by the NetUI Button as an alternative to the <input>
29: * HTML element rendered by the InputSubmitTag.
30: * </p>
31: */
32: public abstract class ButtonTag extends TagHtmlBase implements
33: HtmlConstants {
34: public static void add(HashMap html, HashMap htmlQuirks,
35: HashMap xhtml) {
36: html.put(BUTTON_TAG, new HtmlRendering());
37: htmlQuirks.put(BUTTON_TAG, new HtmlRendering());
38: xhtml.put(BUTTON_TAG, new XhtmlRendering());
39: }
40:
41: public static class State extends InputSubmitTag.State {
42: }
43:
44: public void doStartTag(AbstractRenderAppender writer,
45: AbstractTagState renderState) {
46: assert (writer != null) : "Parameter 'writer' must not be null";
47: assert (renderState != null) : "Parameter 'renderState' must not be null";
48: assert (renderState instanceof ButtonTag.State) : "Paramater 'renderState' must be an instance of ButtonTag.State";
49:
50: State state = (State) renderState;
51:
52: // Generate an HTML element
53: renderTag(writer, BUTTON);
54: if (state.type == null)
55: state.type = INPUT_SUBMIT;
56: renderAttribute(writer, TYPE, state.type);
57: renderAttribute(writer, NAME, state.name);
58: renderAttribute(writer, ID, state.id);
59: renderAttribute(writer, CLASS, state.styleClass);
60: renderAttribute(writer, VALUE, state.value);
61: renderDisabled(writer, state.disabled);
62:
63: renderAttributes(AbstractHtmlState.ATTR_GENERAL, writer, state);
64: renderAttribute(writer, STYLE, state.style);
65: renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, writer,
66: state);
67: writer.append(">");
68: }
69:
70: public void doEndTag(AbstractRenderAppender writer) {
71: renderEndTag(writer, BUTTON);
72: }
73:
74: abstract protected void renderDisabled(
75: AbstractRenderAppender writer, boolean disabled);
76:
77: private static class HtmlRendering extends ButtonTag {
78: protected void renderDisabled(AbstractRenderAppender writer,
79: boolean disabled) {
80: if (disabled)
81: writer.append(" disabled");
82:
83: }
84:
85: }
86:
87: private static class XhtmlRendering extends ButtonTag {
88: protected void renderDisabled(AbstractRenderAppender writer,
89: boolean disabled) {
90: if (disabled)
91: renderAttribute(writer, "disabled", "disabled");
92: }
93: }
94: }
|