001: /*
002: * Created on Mar 12, 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: import com.sun.portal.wireless.htmlconversion.servlet.URLTranscoder;
012: import com.sun.portal.wireless.htmlconversion.servlet.URLScraper;
013: import com.sun.portal.wireless.transcode.TranscodeConstants;
014:
015: /**
016: * Tag processor for the AmlImage tag
017: *
018: * @author ashwin.mathew@sun.com
019: */
020: public class AmlImageTagProcessor extends BaseTagProcessor {
021:
022: public static final String AML_IMAGE = "AmlImage";
023:
024: // Attributes for AmlImage
025: public static final String ATTR_SRC = "src";
026: public static final String ATTR_ALT = "alt";
027: public static final String ATTR_ALIGN = "align";
028: public static final String ATTR_HEIGHT = "height";
029: public static final String ATTR_WIDTH = "width";
030: public static final String ATTR_HSPACE = "hspace";
031: public static final String ATTR_VSPACE = "vspace";
032:
033: // Attributes for HTML img tag
034: public static final String IMG_ATTR_SRC = "src";
035: public static final String IMG_ATTR_ALT = "alt";
036: public static final String IMG_ATTR_ALIGN = "align";
037: public static final String IMG_ATTR_HEIGHT = "height";
038: public static final String IMG_ATTR_WIDTH = "width";
039: public static final String IMG_ATTR_HSPACE = "hspace";
040: public static final String IMG_ATTR_VSPACE = "vspace";
041:
042: private static final String EMPTY_STRING = "";
043:
044: private static final String[] supportedTags = { "img" };
045:
046: /* (non-Javadoc)
047: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getAmlTag()
048: */
049: public String getAmlTag() {
050: return AML_IMAGE;
051: }
052:
053: /* (non-Javadoc)
054: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#getSupportedTags()
055: */
056: public String[] getSupportedTags() {
057: return supportedTags;
058: }
059:
060: /* (non-Javadoc)
061: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#startTag(java.lang.String, java.util.HashMap, com.sun.portal.wireless.htmlconversion.ParserState)
062: */
063: public Element startTag(String tagName, HashMap attributes,
064: ParserState state) {
065: Element amlImage = state.newElement(AML_IMAGE);
066:
067: String src = (String) attributes.get(IMG_ATTR_SRC);
068:
069: // Encode with image transcoder URL
070: StringBuffer srcBuffer = new StringBuffer();
071:
072: URLTranscoder encoder = state.getEncoder();
073: if (encoder != null) {
074: srcBuffer.append(encoder.getContextPath());
075: src = encoder.resolveURL(src);
076: } else {
077: // Just in case, default to "/portal".
078: srcBuffer.append(URLScraper.DEFAULT_CONTEXT);
079: }
080:
081: srcBuffer.append(TranscodeConstants.URI);
082: srcBuffer.append(URLTranscoder.QUERY);
083: srcBuffer.append(TranscodeConstants.IMG);
084: srcBuffer.append(URLTranscoder.EQUALS);
085: srcBuffer.append(URLTranscoder.encode(src));
086:
087: amlImage.setAttribute(ATTR_SRC, srcBuffer.toString());
088:
089: String alt = (String) attributes.get(IMG_ATTR_ALT);
090: if (alt == null) {
091: alt = EMPTY_STRING; // Since alt is a required attribute
092: }
093: amlImage.setAttribute(ATTR_ALT, alt);
094:
095: String align = (String) attributes.get(IMG_ATTR_ALIGN);
096: if (align != null) {
097: amlImage.setAttribute(ATTR_ALIGN, align);
098: }
099:
100: String height = (String) attributes.get(IMG_ATTR_HEIGHT);
101: if (height != null) {
102: amlImage.setAttribute(ATTR_HEIGHT, height);
103: }
104:
105: String width = (String) attributes.get(IMG_ATTR_WIDTH);
106: if (width != null) {
107: amlImage.setAttribute(ATTR_WIDTH, width);
108: }
109:
110: String vspace = (String) attributes.get(IMG_ATTR_VSPACE);
111: if (vspace != null) {
112: amlImage.setAttribute(ATTR_VSPACE, vspace);
113: }
114:
115: String hspace = (String) attributes.get(IMG_ATTR_HSPACE);
116: if (hspace != null) {
117: amlImage.setAttribute(ATTR_HSPACE, hspace);
118: }
119:
120: return amlImage;
121: }
122:
123: /* (non-Javadoc)
124: * @see com.sun.portal.wireless.htmlconversion.TagProcessor#canHaveChildren(com.sun.portal.wireless.htmlconversion.ParserState)
125: */
126: public boolean canHaveChildren(ParserState state) {
127: return false;
128: }
129:
130: }
|