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 the AmlTextArea tag.
014: *
015: * @author ashwin.mathew@sun.com
016: */
017: public class AmlTextAreaTagProcessor extends BaseTagProcessor {
018:
019: public static final String AML_TEXT_AREA = "AmlTextArea";
020:
021: // Attributes for the AmlTextArea tag
022: public static final String ATTR_NAME = "name";
023: public static final String ATTR_HEIGHT = "height";
024: public static final String ATTR_WIDTH = "width";
025: public static final String ATTR_VALUE = "value";
026: public static final String ATTR_VIEW = "view";
027:
028: // Values for the view attribute
029: public static final String VAL_VIEW_SHOW = "show";
030: public static final String VAL_VIEW_HIDDEN = "hidden";
031: public static final String VAL_VIEW_NONE = "none";
032:
033: // Attributes for the HTML textarea tag
034: public static final String TEXTAREA_ATTR_NAME = "name";
035: public static final String TEXTAREA_ATTR_ROWS = "rows";
036: public static final String TEXTAREA_ATTR_COLS = "cols";
037: public static final String TEXTAREA_ATTR_DISABLED = "disabled";
038: public static final String TEXTAREA_ATTR_READONLY = "readonly";
039:
040: private static final String[] supportedTags = { "textarea" };
041:
042: /* (non-Javadoc)
043: * @see com.sun.portal.wireless.htmlconversion.processors.BaseTagProcessor#getAmlTag()
044: */
045: public String getAmlTag() {
046: return AML_TEXT_AREA;
047: }
048:
049: /* (non-Javadoc)
050: * @see com.sun.portal.wireless.htmlconversion.processors.BaseTagProcessor#getSupportedTags()
051: */
052: public String[] getSupportedTags() {
053: return supportedTags;
054: }
055:
056: /* (non-Javadoc)
057: * @see com.sun.portal.wireless.htmlconversion.processors.BaseTagProcessor#canHaveChildren(com.sun.portal.wireless.htmlconversion.ParserState)
058: */
059: public boolean canHaveChildren(ParserState state) {
060: return false;
061: }
062:
063: /* (non-Javadoc)
064: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#startTag(java.lang.String, java.util.HashMap, com.sun.portal.wireless.htmlconversion.ParserState)
065: */
066: public Element startTag(String tagName, HashMap attributes,
067: ParserState state) {
068: Element amlTextArea = state.newElement(AML_TEXT_AREA);
069:
070: String name = (String) attributes.get(TEXTAREA_ATTR_NAME);
071: amlTextArea.setAttribute(ATTR_NAME, name);
072:
073: String rows = (String) attributes.get(TEXTAREA_ATTR_ROWS);
074: if (rows != null) {
075: amlTextArea.setAttribute(ATTR_HEIGHT, rows);
076: }
077:
078: String cols = (String) attributes.get(TEXTAREA_ATTR_COLS);
079: if (cols != null) {
080: amlTextArea.setAttribute(ATTR_WIDTH, cols);
081: }
082:
083: if (attributes.keySet().contains(TEXTAREA_ATTR_DISABLED)
084: || attributes.keySet().contains(TEXTAREA_ATTR_READONLY)) {
085: amlTextArea.setAttribute(ATTR_VIEW, VAL_VIEW_HIDDEN);
086: }
087:
088: return amlTextArea;
089: }
090:
091: /* (non-Javadoc)
092: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#endTag(java.lang.String, com.sun.portal.wireless.htmlconversion.ParserState)
093: */
094: public Element endTag(String tag, ParserState state) {
095: Element currentTag = state.getCurrentOutputTag();
096:
097: // Note that in the case of badly formed HTML, with
098: // formatting elements inserted inside textarea text,
099: // this will fail to function properly
100: if (currentTag.getTagName().equals(AML_TEXT_AREA)
101: && state.isTextAvailable()) {
102: currentTag.setAttribute(ATTR_VALUE, state.getText());
103: }
104:
105: state.clearText();
106:
107: return currentTag;
108: }
109:
110: }
|