001: /*
002: * Created on Mar 1, 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 AmlCheckBox element
015: *
016: * @author ashwin.mathew@sun.com
017: */
018: public class AmlCheckBoxTagProcessor extends BaseTagProcessor {
019:
020: public static final String AML_CHECKBOX = "AmlCheckBox";
021:
022: public static final String ATTR_NAME = "name";
023: public static final String ATTR_SELECTED = "selected";
024: public static final String ATTR_VALUE = "value";
025: public static final String ATTR_VIEW = "view";
026:
027: public static final String VAL_SELECTED_TRUE = "true";
028: public static final String VAL_SELECTED_FALSE = "false";
029:
030: public static final String VAL_VIEW_SHOW = "show";
031: public static final String VAL_VIEW_HIDDEN = "hidden";
032: public static final String VAL_VIEW_NONE = "none";
033:
034: // No mapping to HTML tags, since this operates by delegation
035: // from HtmlInputTagProcessor
036: private static final String[] supportedTags = {};
037:
038: /* (non-Javadoc)
039: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getAmlTag()
040: */
041: public String getAmlTag() {
042: return AML_CHECKBOX;
043: }
044:
045: /* (non-Javadoc)
046: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getSupportedTags()
047: */
048: public String[] getSupportedTags() {
049: return supportedTags;
050: }
051:
052: /* (non-Javadoc)
053: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#canHaveChildren(com.sun.portal.wireless.htmlconversion.ParserState)
054: */
055: public boolean canHaveChildren(ParserState state) {
056: return false;
057: }
058:
059: /* (non-Javadoc)
060: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#startTag(java.lang.String, java.util.HashMap, com.sun.portal.wireless.htmlconversion.ParserState)
061: */
062: public Element startTag(String tagName, HashMap attributes,
063: ParserState state) {
064: Element amlCheckBox = state.newElement(AML_CHECKBOX);
065:
066: amlCheckBox.setAttribute(ATTR_NAME, (String) attributes
067: .get(HtmlInputTagProcessor.ATTR_NAME));
068:
069: String checked = (String) attributes
070: .get(HtmlInputTagProcessor.ATTR_CHECKED);
071: if (checked != null
072: && checked
073: .equals(HtmlInputTagProcessor.VAL_CHECKED_TRUE)) {
074: amlCheckBox.setAttribute(ATTR_SELECTED, VAL_SELECTED_TRUE);
075: }
076:
077: String value = (String) attributes
078: .get(HtmlInputTagProcessor.ATTR_VALUE);
079: if (value != null) {
080: amlCheckBox.setAttribute(ATTR_VALUE, value);
081: }
082:
083: // Special case: if the input tag is set to readonly or disabled, then
084: // output an AmlText with the value (since AmlCheckBox does not support
085: // readonly or disabled itself) and hide the AmlCheckBox (so that it's
086: // value is still returned on form submission). This may have to be
087: // reworked to support i18n on the output "true" and "false" strings.
088: if (attributes.keySet().contains(
089: HtmlInputTagProcessor.ATTR_DISABLED)) {
090: String selectedStr = VAL_SELECTED_TRUE;
091: if (checked == null
092: || checked
093: .equals(HtmlInputTagProcessor.VAL_CHECKED_FALSE)) {
094: selectedStr = VAL_SELECTED_FALSE;
095: }
096:
097: Element amlText = AmlTextTagProcessor.createAmlTextElement(
098: selectedStr, state);
099:
100: GenericHtmlParserCallback.appendChildToOutputContainer(
101: state, amlText);
102:
103: amlCheckBox.setAttribute(ATTR_VIEW, VAL_VIEW_HIDDEN);
104: }
105:
106: return amlCheckBox;
107: }
108: }
|