1 7 package fr.improve.struts.taglib.layout; 8 9 import javax.servlet.jsp.JspException ; 10 11 import fr.improve.struts.taglib.layout.skin.Skin; 12 import fr.improve.struts.taglib.layout.util.LayoutUtils; 13 import fr.improve.struts.taglib.layout.util.TagUtils; 14 15 20 public class ResourceTag extends LayoutTagSupport { 21 protected static final int IMG = 1; 22 protected static final int CFG = 2; 23 protected static final int CSS = 3; 24 protected int type; 25 protected String name; 26 27 public int doStartLayoutTag() throws JspException { 28 Skin lc_skin = LayoutUtils.getSkin(pageContext.getSession()); 30 StringBuffer lc_buffer = new StringBuffer (); 31 32 switch (type) { 33 case IMG: 34 String lc_imgSrc = lc_skin.getImageDirectory(pageContext.getRequest()); 36 lc_buffer.append(lc_imgSrc); 38 if (!lc_imgSrc.endsWith("/") && !name.startsWith("/")) { 39 lc_buffer.append('/'); 40 } 41 lc_buffer.append(name); 42 break; 43 case CFG: 44 String lc_cfgDir = lc_skin.getConfigDirectory(pageContext.getRequest()); 46 lc_buffer.append(lc_cfgDir); 48 if (!lc_cfgDir.endsWith("/") && !name.startsWith("/")) { 49 lc_buffer.append('/'); 50 } 51 lc_buffer.append(name); 52 break; 53 case CSS: 54 String lc_cssDir = lc_skin.getCssDirectory(pageContext.getRequest()); 56 lc_buffer.append(lc_cssDir); 58 if (!lc_cssDir.endsWith("/") && !name.startsWith("/")) { 59 lc_buffer.append('/'); 60 } 61 lc_buffer.append(name); 62 break; 63 } 64 65 TagUtils.write(pageContext, lc_buffer.toString()); 66 return SKIP_BODY; 67 } 68 public void release() { 69 super.release(); 70 type = IMG; 71 name = null; 72 } 73 74 public void setType(String in_type) throws JspException { 75 if ("img".equals(in_type)) { 76 type = IMG; 77 } else if ("cfg".equals(in_type)) { 78 type = CFG; 79 } else if ("css".equals(in_type)) { 80 type = CSS; 81 } else { 82 throw new JspException ("Type " + in_type + " is not supported."); 83 } 84 } 85 86 public void setName(String in_name) { 87 name = in_name; 88 } 89 } 90 | Popular Tags |