KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > packtag > tag > StyleTag


1 /**
2  * Project pack:tag >> http://packtag.sf.net
3  *
4  * This software is published under the terms of the LGPL
5  * License version 2.1, a copy of which has been included with this
6  * distribution in the 'lgpl.txt' file.
7  *
8  * Last author: $Author: danielgalan $
9  * Last modified: $Date: 2007/05/02 21:29:19 $
10  * Revision: $Revision: 1.2 $
11  *
12  * $Log: StyleTag.java,v $
13  * Revision 1.2 2007/05/02 21:29:19 danielgalan
14  * last fixes for 2.0, attribute media
15  *
16  * Revision 1.1 2007/04/22 19:04:24 danielgalan
17  * pack.tag moved from subversion to good old CVS
18  *
19  */

20 package net.sf.packtag.tag;
21
22 import javax.servlet.jsp.JspWriter JavaDoc;
23
24 import net.sf.packtag.implementation.IBloomCssPackStrategy;
25 import net.sf.packtag.strategy.PackStrategy;
26
27
28
29 /**
30  * JSP Tag for compressing Cascading Style Sheet resources.
31  *
32  * @author Daniel Galán y Martins
33  * @version $Revision: 1.2 $
34  */

35 public class StyleTag extends BaseTag {
36
37     private static final long serialVersionUID = -6557382191171304567L;
38
39     private static final String JavaDoc STYLE_START = "<link rel=\"stylesheet\" type=\"text/css\" HREF=\"";
40     private static final String JavaDoc STYLE_MEDIA = "\" media=\"";
41     private static final String JavaDoc STYLE_END = "\"/>";
42     private static final String JavaDoc ATTRIBUTE_MEDIA = "media";
43
44     private String JavaDoc media;
45
46
47     protected PackStrategy getPackStrategy() throws Exception JavaDoc {
48         String JavaDoc 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 JavaDoc writer, String JavaDoc path) throws Exception JavaDoc {
57         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
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 JavaDoc getResourceExtension() {
70         return "css";
71     }
72
73
74     public String JavaDoc getMedia() {
75         return media;
76     }
77
78
79     public void setMedia(String JavaDoc media) {
80         if (isStandardTaglibAvailable()) {
81             this.media = (String JavaDoc)evaluate(ATTRIBUTE_MEDIA, media, String JavaDoc.class);
82         }
83         else {
84             this.media = media;
85         }
86     }
87
88 }
89
Popular Tags