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 and HTML <input> element of either type checkbox or radio. In HTML 4.01 the start
027: * tag is required and the end tag is forbidden. There are no required attributes.
028: */
029: abstract public class InputBooleanTag extends TagHtmlBase implements
030: HtmlConstants {
031: public static void add(HashMap html, HashMap htmlQuirks,
032: HashMap xhtml) {
033: html.put(INPUT_BOOLEAN_TAG, new HtmlRendering());
034: htmlQuirks.put(INPUT_BOOLEAN_TAG, new HtmlRendering());
035: xhtml.put(INPUT_BOOLEAN_TAG, new XhtmlRendering());
036: }
037:
038: public static class State extends AbstractHtmlControlState {
039: public String type;
040: public boolean disabled;
041: public boolean checked;
042: public String value;
043:
044: public void clear() {
045: super .clear();
046:
047: type = null;
048: disabled = false;
049: checked = false;
050: value = null;
051: }
052: }
053:
054: public void doStartTag(AbstractRenderAppender sb,
055: AbstractTagState renderState) {
056: assert (sb != null) : "Parameter 'sb' must not be null";
057: assert (renderState != null) : "Parameter 'renderState' must not be null";
058: assert (renderState instanceof State) : "Paramater 'renderState' must be an instance of InputBooleanTag.State";
059:
060: State state = (State) renderState;
061:
062: // Generate an HTML input element
063: // Create an appropriate "input" element based on our parameters
064: renderTag(sb, INPUT);
065: renderAttribute(sb, TYPE, state.type);
066: renderAttribute(sb, NAME, state.name);
067: renderAttribute(sb, ID, state.id);
068: renderAttribute(sb, CLASS, state.styleClass);
069: renderAttribute(sb, VALUE, state.value);
070: renderDisabled(sb, state.disabled);
071: renderChecked(sb, state.checked);
072:
073: renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
074: renderAttribute(sb, STYLE, state.style);
075: renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
076: writeEnd(sb);
077: }
078:
079: public void doEndTag(AbstractRenderAppender sb) {
080: }
081:
082: abstract protected void writeEnd(AbstractRenderAppender sb);
083:
084: abstract protected void renderDisabled(AbstractRenderAppender sb,
085: boolean disabled);
086:
087: abstract protected void renderChecked(AbstractRenderAppender sb,
088: boolean checked);
089:
090: private static class HtmlRendering extends InputBooleanTag {
091: protected void writeEnd(AbstractRenderAppender sb) {
092: sb.append(">");
093: }
094:
095: protected void renderDisabled(AbstractRenderAppender sb,
096: boolean disabled) {
097: if (disabled)
098: sb.append(" " + DISABLED);
099:
100: }
101:
102: protected void renderChecked(AbstractRenderAppender sb,
103: boolean checked) {
104: if (checked)
105: sb.append(" " + CHECKED);
106:
107: }
108: }
109:
110: private static class XhtmlRendering extends InputBooleanTag {
111: protected void writeEnd(AbstractRenderAppender sb) {
112: sb.append(" />");
113: }
114:
115: protected void renderDisabled(AbstractRenderAppender sb,
116: boolean disabled) {
117: if (disabled)
118: renderAttribute(sb, DISABLED, DISABLED);
119: }
120:
121: protected void renderChecked(AbstractRenderAppender sb,
122: boolean checked) {
123: if (checked)
124: renderAttribute(sb, CHECKED, CHECKED);
125: }
126: }
127: }
|