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: required, End tag: forbidden
027: * Required href
028: */
029: abstract public class InputImageTag extends TagHtmlBase implements
030: HtmlConstants {
031: public static void add(HashMap html, HashMap htmlQuirks,
032: HashMap xhtml) {
033: html.put(INPUT_IMAGE_TAG, new HtmlRendering());
034: htmlQuirks.put(INPUT_IMAGE_TAG, new HtmlRendering());
035: xhtml.put(INPUT_IMAGE_TAG, new XhtmlRendering());
036: }
037:
038: public static class State extends AbstractHtmlState {
039: public String src;
040: public String value;
041: public boolean disabled;
042:
043: public void clear() {
044: super .clear();
045: src = null;
046: value = null;
047: disabled = false;
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 InputImageTag.State";
056:
057: State state = (State) renderState;
058:
059: // Generate an HTML element
060: renderTag(sb, INPUT);
061: renderAttribute(sb, TYPE, INPUT_IMAGE);
062: renderAttribute(sb, ID, state.id);
063: renderAttribute(sb, CLASS, state.styleClass);
064: renderAttribute(sb, SRC, state.src);
065: renderAttribute(sb, VALUE, state.value);
066:
067: renderDisabled(sb, state.disabled);
068:
069: renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
070: renderAttribute(sb, STYLE, state.style);
071: renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
072:
073: writeEnd(sb);
074: }
075:
076: public void doEndTag(AbstractRenderAppender sb) {
077: }
078:
079: abstract protected void writeEnd(AbstractRenderAppender sb);
080:
081: abstract protected void renderDisabled(AbstractRenderAppender sb,
082: boolean disabled);
083:
084: private static class HtmlRendering extends InputImageTag {
085: protected void writeEnd(AbstractRenderAppender sb) {
086: sb.append(">");
087: }
088:
089: protected void renderDisabled(AbstractRenderAppender sb,
090: boolean disabled) {
091: if (disabled)
092: sb.append(" disabled");
093:
094: }
095:
096: }
097:
098: private static class XhtmlRendering extends InputImageTag {
099: protected void writeEnd(AbstractRenderAppender sb) {
100: sb.append(" />");
101: }
102:
103: protected void renderDisabled(AbstractRenderAppender sb,
104: boolean disabled) {
105: if (disabled)
106: renderAttribute(sb, "disabled", "disabled");
107: }
108: }
109: }
|