KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Rendering for HTML anchor tags $lt;a>. In HTML 4.01 the start and end tags are both required.
26  * There are no required attributes.
27  */

28 abstract public class AnchorTag extends TagHtmlBase implements HtmlConstants
29 {
30     /**
31      * Add the Renderer for the HTML and XHTML tokens.
32      * @param html The map of HTML Tag Renderers
33      * @param xhtml The map of XHTML Tag Renderers
34      */

35     public static void add(HashMap JavaDoc html, HashMap JavaDoc htmlQuirks, HashMap JavaDoc xhtml)
36     {
37         html.put(ANCHOR_TAG, new Rendering());
38         htmlQuirks.put(ANCHOR_TAG, new Rendering());
39         xhtml.put(ANCHOR_TAG, new Rendering());
40     }
41
42     /**
43      * The State assocated with the Anchor Tag.
44      */

45     public static class State extends AbstractHtmlState
46     {
47         public String JavaDoc name;
48         public String JavaDoc href;
49
50         public void clear()
51         {
52             super.clear();
53
54             name = null;
55             href = null;
56         }
57     }
58
59     /**
60      * Private class implementation of of the Anchor Tag.
61      */

62     private static class Rendering extends AnchorTag
63     {
64         public void doStartTag(AbstractRenderAppender sb, AbstractTagState renderState)
65         {
66             assert(sb != null) : "Parameter 'sb' must not be null";
67             assert(renderState != null) : "Parameter 'renderState' must not be null";
68             assert(renderState instanceof State) : "Paramater 'renderState' must be an instance of AnchorTag.State";
69
70             // convert to AnchorTag.State
71
State state = (State) renderState;
72
73             renderTag(sb, ANCHOR);
74             renderAttribute(sb, ID, state.id);
75             renderAttribute(sb, NAME, state.name);
76             renderAttribute(sb, HREF, state.href);
77
78             renderAttribute(sb, CLASS, state.styleClass);
79             renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
80             renderAttribute(sb, STYLE, state.style);
81
82             renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
83             sb.append(">");
84         }
85
86         public void doEndTag(AbstractRenderAppender sb)
87         {
88             renderEndTag(sb, ANCHOR);
89         }
90     }
91 }
92
Popular Tags