KickJava   Java API By Example, From Geeks To Geeks.

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


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 InputTextTag extends TagHtmlBase
29         implements HtmlConstants
30 {
31     public static void add(HashMap JavaDoc html, HashMap JavaDoc htmlQuirks, HashMap JavaDoc xhtml)
32     {
33         html.put(INPUT_TEXT_TAG, new HtmlRendering());
34         htmlQuirks.put(INPUT_TEXT_TAG, new HtmlRendering());
35         xhtml.put(INPUT_TEXT_TAG, new XhtmlRendering());
36     }
37
38     public static class State extends AbstractHtmlControlState
39     {
40         public String JavaDoc type;
41         public boolean disabled;
42         public int maxlength;
43         public int size;
44         public String JavaDoc value;
45         public boolean readonly;
46
47         public void clear()
48         {
49             super.clear();
50
51             type = null;
52             disabled = false;
53             maxlength = 0;
54             size = 0;
55             value = null;
56             readonly = false;
57         }
58     }
59
60     public void doStartTag(AbstractRenderAppender sb, AbstractTagState renderState)
61     {
62         assert(sb != null) : "Parameter 'sb' must not be null";
63         assert(renderState != null) : "Parameter 'renderState' must not be null";
64         assert(renderState instanceof State) : "Paramater 'renderState' must be an instance of AnchorTag.State";
65
66         State state = (State) renderState;
67
68         // Generate an HTML element
69
renderTag(sb, INPUT);
70         if (state.type == null)
71             state.type = INPUT_TEXT;
72
73         renderAttribute(sb, TYPE, state.type);
74         renderAttribute(sb, NAME, state.name);
75         renderAttribute(sb, ID, state.id);
76         renderAttribute(sb, CLASS, state.styleClass);
77         renderAttribute(sb, VALUE, state.value);
78
79         if (state.maxlength > 0)
80             renderAttribute(sb, MAXLENGTH, Integer.toString(state.maxlength));
81         if (state.size > 0)
82             renderAttribute(sb, SIZE, Integer.toString(state.size));
83         renderDisabled(sb, state.disabled);
84         renderReadonly(sb, state.readonly);
85
86         renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
87         renderAttribute(sb, STYLE, state.style);
88         renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
89         writeEnd(sb);
90     }
91
92     public void doEndTag(AbstractRenderAppender sb)
93     {
94     }
95
96     abstract protected void writeEnd(AbstractRenderAppender sb);
97
98     abstract protected void renderDisabled(AbstractRenderAppender sb, boolean disabled);
99
100     abstract protected void renderReadonly(AbstractRenderAppender sb, boolean readonly);
101
102     private static class HtmlRendering extends InputTextTag
103     {
104         protected void writeEnd(AbstractRenderAppender sb)
105         {
106             sb.append(">");
107         }
108
109         protected void renderDisabled(AbstractRenderAppender sb, boolean disabled)
110         {
111             if (disabled)
112                 sb.append(" disabled");
113         }
114
115         protected void renderReadonly(AbstractRenderAppender sb, boolean readonly)
116         {
117             if (readonly)
118                 sb.append(" readonly");
119         }
120     }
121
122     private static class XhtmlRendering extends InputTextTag
123     {
124         protected void writeEnd(AbstractRenderAppender sb)
125         {
126             sb.append(" />");
127         }
128
129         protected void renderDisabled(AbstractRenderAppender sb, boolean disabled)
130         {
131             if (disabled)
132                 renderAttribute(sb, "disabled", "disabled");
133         }
134
135         protected void renderReadonly(AbstractRenderAppender sb, boolean readonly)
136         {
137             if (readonly)
138                 renderAttribute(sb, "readonly", "readonly");
139         }
140
141     }
142 }
143
Popular Tags