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 InputSubmitTag extends TagHtmlBase implements
030: HtmlConstants {
031: public static void add(HashMap html, HashMap htmlQuirks,
032: HashMap xhtml) {
033: html.put(INPUT_SUBMIT_TAG, new HtmlRendering());
034: htmlQuirks.put(INPUT_SUBMIT_TAG, new HtmlRendering());
035: xhtml.put(INPUT_SUBMIT_TAG, new XhtmlRendering());
036: }
037:
038: public static class State extends AbstractHtmlControlState {
039: public String type;
040: public boolean disabled;
041: public String value;
042:
043: public void clear() {
044: super .clear();
045:
046: type = null;
047: disabled = false;
048: value = null;
049: }
050: }
051:
052: public void doStartTag(AbstractRenderAppender sb,
053: AbstractTagState renderState) {
054: assert (sb != null) : "Parameter 'sb' must not be null";
055: assert (renderState != null) : "Parameter 'renderState' must not be null";
056: assert (renderState instanceof State) : "Paramater 'renderState' must be an instance of InputSubmitTag.State";
057:
058: State state = (State) renderState;
059:
060: // Generate an HTML element
061: renderTag(sb, INPUT);
062: if (state.type == null)
063: state.type = INPUT_SUBMIT;
064: renderAttribute(sb, TYPE, state.type);
065: renderAttribute(sb, NAME, state.name);
066: renderAttribute(sb, ID, state.id);
067: renderAttribute(sb, CLASS, state.styleClass);
068: renderAttribute(sb, VALUE, state.value);
069:
070: renderDisabled(sb, state.disabled);
071:
072: renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
073: renderAttribute(sb, STYLE, state.style);
074: renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
075: writeEnd(sb);
076: }
077:
078: public void doEndTag(AbstractRenderAppender sb) {
079: }
080:
081: abstract protected void writeEnd(AbstractRenderAppender sb);
082:
083: abstract protected void renderDisabled(AbstractRenderAppender sb,
084: boolean disabled);
085:
086: private static class HtmlRendering extends InputSubmitTag {
087: protected void writeEnd(AbstractRenderAppender sb) {
088: sb.append(">");
089: }
090:
091: protected void renderDisabled(AbstractRenderAppender sb,
092: boolean disabled) {
093: if (disabled)
094: sb.append(" disabled");
095:
096: }
097:
098: }
099:
100: private static class XhtmlRendering extends InputSubmitTag {
101: protected void writeEnd(AbstractRenderAppender sb) {
102: sb.append(" />");
103: }
104:
105: protected void renderDisabled(AbstractRenderAppender sb,
106: boolean disabled) {
107: if (disabled)
108: renderAttribute(sb, "disabled", "disabled");
109: }
110: }
111: }
|