001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.jsp.tag.presentation;
016:
017: import java.io.Writer;
018: import javax.servlet.jsp.JspException;
019: import org.araneaframework.jsp.exception.AraneaJspException;
020: import org.araneaframework.jsp.tag.PresentationTag;
021:
022: /**
023: * UI image tag.
024: *
025: * @author Oleg Mürk
026: */
027: public abstract class BaseImageTag extends PresentationTag {
028: // Usual HTML <img> tag attributes
029: protected String code, src, width, height, alt, title;
030:
031: protected int doStartTag(Writer out) throws Exception {
032: super .doStartTag(out);
033:
034: if (code != null) {
035: Info info = getImageInfo(code);
036: if (info == null)
037: throw new AraneaJspException(
038: "Missing image description with code '" + code
039: + "'");
040: this .src = info.src;
041: this .width = info.width;
042: this .height = info.height;
043: }
044:
045: return EVAL_BODY_INCLUDE;
046: }
047:
048: /**
049: * Image info class.
050: */
051: protected static class Info {
052: public Info(String src, String width, String height) {
053: this .src = src;
054: this .width = width;
055: this .height = height;
056: this .alt = null;
057: }
058:
059: public Info(String src, String width, String height, String alt) {
060: this .src = src;
061: this .width = width;
062: this .height = height;
063: this .alt = alt;
064: }
065:
066: public String src;
067: public String width;
068: public String height;
069: public String alt;
070: }
071:
072: /* ***********************************************************************************
073: * Tag attributes
074: * ***********************************************************************************/
075: /**
076: * @jsp.attribute
077: * type = "java.lang.String"
078: * required = "false"
079: * description = "Image code."
080: */
081: public void setCode(String code) throws JspException {
082: this .code = (String) evaluate("code", code, String.class);
083: }
084:
085: /**
086: * @jsp.attribute
087: * type = "java.lang.String"
088: * required = "false"
089: * description = "Image src."
090: */
091: public void setSrc(String src) throws JspException {
092: this .src = (String) evaluate("src", src, String.class);
093: }
094:
095: /**
096: * @jsp.attribute
097: * type = "java.lang.String"
098: * required = "false"
099: * description = "Image width"
100: */
101:
102: public void setWidth(String width) throws JspException {
103: this .width = (String) evaluate("width", width, String.class);
104: }
105:
106: /**
107: * @jsp.attribute
108: * type = "java.lang.String"
109: * required = "false"
110: * description = "Image height."
111: */
112: public void setHeight(String height) throws JspException {
113: this .height = (String) evaluate("height", height, String.class);
114: }
115:
116: /**
117: * @jsp.attribute
118: * type = "java.lang.String"
119: * required = "false"
120: * description = "Image alternate text."
121: */
122: public void setAlt(String alt) throws JspException {
123: this .alt = (String) evaluate("alt", alt, String.class);
124: }
125:
126: /**
127: * @jsp.attribute
128: * type = "java.lang.String"
129: * required = "false"
130: * description = "Image title"
131: */
132: public void setTitle(String title) throws JspException {
133: this .title = (String) evaluate("title", title, String.class);
134: }
135:
136: /* ***********************************************************************************
137: * ABSTRACT METHODS
138: * ***********************************************************************************/
139: protected abstract Info getImageInfo(String code);
140: }
|