1 15 package org.apache.tapestry.html; 16 17 import org.apache.hivemind.Resource; 18 import org.apache.tapestry.AbstractComponent; 19 import org.apache.tapestry.IMarkupWriter; 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.PageRenderSupport; 22 import org.apache.tapestry.TapestryUtils; 23 import org.apache.tapestry.asset.AssetFactory; 24 import org.apache.tapestry.util.PageRenderSupportImpl; 25 import org.apache.tapestry.web.WebResponse; 26 27 35 36 public abstract class Body extends AbstractComponent implements PageRenderSupport 37 { 38 private PageRenderSupportImpl _pageRenderSupport; 39 40 48 49 public String getPreloadedImageReference(String URL) 50 { 51 return _pageRenderSupport.getPreloadedImageReference(URL); 52 } 53 54 59 60 public void addInitializationScript(String script) 61 { 62 _pageRenderSupport.addInitializationScript(script); 63 } 64 65 81 82 public void addBodyScript(String script) 83 { 84 _pageRenderSupport.addBodyScript(script); 85 } 86 87 94 95 public void addExternalScript(Resource scriptLocation) 96 { 97 _pageRenderSupport.addExternalScript(scriptLocation); 98 } 99 100 109 110 public static Body get(IRequestCycle cycle) 111 { 112 return (Body) TapestryUtils.getPageRenderSupport(cycle, null); 113 } 114 115 protected void prepareForRender(IRequestCycle cycle) 116 { 117 super.prepareForRender(cycle); 118 119 _pageRenderSupport = new PageRenderSupportImpl(getAssetFactory(), getResponse() 120 .getNamespace(), getLocation()); 121 } 122 123 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 124 { 125 TapestryUtils.storePageRenderSupport(cycle, this); 126 127 IMarkupWriter nested = writer.getNestedWriter(); 128 129 renderBody(nested, cycle); 130 131 writer.println(); 133 writer.begin(getElement()); 134 renderInformalParameters(writer, cycle); 135 136 writer.println(); 137 138 141 _pageRenderSupport.writeBodyScript(writer, cycle); 142 143 146 nested.close(); 147 148 153 _pageRenderSupport.writeInitializationScript(writer); 154 155 writer.end(); } 157 158 protected void cleanupAfterRender(IRequestCycle cycle) 159 { 160 super.cleanupAfterRender(cycle); 161 162 _pageRenderSupport = null; 163 164 TapestryUtils.removePageRenderSupport(cycle); 165 } 166 167 170 public abstract String getElement(); 171 172 177 public abstract AssetFactory getAssetFactory(); 178 179 184 185 public abstract WebResponse getResponse(); 186 187 188 189 public String getUniqueString(String baseValue) 190 { 191 return _pageRenderSupport.getUniqueString(baseValue); 192 } 193 194 } | Popular Tags |