KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Renderthe HTML <form> element. In HTML 4.01 both the start and end tag are rquired.
26  * The action is a required attribute.
27  */

28 public abstract class FormTag extends TagHtmlBase implements HtmlConstants
29 {
30     public static void add(HashMap JavaDoc html, HashMap JavaDoc htmlQuirks, HashMap JavaDoc xhtml)
31     {
32         html.put(FORM_TAG, new HtmlRendering());
33         htmlQuirks.put(FORM_TAG, new HtmlRendering());
34         xhtml.put(FORM_TAG, new XhtmlRendering());
35     }
36
37     public static class State extends AbstractHtmlState
38     {
39         public String JavaDoc name;
40         public String JavaDoc method;
41         public String JavaDoc action;
42
43         public void clear()
44         {
45             super.clear();
46
47             name = null;
48             method = null;
49             action = null;
50         }
51     }
52
53     public void doStartTag(AbstractRenderAppender sb, AbstractTagState renderState)
54     {
55         State state = (State) renderState;
56
57         renderTag(sb, FORM);
58         renderNameAndId(sb, state);
59         renderAttribute(sb, ACTION, state.action);
60         renderAttribute(sb, CLASS, state.styleClass);
61         renderAttribute(sb, METHOD, state.method);
62
63         renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
64         renderAttribute(sb, STYLE, state.style);
65         renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
66
67         sb.append(">");
68     }
69
70     public void doEndTag(AbstractRenderAppender sb)
71     {
72         renderEndTag(sb, FORM);
73     }
74
75     abstract void renderNameAndId(AbstractRenderAppender sb, State renderState);
76
77     private static class HtmlRendering extends FormTag
78     {
79         public void renderNameAndId(AbstractRenderAppender sb, State state)
80         {
81             renderAttribute(sb, NAME, state.name);
82             renderAttribute(sb, ID, state.id);
83         }
84     }
85
86     private static class XhtmlRendering extends FormTag
87     {
88         public void renderNameAndId(AbstractRenderAppender sb, State state)
89         {
90             renderAttribute(sb, ID, state.name);
91         }
92     }
93 }
94
Popular Tags