KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Render the HTML <base> tag. This is the document base URI.
26  * In HTML 4.01 the start tag is required and the end tag forbidden.
27  * The tag will be rendered as a single tag. The href attribute is required in HTML 4.01 and optional
28  * in XHTML.
29  */

30 public abstract class BaseTag extends TagHtmlBase implements HtmlConstants
31 {
32     public static void add(HashMap JavaDoc html, HashMap JavaDoc htmlQuirks, HashMap JavaDoc xhtml)
33     {
34         html.put(BASE_TAG, new HtmlRendering());
35         htmlQuirks.put(BASE_TAG, new HtmlRendering());
36         xhtml.put(BASE_TAG, new XhtmlRendering());
37     }
38
39     public static class State extends AbstractAttributeState
40     {
41         public String JavaDoc target;
42         public String JavaDoc href;
43
44         public void clear()
45         {
46             super.clear();
47
48             target = null;
49             href = 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 BaseTag.State) : "Paramater 'renderState' must be an instance of Base.State";
58
59         State state = (State) renderState;
60
61         renderTag(sb, BASE);
62         renderAttribute(sb, HREF, state.href);
63         renderAttribute(sb, TARGET, state.target);
64
65         // These are not actually used by the <base> tag, but may be set by external sources.
66
renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
67         writeEnd(sb);
68     }
69
70     public void doEndTag(AbstractRenderAppender sb)
71     {
72         // do nothing...
73
}
74
75     abstract protected void writeEnd(AbstractRenderAppender sb);
76
77
78     private static class HtmlRendering extends BaseTag
79     {
80         protected void writeEnd(AbstractRenderAppender sb)
81         {
82             sb.append(">");
83         }
84     }
85
86     private static class XhtmlRendering extends BaseTag
87     {
88         protected void writeEnd(AbstractRenderAppender sb)
89         {
90             sb.append(" />");
91         }
92     }
93 }
94
Popular Tags