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: /**
26: * Render the HTML <base> tag. This is the document base URI.
27: * In HTML 4.01 the start tag is required and the end tag forbidden.
28: * The tag will be rendered as a single tag. The href attribute is required in HTML 4.01 and optional
29: * in XHTML.
30: */
31: public abstract class BaseTag extends TagHtmlBase implements
32: HtmlConstants {
33: public static void add(HashMap html, HashMap htmlQuirks,
34: HashMap xhtml) {
35: html.put(BASE_TAG, new HtmlRendering());
36: htmlQuirks.put(BASE_TAG, new HtmlRendering());
37: xhtml.put(BASE_TAG, new XhtmlRendering());
38: }
39:
40: public static class State extends AbstractAttributeState {
41: public String target;
42: public String href;
43:
44: public void clear() {
45: super .clear();
46:
47: target = null;
48: href = null;
49: }
50: }
51:
52: public void doStartTag(AbstractRenderAppender sb,
53: AbstractTagState renderState) {
54: assert (sb != null) : "Parameter 'sb' must not be null";
55: assert (renderState != null) : "Parameter 'renderState' must not be null";
56: assert (renderState instanceof BaseTag.State) : "Paramater 'renderState' must be an instance of Base.State";
57:
58: State state = (State) renderState;
59:
60: renderTag(sb, BASE);
61: renderAttribute(sb, HREF, state.href);
62: renderAttribute(sb, TARGET, state.target);
63:
64: // These are not actually used by the <base> tag, but may be set by external sources.
65: renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
66: writeEnd(sb);
67: }
68:
69: public void doEndTag(AbstractRenderAppender sb) {
70: // do nothing...
71: }
72:
73: abstract protected void writeEnd(AbstractRenderAppender sb);
74:
75: private static class HtmlRendering extends BaseTag {
76: protected void writeEnd(AbstractRenderAppender sb) {
77: sb.append(">");
78: }
79: }
80:
81: private static class XhtmlRendering extends BaseTag {
82: protected void writeEnd(AbstractRenderAppender sb) {
83: sb.append(" />");
84: }
85: }
86: }
|