KickJava   Java API By Example, From Geeks To Geeks.

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


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: optional, End tag: optional
26  * Required href
27  */

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