001: /*
002: * Created on Feb 28, 2005
003: */
004: package com.sun.portal.wireless.htmlconversion.processors;
005:
006: import java.util.HashMap;
007:
008: import org.w3c.dom.Element;
009:
010: import com.sun.portal.wireless.htmlconversion.GenericHtmlParserCallback;
011: import com.sun.portal.wireless.htmlconversion.ParserState;
012:
013: /**
014: * Tag processor for the AmlInput tag.
015: *
016: * Note that this tag processor operates by delegation from
017: * HtmlInputTagProcessor.
018: *
019: * @author ashwin.mathew@sun.com
020: */
021: public class AmlInputTagProcessor extends BaseTagProcessor {
022:
023: public static final String AML_INPUT = "AmlInput";
024:
025: // AmlInput attributes
026: public static final String ATTR_NAME = "name";
027: public static final String ATTR_TYPE = "type";
028: public static final String ATTR_VALUE = "value";
029: public static final String ATTR_WIDTH = "width";
030: public static final String ATTR_MAXCHARS = "maxchars";
031: public static final String ATTR_VIEW = "view";
032:
033: public static final String VAL_TYPE_TEXT = "text";
034: public static final String VAL_TYPE_PASSWORD = "password";
035:
036: public static final String VAL_VIEW_SHOW = "show";
037: public static final String VAL_VIEW_HIDDEN = "hidden";
038: public static final String VAL_VIEW_NONE = "none";
039:
040: // Empty, since this tag processor operates by delegation
041: // from HtmlInputTagProcessor
042: private static final String[] supportedTags = {};
043:
044: /* (non-Javadoc)
045: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getAmlTag()
046: */
047: public String getAmlTag() {
048: return AML_INPUT;
049: }
050:
051: /* (non-Javadoc)
052: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getSupportedTags()
053: */
054: public String[] getSupportedTags() {
055: return supportedTags;
056: }
057:
058: /* (non-Javadoc)
059: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#canHaveChildren()
060: */
061: public boolean canHaveChildren(ParserState state) {
062: return false;
063: }
064:
065: /* (non-Javadoc)
066: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#startTag(java.lang.String, java.util.HashMap, com.sun.portal.wireless.htmlconversion.ParserState)
067: */
068: public Element startTag(String tagName, HashMap attributes,
069: ParserState state) {
070: Element amlInput = state.newElement(AML_INPUT);
071:
072: amlInput.setAttribute(ATTR_NAME, (String) attributes
073: .get(HtmlInputTagProcessor.ATTR_NAME));
074:
075: String amlView = null;
076:
077: String type = (String) attributes
078: .get(HtmlInputTagProcessor.ATTR_TYPE);
079: if (type != null) {
080: if (type.equals(HtmlInputTagProcessor.VAL_TYPE_PASSWORD)) {
081: amlInput.setAttribute(ATTR_TYPE, VAL_TYPE_PASSWORD);
082: } else if (type
083: .equals(HtmlInputTagProcessor.VAL_TYPE_HIDDEN)) {
084: amlView = VAL_VIEW_HIDDEN;
085: }
086: }
087:
088: if (amlView != null) {
089: amlInput.setAttribute(ATTR_VIEW, amlView);
090: }
091:
092: String value = (String) attributes
093: .get(HtmlInputTagProcessor.ATTR_VALUE);
094: if (value != null) {
095: amlInput.setAttribute(ATTR_VALUE, value);
096: }
097:
098: String size = (String) attributes
099: .get(HtmlInputTagProcessor.ATTR_SIZE);
100: if (size != null) {
101: amlInput.setAttribute(ATTR_WIDTH, size);
102: }
103:
104: String maxlength = (String) attributes
105: .get(HtmlInputTagProcessor.ATTR_MAXLENGTH);
106: if (maxlength != null) {
107: amlInput.setAttribute(ATTR_MAXCHARS, maxlength);
108: }
109:
110: // Special case: if the input tag is set to readonly or disabled, then
111: // output an AmlText with the value (since AmlInput does not support
112: // readonly or disabled itself) and hide the AmlInput (so that it's
113: // value is still returned on form submission)
114: if (attributes.keySet().contains(
115: HtmlInputTagProcessor.ATTR_READONLY)
116: || attributes.keySet().contains(
117: HtmlInputTagProcessor.ATTR_DISABLED)) {
118: Element amlText = AmlTextTagProcessor.createAmlTextElement(
119: value, state);
120: GenericHtmlParserCallback.appendChildToOutputContainer(
121: state, amlText);
122:
123: amlInput.setAttribute(ATTR_VIEW, VAL_VIEW_HIDDEN);
124: }
125:
126: return amlInput;
127: }
128:
129: }
|