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: * Body, Start Tag: optional, End tag: optional
027: * Required href
028: */
029: public abstract class SelectTag extends TagHtmlBase implements
030: HtmlConstants {
031: public static void add(HashMap html, HashMap htmlQuirks,
032: HashMap xhtml) {
033: html.put(SELECT_TAG, new HtmlRendering());
034: htmlQuirks.put(SELECT_TAG, new HtmlRendering());
035: xhtml.put(SELECT_TAG, new XhtmlRendering());
036: }
037:
038: public static class State extends AbstractHtmlControlState {
039: public boolean disabled;
040: public boolean multiple;
041: public int size;
042:
043: public void clear() {
044: super .clear();
045: disabled = false;
046: multiple = false;
047: size = 0;
048: }
049: }
050:
051: public void doStartTag(AbstractRenderAppender sb,
052: AbstractTagState renderState) {
053: assert (sb != null) : "Parameter 'sb' must not be null";
054: assert (renderState != null) : "Parameter 'renderState' must not be null";
055: assert (renderState instanceof State) : "Paramater 'renderState' must be an instance of SelectTag.State";
056:
057: State state = (State) renderState;
058:
059: renderTag(sb, SELECT);
060: renderAttribute(sb, NAME, state.name);
061: renderAttribute(sb, ID, state.id);
062: renderAttribute(sb, CLASS, state.styleClass);
063: renderMultiple(sb, state.multiple);
064: renderDisabled(sb, state.disabled);
065: if (state.size > 0)
066: renderAttribute(sb, SIZE, Integer.toString(state.size));
067:
068: renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
069: renderAttribute(sb, STYLE, state.style);
070: renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
071: sb.append(">");
072: }
073:
074: public void doEndTag(AbstractRenderAppender sb) {
075: renderEndTag(sb, SELECT);
076: }
077:
078: abstract protected void renderDisabled(AbstractRenderAppender sb,
079: boolean disabled);
080:
081: abstract protected void renderMultiple(AbstractRenderAppender sb,
082: boolean readonly);
083:
084: private static class HtmlRendering extends SelectTag {
085: protected void renderDisabled(AbstractRenderAppender sb,
086: boolean disabled) {
087: if (disabled)
088: sb.append(" disabled");
089:
090: }
091:
092: protected void renderMultiple(AbstractRenderAppender sb,
093: boolean multiple) {
094: if (multiple)
095: sb.append(" multiple");
096:
097: }
098: }
099:
100: private static class XhtmlRendering extends SelectTag {
101: protected void renderDisabled(AbstractRenderAppender sb,
102: boolean disabled) {
103: if (disabled)
104: renderAttribute(sb, "disabled", "disabled");
105:
106: }
107:
108: protected void renderMultiple(AbstractRenderAppender sb,
109: boolean multiple) {
110: if (multiple)
111: renderAttribute(sb, "multiple", "multiple");
112:
113: }
114: }
115: }
|