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 InputTextTag extends TagHtmlBase implements
030: HtmlConstants {
031: public static void add(HashMap html, HashMap htmlQuirks,
032: HashMap xhtml) {
033: html.put(INPUT_TEXT_TAG, new HtmlRendering());
034: htmlQuirks.put(INPUT_TEXT_TAG, new HtmlRendering());
035: xhtml.put(INPUT_TEXT_TAG, new XhtmlRendering());
036: }
037:
038: public static class State extends AbstractHtmlControlState {
039: public String type;
040: public boolean disabled;
041: public int maxlength;
042: public int size;
043: public String value;
044: public boolean readonly;
045:
046: public void clear() {
047: super .clear();
048:
049: type = null;
050: disabled = false;
051: maxlength = 0;
052: size = 0;
053: value = null;
054: readonly = false;
055: }
056: }
057:
058: public void doStartTag(AbstractRenderAppender sb,
059: AbstractTagState renderState) {
060: assert (sb != null) : "Parameter 'sb' must not be null";
061: assert (renderState != null) : "Parameter 'renderState' must not be null";
062: assert (renderState instanceof State) : "Paramater 'renderState' must be an instance of AnchorTag.State";
063:
064: State state = (State) renderState;
065:
066: // Generate an HTML element
067: renderTag(sb, INPUT);
068: if (state.type == null)
069: state.type = INPUT_TEXT;
070:
071: renderAttribute(sb, TYPE, state.type);
072: renderAttribute(sb, NAME, state.name);
073: renderAttribute(sb, ID, state.id);
074: renderAttribute(sb, CLASS, state.styleClass);
075: renderAttribute(sb, VALUE, state.value);
076:
077: if (state.maxlength > 0)
078: renderAttribute(sb, MAXLENGTH, Integer
079: .toString(state.maxlength));
080: if (state.size > 0)
081: renderAttribute(sb, SIZE, Integer.toString(state.size));
082: renderDisabled(sb, state.disabled);
083: renderReadonly(sb, state.readonly);
084:
085: renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
086: renderAttribute(sb, STYLE, state.style);
087: renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
088: writeEnd(sb);
089: }
090:
091: public void doEndTag(AbstractRenderAppender sb) {
092: }
093:
094: abstract protected void writeEnd(AbstractRenderAppender sb);
095:
096: abstract protected void renderDisabled(AbstractRenderAppender sb,
097: boolean disabled);
098:
099: abstract protected void renderReadonly(AbstractRenderAppender sb,
100: boolean readonly);
101:
102: private static class HtmlRendering extends InputTextTag {
103: protected void writeEnd(AbstractRenderAppender sb) {
104: sb.append(">");
105: }
106:
107: protected void renderDisabled(AbstractRenderAppender sb,
108: boolean disabled) {
109: if (disabled)
110: sb.append(" disabled");
111: }
112:
113: protected void renderReadonly(AbstractRenderAppender sb,
114: boolean readonly) {
115: if (readonly)
116: sb.append(" readonly");
117: }
118: }
119:
120: private static class XhtmlRendering extends InputTextTag {
121: protected void writeEnd(AbstractRenderAppender sb) {
122: sb.append(" />");
123: }
124:
125: protected void renderDisabled(AbstractRenderAppender sb,
126: boolean disabled) {
127: if (disabled)
128: renderAttribute(sb, "disabled", "disabled");
129: }
130:
131: protected void renderReadonly(AbstractRenderAppender sb,
132: boolean readonly) {
133: if (readonly)
134: renderAttribute(sb, "readonly", "readonly");
135: }
136:
137: }
138: }
|