001: /*
002: * Created on Mar 2, 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.ParserState;
011:
012: /**
013: * Tag processor for HTML Button tags - this sets the AmlForm
014: * submit_label, reset flag and reset_label.
015: *
016: * Note that the JDK HTML parser being used considers buttons to
017: * be "simple" tags (tags with no body), and therefore does not
018: * invoke endTag() for button - resulting in a failure of this
019: * tag processor. There is no workaround at this time. This should
020: * work properly under XHTML.
021: *
022: * @author ashwin.mathew@sun.com
023: */
024: public class HtmlButtonTagProcessor extends BaseTagProcessor {
025:
026: // Attributes for HTML Button
027: public static final String BUTTON_ATTR_TYPE = "type";
028: public static final String BUTTON_ATTR_DISABLED = "disabled";
029:
030: // Values for type attribute
031: public static final String BUTTON_VAL_TYPE_BUTTON = "button";
032: public static final String BUTTON_VAL_TYPE_SUBMIT = "submit";
033: public static final String BUTTON_VAL_TYPE_RESET = "reset";
034:
035: // Constant name used to store the button type on ParserState
036: private static final String STATE_BUTTON_TYPE = "HtmlButtonType";
037:
038: private static final String[] supportedTags = { "button" };
039:
040: /* (non-Javadoc)
041: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getAmlTag()
042: */
043: public String getAmlTag() {
044: // Return null - this has no AML tag
045: return null;
046: }
047:
048: /* (non-Javadoc)
049: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getSupportedTags()
050: */
051: public String[] getSupportedTags() {
052: return supportedTags;
053: }
054:
055: /* (non-Javadoc)
056: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#canHaveChildren(com.sun.portal.wireless.htmlconversion.ParserState)
057: */
058: public boolean canHaveChildren(ParserState state) {
059: return false;
060: }
061:
062: /* (non-Javadoc)
063: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#startTag(java.lang.String, java.util.HashMap, com.sun.portal.wireless.htmlconversion.ParserState)
064: */
065: public Element startTag(String tagName, HashMap attributes,
066: ParserState state) {
067: // We're only interested in non-disabled submit or reset buttons
068: String type = (String) attributes.get(BUTTON_ATTR_TYPE);
069: if (type != null
070: && !type.equals(BUTTON_VAL_TYPE_BUTTON)
071: && !(attributes.keySet().contains(BUTTON_ATTR_DISABLED))) {
072: state.setProcessorAttribute(STATE_BUTTON_TYPE, type);
073: }
074:
075: return null;
076: }
077:
078: /* (non-Javadoc)
079: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#endTag(java.lang.String, com.sun.portal.wireless.htmlconversion.ParserState)
080: */
081: public Element endTag(String tag, ParserState state) {
082: String type = (String) state
083: .getProcessorAttribute(STATE_BUTTON_TYPE);
084:
085: String labelText = null;
086: if (state.isTextAvailable()) {
087: labelText = state.getText();
088: state.clearText();
089: }
090:
091: if (type == null) {
092: // This is going to happen for button tags of type "button",
093: // which are unsupported
094: return null;
095: }
096:
097: if (type.equals(BUTTON_VAL_TYPE_SUBMIT)) {
098: AmlFormSubmitTagProcessor.setFormSubmitAttribute(labelText,
099: state);
100: } else if (type.equals(BUTTON_VAL_TYPE_RESET)) {
101: AmlFormResetTagProcessor.setFormResetAttribute(labelText,
102: state);
103: }
104:
105: return null;
106: }
107:
108: }
|