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