KickJava   Java API By Example, From Geeks To Geeks.

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


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 <img> element. In HTML 4.01, the start tag is required and end tag forbidden.
26  * The attributes src and alt are both required.
27  */

28 abstract public class ImageTag extends TagHtmlBase implements HtmlConstants
29 {
30     public static void add(HashMap JavaDoc html, HashMap JavaDoc htmlQuirks, HashMap JavaDoc xhtml)
31     {
32         html.put(IMAGE_TAG, new HtmlRendering());
33         htmlQuirks.put(IMAGE_TAG, new HtmlRendering());
34         xhtml.put(IMAGE_TAG, new XhtmlRendering());
35     }
36
37     public static class State extends AbstractHtmlState
38     {
39         public String JavaDoc src;
40
41         public void clear()
42         {
43             super.clear();
44
45             src = null;
46         }
47     }
48
49     public void doStartTag(AbstractRenderAppender sb, AbstractTagState renderState)
50     {
51         assert(sb != null) : "Parameter 'sb' must not be null";
52         assert(renderState != null) : "Parameter 'renderState' must not be null";
53         assert(renderState instanceof State) : "Paramater 'renderState' must be an instance of ImageTag.State";
54
55         State state = (State) renderState;
56
57         renderTag(sb, IMAGE);
58         renderAttribute(sb, SRC, state.src);
59         renderAttribute(sb, ID, state.id);
60
61         renderAttribute(sb, STYLE, state.style);
62         renderAttribute(sb, CLASS, state.styleClass);
63         renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
64         renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
65
66         writeEnd(sb);
67     }
68
69     public void doEndTag(AbstractRenderAppender sb)
70     {
71     }
72
73     abstract protected void writeEnd(AbstractRenderAppender sb);
74
75     private static class HtmlRendering extends ImageTag
76     {
77         protected void writeEnd(AbstractRenderAppender sb)
78         {
79             sb.append(">");
80         }
81     }
82
83     private static class XhtmlRendering extends ImageTag
84     {
85         protected void writeEnd(AbstractRenderAppender sb)
86         {
87             sb.append(" />");
88         }
89     }
90 }
91
Popular Tags