KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > rendering > InputSubmitTag


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.rendering;
19
20 import org.apache.beehive.netui.tags.html.HtmlConstants;
21
22 import java.util.HashMap JavaDoc;
23
24 /**
25  * Body, Start Tag: required, End tag: forbidden
26  * Required href
27  */

28 abstract public class InputSubmitTag extends TagHtmlBase implements HtmlConstants
29 {
30     public static void add(HashMap JavaDoc html, HashMap JavaDoc htmlQuirks, HashMap JavaDoc xhtml)
31     {
32         html.put(INPUT_SUBMIT_TAG, new HtmlRendering());
33         htmlQuirks.put(INPUT_SUBMIT_TAG, new HtmlRendering());
34         xhtml.put(INPUT_SUBMIT_TAG, new XhtmlRendering());
35     }
36
37     public static class State extends AbstractHtmlControlState
38     {
39         public String JavaDoc type;
40         public boolean disabled;
41         public String JavaDoc value;
42
43         public void clear()
44         {
45             super.clear();
46
47             type = null;
48             disabled = false;
49             value = null;
50         }
51     }
52
53     public void doStartTag(AbstractRenderAppender sb, AbstractTagState renderState)
54     {
55         assert(sb != null) : "Parameter 'sb' must not be null";
56         assert(renderState != null) : "Parameter 'renderState' must not be null";
57         assert(renderState instanceof State) : "Paramater 'renderState' must be an instance of InputSubmitTag.State";
58
59         State state = (State) renderState;
60
61         // Generate an HTML element
62
renderTag(sb, INPUT);
63         if (state.type == null)
64             state.type = INPUT_SUBMIT;
65         renderAttribute(sb, TYPE, state.type);
66         renderAttribute(sb, NAME, state.name);
67         renderAttribute(sb, ID, state.id);
68         renderAttribute(sb, CLASS, state.styleClass);
69         renderAttribute(sb, VALUE, state.value);
70
71         renderDisabled(sb, state.disabled);
72
73         renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
74         renderAttribute(sb, STYLE, state.style);
75         renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
76         writeEnd(sb);
77     }
78
79     public void doEndTag(AbstractRenderAppender sb)
80     {
81     }
82
83     abstract protected void writeEnd(AbstractRenderAppender sb);
84
85     abstract protected void renderDisabled(AbstractRenderAppender sb, boolean disabled);
86
87
88     private static class HtmlRendering extends InputSubmitTag
89     {
90         protected void writeEnd(AbstractRenderAppender sb)
91         {
92             sb.append(">");
93         }
94
95         protected void renderDisabled(AbstractRenderAppender sb, boolean disabled)
96         {
97             if (disabled)
98                 sb.append(" disabled");
99
100         }
101
102     }
103
104     private static class XhtmlRendering extends InputSubmitTag
105     {
106         protected void writeEnd(AbstractRenderAppender sb)
107         {
108             sb.append(" />");
109         }
110
111         protected void renderDisabled(AbstractRenderAppender sb, boolean disabled)
112         {
113             if (disabled)
114                 renderAttribute(sb, "disabled", "disabled");
115         }
116     }
117 }
118
Popular Tags