View Javadoc

1   package net.sf.tacos.javascript.jquery;
2   
3   import java.util.List;
4   
5   import org.apache.tapestry.IAsset;
6   import org.apache.tapestry.IMarkupWriter;
7   import org.apache.tapestry.IRequestCycle;
8   import org.apache.tapestry.javascript.JavascriptManagerImpl;
9   
10  /**
11   * For some jquery plugins we bundle, we want to add their css.
12   * 
13   * @author andyhot
14   */
15  public class JqueryJavascriptManagerImpl extends JavascriptManagerImpl {
16  	private List cssAssets;
17  	
18      public void setCssFiles(String cssFiles)
19      {
20      	this.cssAssets = buildAssetList(cssFiles, "cssFiles");
21      }
22      
23      public List getCssAssets() {
24      	return this.cssAssets;
25      }
26  
27  	public void renderLibraryResources(IMarkupWriter writer, IRequestCycle cycle, 
28  			boolean hasForm, boolean hasWidget) {
29  		super.renderLibraryResources(writer, cycle, hasForm, hasWidget);
30  
31  		appendAssetsAsCss(writer, cycle, getCssAssets());
32  	}
33  	
34      
35      protected void appendAssetsAsCss(IMarkupWriter writer, IRequestCycle cycle, List assets) {
36      	if (assets==null) {
37      		return;
38      	}
39      	
40          for (int i = 0; i < assets.size(); i++) {
41          	appendAssetAsCss(writer, cycle, (IAsset) assets.get(i));
42          }    	
43      }     
44      
45      /**
46       * Appends a link tag to include the given asset. 
47       * @param str
48       * @param cycle
49       * @param asset
50       */
51      protected void appendAssetAsCss(IMarkupWriter writer, IRequestCycle cycle, IAsset asset)
52      {
53          final String url = asset.buildURL();
54          
55          writer.beginEmpty("link");
56          writer.attribute("media", "screen");
57          writer.attribute("rel", "stylesheet");
58          writer.attribute("type", "text/css");
59          writer.attribute("href", url);
60          writer.println();        
61      } 	
62      
63  }