KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > deprecated > taglibs > button > DisplayIconTag


1 // ____.
2
// __/\ ______| |__/\. _______
3
// __ .____| | \ | +----+ \
4
// _______| /--| | | - \ _ | : - \_________
5
// \\______: :---| : : | : | \________>
6
// |__\---\_____________:______: :____|____:_____\
7
// /_____|
8
//
9
// . . . i n j a h i a w e t r u s t . . .
10
//
11
/*
12  * ----- BEGIN LICENSE BLOCK -----
13  * Version: JCSL 1.0
14  *
15  * The contents of this file are subject to the Jahia Community Source License
16  * 1.0 or later (the "License"); you may not use this file except in
17  * compliance with the License. You may obtain a copy of the License at
18  * http://www.jahia.org/license
19  *
20  * Software distributed under the License is distributed on an "AS IS" basis,
21  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
22  * for the rights, obligations and limitations governing use of the contents
23  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
24  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
25  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
26  *
27  * The Shared Modifications are Jahia button TagLibs.
28  *
29  * The Developer of the Shared Modifications is Jahia Solution S�rl.
30  * Portions created by the Initial Developer are Copyright (C) 2002 by the
31  * Initial Developer. All Rights Reserved.
32  *
33  * Contributor(s):
34  * Sep 24 2002 Jahia Solutions S�rl: MAP Initial release.
35  *
36  * ----- END LICENSE BLOCK -----
37  */

38
39 package org.jahia.deprecated.taglibs.button;
40
41 import java.io.IOException JavaDoc;
42
43 import javax.servlet.http.HttpServletRequest JavaDoc;
44 import javax.servlet.jsp.JspException JavaDoc;
45 import javax.servlet.jsp.JspWriter JavaDoc;
46 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
47
48 import org.jahia.data.JahiaData;
49 import org.jahia.resourcebundle.JahiaResourceBundle;
50
51 /**
52  * <p>The Jahia Shared Modification is: Jahia Tag Libs</p>
53  *
54  * <p>Description:
55  * Write a non localized HTML image tag defined in a common resource bundle
56  * file.<br>
57  *
58  * Synopsis : < jahia:displayIcon SRC="resourceBundleKey" [alt="< text>"]
59  * [resource="< relative path to an image>"]<br>
60  *
61  * src : resource bundle key.<br>
62  * alt : Correspond to the < IMG> tag "alt" parameter.<br>
63  * resource : Alternative resource defined by the relative path from the
64  * JSP source file to an image file.</p>
65  *
66  * <p>Copyright: MAP (Jahia Solutions S�rl 2002)</p>
67  * <p>Company: Jahia Solutions S�rl</p>
68  * @author MAP
69  * @version 1.0
70  */

71 public class DisplayIconTag extends BodyTagSupport JavaDoc {
72
73     /**
74      * @param src The resource bundle key. Required but not take if 'resource'
75      * is set.
76      */

77     public void setSrc(String JavaDoc src) {
78         _src = src;
79     }
80
81     /**
82      * @param resource The path to a resource image file.
83      */

84     public void setResource(String JavaDoc resource) {
85         _resource = resource;
86     }
87
88     /**
89      * @param height The image height
90      */

91     public void setHeight(Integer JavaDoc height) {
92         _height = height;
93     }
94
95     /**
96      * @param width The image width
97      */

98     public void setWidth(Integer JavaDoc width) {
99         _width = width;
100     }
101
102     /**
103      * @param alt The alt parameter from the flag image.
104      */

105     public void setAlt(String JavaDoc alt) {
106         _alt = alt;
107     }
108
109     public void setAltKey(String JavaDoc altKey) {
110         this.altKey = altKey;
111     }
112
113     public void setAltBundle(String JavaDoc altBundle) {
114         this.altBundle = altBundle;
115     }
116
117     /**
118      * @param align The align parameter from the image tag.
119      */

120     public void setAlign(String JavaDoc align) {
121         _align = align;
122     }
123
124     public int doStartTag() {
125
126         // Recover 'jData'
127
// @todo FIXME : This code is repeated in a lot of button taglibs
128
HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
129         JahiaData jData = (JahiaData)request.getAttribute("org.jahia.data.JahiaData");
130
131         // now let's resolve the alt text if resource bundle keys are being used.
132
if (altKey != null) {
133             _alt = JahiaResourceBundle.getResource(altBundle, altKey, jData.params().getLocale(), jData.params());
134         }
135
136         // Produce the HTML code
137
try {
138             JspWriter JavaDoc out = pageContext.getOut();
139             StringBuffer JavaDoc str = new StringBuffer JavaDoc("");
140             // Resolve file name
141
String JavaDoc imagePath = JahiaResourceBundle.getUrlPathCommonResource(
142                     _src, jData.params());
143             if (("".equals(_resource)) && (imagePath == null)) {
144                 str.append("<!-- couldn't find resource with key " + _src + " -->");
145             } else {
146                 // Write image HTML tag
147
str.append("<img alt=\"");
148                 str.append(_alt);
149                 str.append("\" border=\"0\" SRC=\"");
150                 if ("".equals(_resource)) {
151                     str.append(imagePath);
152                 } else {
153                     str.append(_resource);
154                 }
155                 str.append("\"");
156                 if (_height != null) {
157                     str.append(" height=\"");
158                     str.append(_height.intValue());
159                     str.append("\"");
160                 }
161                 if (_width != null) {
162                     str.append(" width=\"");
163                     str.append(_width.intValue());
164                     str.append("\"");
165                 }
166                 if (_align != null) {
167                     str.append(" align=\"");
168                     str.append(_align);
169                     str.append("\"");
170                 }
171                 str.append(">");
172             }
173             out.print(str.toString());
174         } catch (IOException JavaDoc ioe) {
175             logger.debug(ioe.toString());
176         }
177         return SKIP_BODY;
178     }
179
180     public int doEndTag() throws JspException JavaDoc {
181         // let's reinitialize the tag variables to allow tag object reuse in
182
// pooling.
183
_src = "";
184         _resource = "";
185         _alt = "";
186         altKey = null;
187         altBundle = null;
188         _height = null;
189         _width = null;
190         _align = "";
191         return EVAL_PAGE;
192     }
193
194
195     // Taglib parameters
196
private String JavaDoc _src = "";
197     private String JavaDoc _resource = "";
198     private String JavaDoc _alt = "";
199     private String JavaDoc altKey = null;
200     private String JavaDoc altBundle = null;
201     private Integer JavaDoc _height = null;
202     private Integer JavaDoc _width = null;
203     private String JavaDoc _align = "";
204
205     private static long imgID = 0;
206
207     private static org.apache.log4j.Logger logger =
208             org.apache.log4j.Logger.getLogger(DisplayIconTag.class);
209
210 }
211
Popular Tags