001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags.rendering;
020:
021: import org.apache.beehive.netui.tags.html.HtmlConstants;
022:
023: import java.util.HashMap;
024:
025: /**
026: * Render the HTML <form> element. In HTML 4.01 both the start and end tag are rquired.
027: * The action is a required attribute.
028: */
029: abstract public class HtmlTag extends TagHtmlBase implements
030: HtmlConstants {
031: public static void add(HashMap html, HashMap htmlQuirks,
032: HashMap xhtml) {
033: html.put(HTML_TAG, new HtmlTag.HtmlRendering());
034: htmlQuirks.put(HTML_TAG, new HtmlTag.HtmlQuirksRendering());
035: xhtml.put(HTML_TAG, new HtmlTag.XhtmlRendering());
036: }
037:
038: public static class State extends AbstractAttributeState {
039: public String lang;
040: public String dir;
041:
042: public void clear() {
043: super .clear();
044:
045: lang = null;
046: dir = null;
047: }
048: }
049:
050: public void doStartTag(AbstractRenderAppender sb,
051: AbstractTagState renderState) {
052: State state = (State) renderState;
053:
054: renderDocType(sb);
055: sb.append("\n");
056: renderTag(sb, HTML);
057: renderAttribute(sb, LANG, state.lang);
058: renderAttribute(sb, DIR, state.dir);
059: renderAdditionalAttributes(sb, state);
060: renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
061:
062: sb.append(">");
063: }
064:
065: public void doEndTag(AbstractRenderAppender sb) {
066: renderEndTag(sb, HTML);
067: }
068:
069: abstract protected void renderAdditionalAttributes(
070: AbstractRenderAppender sb, State renderState);
071:
072: abstract protected void renderDocType(AbstractRenderAppender sb);
073:
074: private static class HtmlRendering extends HtmlTag {
075: protected void renderDocType(AbstractRenderAppender sb) {
076: sb
077: .append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n\t\"http://www.w3.org/TR/html4/loose.dtd\">");
078: }
079:
080: protected void renderAdditionalAttributes(
081: AbstractRenderAppender sb, State renderState) {
082: }
083: }
084:
085: private static class HtmlQuirksRendering extends HtmlTag {
086: protected void renderDocType(AbstractRenderAppender sb) {
087: sb
088: .append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n>");
089: }
090:
091: protected void renderAdditionalAttributes(
092: AbstractRenderAppender sb, State renderState) {
093: }
094: }
095:
096: private static class XhtmlRendering extends HtmlTag {
097: protected void renderDocType(AbstractRenderAppender sb) {
098: sb
099: .append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
100: }
101:
102: protected void renderAdditionalAttributes(
103: AbstractRenderAppender sb, State renderState) {
104: renderAttribute(sb, "xml:lang", renderState.lang);
105: renderAttribute(sb, "xmlns", "http://www.w3.org/1999/xhtml");
106: }
107: }
108: }
|