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.ParserState;
011:
012: /**
013: * Tag processor for AmlForm
014: *
015: * @author ashwin.mathew@sun.com
016: */
017: public class AmlFormTagProcessor extends BaseTagProcessor {
018:
019: public static final String AML_FORM = "AmlForm";
020:
021: private static final String[] supportedTags = { "form" };
022:
023: // Attributes for AmlForm
024: public static final String ATTR_URL = "url";
025: public static final String ATTR_METHOD = "method";
026: public static final String ATTR_SUBMIT_LABEL = "submit_label";
027: public static final String ATTR_RESET = "reset";
028: public static final String ATTR_RESET_LABEL = "reset_label";
029:
030: public static final String VAL_METHOD_GET = "get";
031: public static final String VAL_METHOD_POST = "post";
032:
033: public static final String VAL_RESET_TRUE = "true";
034:
035: // Attributes on Form tag
036: public static final String FORM_ATTR_ACTION = "action";
037: public static final String FORM_ATTR_METHOD = "method";
038:
039: // List of AML elements that require a AmlForm in
040: // their parent hierarchy
041: private static final String[] elementsRequireForm = new String[4];
042: static {
043: elementsRequireForm[0] = AmlInputTagProcessor.AML_INPUT;
044: elementsRequireForm[1] = AmlChoiceTagProcessor.AML_CHOICE;
045: elementsRequireForm[2] = AmlTextAreaTagProcessor.AML_TEXT_AREA;
046: elementsRequireForm[3] = AmlCheckBoxTagProcessor.AML_CHECKBOX;
047: }
048:
049: /* (non-Javadoc)
050: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getAmlTag()
051: */
052: public String getAmlTag() {
053: return AML_FORM;
054: }
055:
056: /* (non-Javadoc)
057: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getSupportedTags()
058: */
059: public String[] getSupportedTags() {
060: return supportedTags;
061: }
062:
063: /* (non-Javadoc)
064: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#canHaveChildren()
065: */
066: public boolean canHaveChildren(ParserState state) {
067: return true;
068: }
069:
070: /* (non-Javadoc)
071: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#startTag(java.lang.String, java.util.HashMap, com.sun.portal.wireless.htmlconversion.ParserState)
072: */
073: public Element startTag(String tagName, HashMap attributes,
074: ParserState state) {
075: Element amlForm = state.newElement(AML_FORM);
076:
077: String url = AmlLinkTagProcessor.rewriteUrl((String) attributes
078: .get(FORM_ATTR_ACTION), state);
079: amlForm.setAttribute(ATTR_URL, url);
080:
081: String method = (String) attributes.get(FORM_ATTR_METHOD);
082: if (method != null) {
083: amlForm.setAttribute(ATTR_METHOD, method);
084: }
085:
086: state.getLayoutManager().registerAmlFormTag(amlForm);
087:
088: state.startedAmlForm();
089:
090: return amlForm;
091: }
092:
093: /* (non-Javadoc)
094: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#endTag(java.lang.String, com.sun.portal.wireless.htmlconversion.ParserState)
095: */
096: public Element endTag(String tag, ParserState state) {
097: state.endedAmlForm();
098:
099: return super .endTag(tag, state);
100: }
101:
102: /**
103: * Indicates whether or not the specified tag requires an AmlForm
104: * in it's parent tag hierarchy.
105: *
106: * @param tagName
107: * @return
108: */
109: public static boolean doesElementRequireForm(String tagName) {
110: boolean requiresForm = false;
111:
112: for (int i = 0; i < elementsRequireForm.length; i++) {
113: if (tagName.equals(elementsRequireForm[i])) {
114: requiresForm = true;
115: break;
116: }
117: }
118:
119: return requiresForm;
120: }
121:
122: }
|