KickJava   Java API By Example, From Geeks To Geeks.

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


1 package fr.improve.struts.taglib.layout;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import javax.servlet.jsp.JspException JavaDoc;
5
6 import fr.improve.struts.taglib.layout.skin.Skin;
7 import fr.improve.struts.taglib.layout.util.HTMLUtils;
8 import fr.improve.struts.taglib.layout.util.LayoutUtils;
9 import fr.improve.struts.taglib.layout.util.TagUtils;
10
11 /**
12  * Struts-Layout skin tag (&lt;layout:skin&gt;).<br>
13  * This tag generates in the JSP code to :
14  * <ul>
15  * <li>Load the current Skin CSS</li>
16  * <li>Define global Javascript variables (
17  * imgsrc : server root relative skin image directory,
18  * scriptsrc : server root relatrive config directory,
19  * langue : Struts locale,
20  * contextPath : application context path)
21  * </li>
22  * <li>Load Struts-Layout Javascript (the file named javascript.js in the skin config directory); if includeScript is set to true.</li>
23  * </ul>
24  *
25  * Creation date: (17/06/2001 18:01:46)
26  * @author: Jean-NoŽl Ribette
27  */

28 public class SkinTag extends javax.servlet.jsp.tagext.TagSupport JavaDoc {
29     /**
30      * Should we include Struts-Layout Javascript ?
31      * Default is false for background compatibility.
32      */

33     private boolean include = false;
34
35     /**
36      * End tag callback.
37      */

38     public int doEndTag() throws JspException JavaDoc {
39         // Get the current skin.
40
Skin lc_skin = LayoutUtils.getSkin(pageContext.getSession());
41         
42         // Load the CSS skin.
43
String JavaDoc cssLocation = lc_skin.getCssDirectory(pageContext.getRequest())+"/"+lc_skin.getCssFileName();
44         HTMLUtils.generateTag(pageContext, "link", new String JavaDoc[][]{{"rel", "stylesheet"}, {"href", cssLocation}, {"type", "text/css"}});
45         
46         // Generate various Javascript variables.
47
HTMLUtils.openTag(pageContext, "script", new String JavaDoc[][]{{"type", "text/javascript"}});
48         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
49         sb.append("var imgsrc=\"");
50         sb.append(lc_skin.getImageDirectory(pageContext.getRequest()));
51         if (!lc_skin.getImageDirectory(pageContext.getRequest()).endsWith("/")) sb.append("/");
52         sb.append("\"; var scriptsrc=\"");
53         sb.append(lc_skin.getConfigDirectory(pageContext.getRequest()));
54         if (!lc_skin.getConfigDirectory(pageContext.getRequest()).endsWith("/")) sb.append("/");
55         sb.append("\"; var langue=\"");
56         sb.append(LayoutUtils.getLocale(pageContext).getLanguage());
57         sb.append("\"; var contextPath=\"");
58         sb.append(((HttpServletRequest JavaDoc)pageContext.getRequest()).getContextPath());
59         sb.append("\";");
60         TagUtils.write(pageContext, sb.toString());
61         HTMLUtils.closeTag(pageContext, "script");
62         
63         // Load Struts-Layout Javascript code if configured to do so.
64
if (include) {
65             sb = new StringBuffer JavaDoc(lc_skin.getConfigDirectory(pageContext.getRequest()));
66             if (!lc_skin.getConfigDirectory(pageContext.getRequest()).endsWith("/")) sb.append("/");
67             sb.append("javascript.js");
68             HTMLUtils.openTag(pageContext, "script", new String JavaDoc[][]{{"type", "text/javascript"}, {"src", sb.toString()}});
69             HTMLUtils.closeTag(pageContext, "script");
70         }
71         
72         // Go on evaluating the page.
73
return EVAL_PAGE;
74     }
75     
76     /**
77      * Release the tag.
78      */

79     public void release() {
80         include = false;
81     }
82     
83     /**
84      * Setter for setting the includeScript boolean variable.
85      * @param in_include include Struts-Layout Javascript loading code
86      */

87     public void setIncludeScript(boolean in_include) {
88         include = in_include;
89     }
90 }
91
Popular Tags