001: /* Img.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Tue Sep 20 15:13:32 2005, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.web.servlet.dsp.action.html;
020:
021: import java.io.IOException;
022:
023: import org.zkoss.web.mesg.MWeb;
024: import org.zkoss.web.servlet.ServletException;
025: import org.zkoss.web.servlet.dsp.action.AbstractAction;
026: import org.zkoss.web.servlet.dsp.action.ActionContext;
027:
028: /**
029: * Generates the HTML <img> tag
030: *
031: * @author tomyeh
032: */
033: public class Img extends AbstractAction {
034: private String _id, _onclick;
035: private String _src, _height, _width, _border, _hspace, _vspace;
036: private String _align, _title, _alt, _sclass, _style;
037:
038: /** Returns the id attribute.
039: * Default: null.
040: */
041: public String getId() {
042: return _id;
043: }
044:
045: /** Sets the id attribute.
046: */
047: public void setId(String id) {
048: _id = id;
049: }
050:
051: /** Returns the src (URL).
052: * Default: null.
053: */
054: public String getSrc() {
055: return _src;
056: }
057:
058: /** Sets the src (URL).
059: */
060: public void setSrc(String src) {
061: _src = src;
062: }
063:
064: /** Returns the alignment.
065: * Default: null.
066: */
067: public String getAlign() {
068: return _align;
069: }
070:
071: /** Sets the alignment.
072: */
073: public void setAlign(String align) {
074: _align = align;
075: }
076:
077: /** Returns the alt.
078: * Default: null.
079: */
080: public String getAlt() {
081: return _alt;
082: }
083:
084: /** Sets the alt.
085: */
086: public void setAlt(String alt) {
087: _alt = alt;
088: }
089:
090: /** Returns the border.
091: * Default: null.
092: */
093: public String getBorder() {
094: return _border;
095: }
096:
097: /** Sets the border.
098: */
099: public void setBorder(String border) {
100: _border = border;
101: }
102:
103: /** Returns the hspace.
104: * Default: null.
105: */
106: public String getHspace() {
107: return _hspace;
108: }
109:
110: /** Sets the hspace.
111: */
112: public void setHspace(String hspace) {
113: _hspace = hspace;
114: }
115:
116: /** Returns the vspace.
117: * Default: null.
118: */
119: public String getVspace() {
120: return _vspace;
121: }
122:
123: /** Sets the vspace.
124: */
125: public void setVspace(String vspace) {
126: _vspace = vspace;
127: }
128:
129: /** Returns the style class.
130: * Default: null.
131: */
132: public String getSclass() {
133: return _sclass;
134: }
135:
136: /** Sets the style class.
137: */
138: public void setSclass(String sclass) {
139: _sclass = sclass;
140: }
141:
142: /** Returns the style.
143: * Default: null.
144: */
145: public String getStyle() {
146: return _style;
147: }
148:
149: /** Sets the style.
150: */
151: public void setStyle(String style) {
152: _style = style;
153: }
154:
155: /** Returns the height.
156: * Default: null.
157: */
158: public String getHeight() {
159: return _height;
160: }
161:
162: /** Sets the height.
163: */
164: public void setHeight(String height) {
165: _height = height;
166: }
167:
168: /** Returns the width.
169: * Default: null.
170: */
171: public String getWidth() {
172: return _width;
173: }
174:
175: /** Sets the width.
176: */
177: public void setWidth(String width) {
178: _width = width;
179: }
180:
181: /** Returns the title.
182: * Default: null (no title at all).
183: */
184: public String getTitle() {
185: return _title;
186: }
187:
188: /** Sets the title.
189: */
190: public void setTitle(String title) {
191: _title = title;
192: }
193:
194: /** Returns the onclick.
195: * Default: null.
196: */
197: public String getOnclick() {
198: return _onclick;
199: }
200:
201: /** Sets the onclick.
202: */
203: public void setOnclick(String onclick) {
204: _onclick = onclick;
205: }
206:
207: //-- Action --//
208: public void render(ActionContext ac, boolean nested)
209: throws javax.servlet.ServletException, IOException {
210: if (!isEffective() || _src == null || _src.length() == 0)
211: return; //nothing to generate
212: if (nested)
213: throw new ServletException(
214: MWeb.DSP_NESTED_ACTION_NOT_ALLOWED, new Object[] {
215: this , new Integer(ac.getLineNumber()) });
216:
217: final StringBuffer sb = new StringBuffer(64).append(
218: "<img src=\"").append(ac.encodeURL(_src)).append('"');
219: append(sb, "id", _id);
220: append(sb, "height", _height);
221: append(sb, "width", _width);
222: append(sb, "title", _title);
223: append(sb, "align", _align);
224: append(sb, "alt", _alt);
225: append(sb, "class", _sclass);
226: append(sb, "style", _style);
227: append(sb, "border", _border);
228: append(sb, "hspace", _hspace);
229: append(sb, "vspace", _vspace);
230: append(sb, "onclick", _onclick);
231: sb.append("/>");
232: ac.getOut().write(sb.toString());
233: }
234:
235: //-- Object --//
236: public String toString() {
237: return "image";
238: }
239: }
|