KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > ImgTag


1 package fr.improve.struts.taglib.layout;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import fr.improve.struts.taglib.layout.el.Expression;
6 import fr.improve.struts.taglib.layout.skin.Skin;
7 import fr.improve.struts.taglib.layout.util.LayoutUtils;
8
9 /**
10  * Image tag, allowing to include an image from the skin image directory.
11  * @author JN Ribette
12  */

13 public class ImgTag extends org.apache.struts.taglib.html.ImgTag {
14     /**
15      * Image location relative to the skin image directory.
16      */

17     protected String JavaDoc srcName;
18     
19     /**
20      * Original styleId value
21      */

22     private String JavaDoc jspStyleId;
23     
24     /**
25      * Original onclick value.
26      */

27     private String JavaDoc jspOnclick;
28     
29     /**
30      * Original action value.
31      */

32     private String JavaDoc jspAction;
33     
34     /**
35      * Layout support.
36      */

37     protected boolean layout = true;
38     
39     public int doStartTag() throws JspException JavaDoc {
40         initDynamicValues();
41         return super.doStartTag();
42     }
43     
44     public int doEndTag() throws JspException JavaDoc {
45         int ret = super.doEndTag();
46         reset();
47         return ret;
48     }
49     
50     public void release() {
51         super.release();
52         srcName = null;
53         layout = true;
54     }
55     
56     protected void reset() {
57         setOnclick(jspOnclick);
58         setStyleId(jspStyleId);
59         setAction(jspAction);
60     }
61     
62     protected void initDynamicValues() {
63         jspOnclick = getOnclick();
64         setOnclick(Expression.evaluate(getOnclick(), pageContext));
65         jspStyleId = getStyleId();
66         setStyleId(Expression.evaluate(getStyleId(), pageContext));
67         jspAction = action;
68         setAction(Expression.evaluate(getAction(), pageContext));
69     }
70     
71     public String JavaDoc getSrcName() {
72         return srcName;
73     }
74     public void setSrcName(String JavaDoc skinSrc) {
75         this.srcName = skinSrc;
76     }
77     public boolean isLayout() {
78         return layout;
79     }
80     public void setLayout(boolean layout) {
81         this.layout = layout;
82     }
83     protected String JavaDoc src() throws JspException JavaDoc {
84         if (srcName!=null) {
85             // Get skin image directory.
86
Skin lc_skin = LayoutUtils.getSkin(pageContext.getSession());
87             String JavaDoc lc_imgSrc = lc_skin.getImageDirectory(pageContext.getRequest());
88             
89             // Generate image URL code.
90
StringBuffer JavaDoc lc_buffer = new StringBuffer JavaDoc(lc_imgSrc);
91             if (!lc_imgSrc.endsWith("/") && !srcName.startsWith("/")) {
92                 lc_buffer.append('/');
93             }
94             lc_buffer.append(srcName);
95             return lc_buffer.toString();
96         } else {
97             return super.src();
98         }
99     }
100 }
101
Popular Tags