1 20 package net.sf.packtag.tag; 21 22 import javax.servlet.jsp.JspWriter ; 23 24 import net.sf.packtag.implementation.IBloomCssPackStrategy; 25 import net.sf.packtag.strategy.PackStrategy; 26 27 28 29 35 public class StyleTag extends BaseTag { 36 37 private static final long serialVersionUID = -6557382191171304567L; 38 39 private static final String STYLE_START = "<link rel=\"stylesheet\" type=\"text/css\" HREF=\""; 40 private static final String STYLE_MEDIA = "\" media=\""; 41 private static final String STYLE_END = "\"/>"; 42 private static final String ATTRIBUTE_MEDIA = "media"; 43 44 private String media; 45 46 47 protected PackStrategy getPackStrategy() throws Exception { 48 String className = getPackStrategyClassName("style"); 49 if ((className == null) || className.equals("")) { 50 return new IBloomCssPackStrategy(); 51 } 52 return (PackStrategy)Class.forName(className).newInstance(); 53 } 54 55 56 protected void writeResouce(JspWriter writer, String path) throws Exception { 57 StringBuffer buffer = new StringBuffer (); 58 buffer.append(STYLE_START); 59 buffer.append(path); 60 if ((getMedia() != null) && !getMedia().equals(EMPTY_STRING)) { 61 buffer.append(STYLE_MEDIA); 62 buffer.append(getMedia()); 63 } 64 buffer.append(STYLE_END); 65 writer.write(buffer.toString()); 66 } 67 68 69 protected String getResourceExtension() { 70 return "css"; 71 } 72 73 74 public String getMedia() { 75 return media; 76 } 77 78 79 public void setMedia(String media) { 80 if (isStandardTaglibAvailable()) { 81 this.media = (String )evaluate(ATTRIBUTE_MEDIA, media, String .class); 82 } 83 else { 84 this.media = media; 85 } 86 } 87 88 } 89 | Popular Tags |