KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > html > ImageTag


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.html;
8
9
10 import java.io.IOException JavaDoc;
11
12 import javax.servlet.jsp.JspException JavaDoc;
13
14 import org.apache.log4j.Logger;
15
16 import com.inversoft.util.ObjectTools;
17 import com.inversoft.verge.mvc.view.HtmlConstants;
18 import com.inversoft.verge.mvc.view.HtmlViewToolkit;
19 import com.inversoft.verge.mvc.view.jsp.JspTools;
20
21
22 /**
23  * This class is the image submit input tag.
24  *
25  * @author Brian Pontarelli
26  */

27 public class ImageTag extends SubmitTag {
28
29     /**
30      * This classes logger
31      */

32     private static final Logger logger = Logger.getLogger(ImageTag.class);
33
34     private String JavaDoc src;
35     protected String JavaDoc localSrc;
36     private String JavaDoc usemap;
37     protected String JavaDoc localUsemap;
38     private String JavaDoc ismap;
39     protected String JavaDoc localIsmap;
40
41
42     /**
43      * Retrieves the tag's src attribute
44      *
45      * @return Returns the tag's src attribute
46      */

47     public String JavaDoc getSrc() {
48         return src;
49     }
50
51     /**
52      * Populates the tag's src attribute
53      *
54      * @param src The value of the tag's src attribute
55      */

56     public void setSrc(String JavaDoc src) {
57         this.src = src;
58     }
59
60     /**
61      * Retrieves the tag's use map attribute
62      *
63      * @return Returns the tag's use map attribute
64      */

65     public String JavaDoc getUsemap() {
66         return usemap;
67     }
68
69     /**
70      * Populates the tag's use map attribute
71      *
72      * @param usemap The value of the tag's use map attribute
73      */

74     public void setUsemap(String JavaDoc usemap) {
75         this.usemap = usemap;
76     }
77
78     /**
79      * Retrieves the tag's ismap attribute
80      *
81      * @return Returns the tag's ismap attribute
82      */

83     public String JavaDoc getIsmap() {
84         return ismap;
85     }
86
87     /**
88      * Populates the tag's ismap attribute
89      *
90      * @param ismap The value of the tag's ismap attribute
91      */

92     public void setIsmap(String JavaDoc ismap) {
93         this.ismap = ismap;
94     }
95
96     /**
97      * Exapnds the attributes if not JSP 2.0 or greater.
98      *
99      * @throws JspException If there were any problems expanding the attributes
100      */

101     protected void initialize() throws JspException JavaDoc {
102         super.initialize();
103
104         localSrc = src;
105         localUsemap = usemap;
106         localIsmap = ismap;
107
108         if (!JspTools.JSP_20) {
109             localSrc = (String JavaDoc) JspTools.expand("src", src, String JavaDoc.class, this,
110                 pageContext);
111             localIsmap = (String JavaDoc) JspTools.expand("ismap", ismap, String JavaDoc.class,
112                 this, pageContext);
113             localUsemap = (String JavaDoc) JspTools.expand("usemap", usemap,
114                 String JavaDoc.class, this, pageContext);
115         }
116
117         attributes.put(HtmlConstants.IS_MAP, localIsmap);
118         attributes.put(HtmlConstants.USE_MAP, localUsemap);
119     }
120
121     /**
122      * Ouputs an image input tag.
123      *
124      * @return Always returns SKIP_BODY
125      * @throws JspException If this tag is not inside a submit tag and the submit
126      * tag is not inside a form tag, or if a property name was not specified
127      */

128     public int doStartTag() throws JspException JavaDoc {
129
130         // Initialize the parent reference and the bean reference
131
initialize();
132
133         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
134         createImageTag(buf, id, localName, localSrc, localValue);
135
136         if (logger.isDebugEnabled()) {
137             logger.debug("The image tag: " + buf.toString());
138         }
139
140         try {
141             pageContext.getOut().print(buf.toString());
142         } catch (IOException JavaDoc ioe) {
143             throw new JspException JavaDoc(ioe.toString());
144         }
145
146         return SKIP_BODY;
147     }
148
149     /**
150      * Does the work of creating the tags body. This method can be overridden
151      * in sub-classes to change the attributes that are appended, etc. By default
152      * this creates an image tag with the name, value, attributes (single and named)
153      *
154      * @param buf The StringBuffer to append to
155      */

156     protected void createImageTag(StringBuffer JavaDoc buf, String JavaDoc id, String JavaDoc name,
157             String JavaDoc src, Object JavaDoc value) {
158         String JavaDoc valueStr = ObjectTools.toString(value);
159         HtmlViewToolkit.createImageTag(buf, id, name, src, valueStr,
160             attributes, singleAttrs);
161     }
162 }
Popular Tags