1 package org.apache.turbine.modules; 2 3 56 57 import java.io.Writer ; 58 59 import org.apache.fulcrum.ServiceException; 60 import org.apache.fulcrum.TurbineServices; 61 import org.apache.fulcrum.template.TemplateService; 62 import org.apache.turbine.RunData; 63 import org.apache.turbine.TemplateContext; 64 import org.apache.turbine.Turbine; 65 import org.apache.turbine.services.pull.ApplicationTool; 66 import org.apache.turbine.services.pull.PullService; 67 68 83 public class Module 84 { 85 94 protected String doBuild( RunData data ) 95 throws Exception 96 { 97 doBuildTemplate(data); 98 return ""; 99 } 100 101 109 protected String build( RunData data ) 110 throws Exception 111 { 112 return doBuild( data ); 113 } 114 115 public String evaluate(RunData data) 116 throws Exception 117 { 118 return doBuild(data); 119 } 120 121 public void execute(RunData data) 122 throws Exception 123 { 124 doBuild(data); 125 } 126 127 134 protected void doBuildTemplate( RunData data, TemplateContext context) 135 throws Exception 136 { 137 } 138 139 protected void doBuildTemplate( RunData data ) 140 throws Exception 141 { 142 doBuildTemplate(data, getTemplateContext(data)); 143 } 144 145 151 public static TemplateContext getTemplateContext(RunData data) 152 { 153 TemplateContext context = 156 (TemplateContext) data.getTemp(Turbine.CONTEXT); 157 158 if (context == null) 159 { 160 context = getPullService().getRuntimeContext(data); 161 context.put ( "data", data ); 162 data.setTemp(Turbine.CONTEXT, context); 163 } 164 return context; 165 } 166 167 public static String handleRequest(TemplateContext context, String template) 168 throws ServiceException 169 { 170 return getTemplateService().handleRequest(new ContextAdapter(context), template); 171 } 172 173 public static void handleRequest(TemplateContext context, 174 String template, Writer writer) 175 throws ServiceException 176 { 177 getTemplateService().handleRequest(new ContextAdapter(context), 178 template, writer); 179 } 180 181 public static boolean templateExists(String template) 182 { 183 return getTemplateService().templateExists(template); 184 } 185 186 192 public static void requestFinished(TemplateContext context) 193 { 194 getPullService().releaseTools(context); 195 } 196 197 206 public static ApplicationTool getTool(TemplateContext context, 207 String name) 208 { 209 try 210 { 211 return (ApplicationTool) context.get(name); 212 } 213 catch (Exception e) 214 { 215 return null; 216 } 217 } 218 219 231 public static void setTemplate(RunData data, String template) 232 { 233 setTarget(data,template); 234 } 235 236 public static void setTarget(RunData data, String template) 237 { 238 data.setTarget(template); 239 } 240 241 247 protected static PullService getPullService() 248 { 249 return (PullService)TurbineServices 250 .getInstance().getService(PullService.SERVICE_NAME); 251 } 252 253 259 protected static TemplateService getTemplateService() 260 { 261 return (TemplateService)TurbineServices 262 .getInstance().getService(TemplateService.SERVICE_NAME); 263 } 264 } 265 | Popular Tags |