01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.tags.rendering;
20:
21: import org.apache.beehive.netui.tags.html.HtmlConstants;
22:
23: import java.util.HashMap;
24:
25: public abstract class ScriptTag extends TagHtmlBase {
26: public static void add(HashMap html, HashMap htmlQuirks,
27: HashMap xhtml) {
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: public String type;
35: public String src;
36: public String language;
37: public boolean suppressComments = true;
38:
39: public void clear() {
40: super .clear();
41: type = null;
42: src = null;
43: language = null;
44: suppressComments = true;
45: }
46: }
47:
48: public abstract void doEndTag(AbstractRenderAppender sb,
49: boolean supressComments);
50:
51: private static class Rendering extends ScriptTag implements
52: HtmlConstants {
53: public void doStartTag(AbstractRenderAppender sb,
54: AbstractTagState renderState) {
55: assert (sb != null) : "Parameter 'sb' must not be null";
56: assert (renderState != null) : "Parameter 'renderState' must not be null";
57: assert (renderState instanceof State) : "Paramater 'renderState' must be an instance of SpanTag.State";
58:
59: State state = (State) renderState;
60:
61: renderTag(sb, SCRIPT);
62:
63: if (state.language == null) {
64: // @todo: this should be all lower case!
65: state.language = "JavaScript";
66: }
67: if (state.type == null) {
68: // @todo: this should be all lower case!
69: state.type = "text/JavaScript";
70: }
71:
72: renderAttribute(sb, LANGUAGE, state.language);
73: renderAttribute(sb, TYPE, state.type);
74: renderAttribute(sb, SRC, state.src);
75:
76: renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
77: sb.append(">");
78:
79: // for javascript will will continue put the script itself into html comments
80: if (!state.suppressComments)
81: sb.append("\n<!--\n");
82: }
83:
84: public void doEndTag(AbstractRenderAppender sb,
85: boolean supressComments) {
86: if (!supressComments)
87: sb.append("-->\n");
88: doEndTag(sb);
89: }
90:
91: public void doEndTag(AbstractRenderAppender sb) {
92: renderEndTag(sb, SCRIPT);
93: }
94: }
95: }
|