KickJava   Java API By Example, From Geeks To Geeks.

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


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 public abstract class ScriptTag extends TagHtmlBase
25 {
26     public static void add(HashMap JavaDoc html, HashMap JavaDoc htmlQuirks, HashMap JavaDoc xhtml)
27     {
28         html.put(SCRIPT_TAG, new ScriptTag.Rendering());
29         htmlQuirks.put(SCRIPT_TAG, new ScriptTag.Rendering());
30         xhtml.put(SCRIPT_TAG, new ScriptTag.Rendering());
31     }
32
33     public static class State extends AbstractAttributeState
34     {
35         public String JavaDoc type;
36         public String JavaDoc src;
37         public String JavaDoc language;
38         public boolean suppressComments = true;
39
40         public void clear()
41         {
42             super.clear();
43             type = null;
44             src = null;
45             language = null;
46             suppressComments = true;
47         }
48     }
49
50     public abstract void doEndTag(AbstractRenderAppender sb, boolean supressComments);
51
52     private static class Rendering extends ScriptTag implements HtmlConstants
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 SpanTag.State";
59
60             State state = (State) renderState;
61
62             renderTag(sb, SCRIPT);
63
64             if (state.language == null) {
65                 // @todo: this should be all lower case!
66
state.language = "JavaScript";
67             }
68             if (state.type == null) {
69                 // @todo: this should be all lower case!
70
state.type = "text/JavaScript";
71             }
72
73             renderAttribute(sb, LANGUAGE, state.language);
74             renderAttribute(sb, TYPE, state.type);
75             renderAttribute(sb, SRC, state.src);
76
77             renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
78             sb.append(">");
79
80             // for javascript will will continue put the script itself into html comments
81
if (!state.suppressComments)
82                 sb.append("\n<!--\n");
83         }
84
85         public void doEndTag(AbstractRenderAppender sb, boolean supressComments)
86         {
87             if (!supressComments)
88                 sb.append("-->\n");
89             doEndTag(sb);
90         }
91
92         public void doEndTag(AbstractRenderAppender sb)
93         {
94             renderEndTag(sb, SCRIPT);
95         }
96     }
97 }
98
Popular Tags