1 package org.apache.turbine.pipeline; 2 3 56 57 import java.io.IOException ; 58 59 import org.apache.commons.logging.Log; 60 import org.apache.commons.logging.LogFactory; 61 import org.apache.commons.configuration.Configuration; 62 import org.apache.turbine.RunData; 63 import org.apache.turbine.TemplateContext; 64 import org.apache.turbine.Turbine; 65 import org.apache.turbine.TurbineException; 66 import org.apache.turbine.ValveContext; 67 import org.apache.turbine.modules.Module; 68 69 81 public class DefaultTargetValve 82 extends AbstractValve 83 { 84 private static final Log log = LogFactory.getLog(DefaultTargetValve.class); 85 86 protected static final String DEFAULT_MODULE_TYPE = "screens"; 87 88 protected String targetModuleType = DEFAULT_MODULE_TYPE; 89 90 95 public DefaultTargetValve() 96 { 97 98 } 99 100 101 102 105 public void initialize() throws Exception { 106 Configuration cfg = Turbine.getConfiguration(); 107 108 if (cfg != null) 109 { 110 targetModuleType = 112 cfg.getString("pipeline.default.targetModuleType", 113 DEFAULT_MODULE_TYPE); 114 } 115 } 116 119 public void invoke(RunData data, ValveContext context) 120 throws IOException , TurbineException 121 { 122 try 123 { 124 execute(data); 125 } 126 catch (Exception e) 127 { 128 throw new TurbineException(e); 129 } 130 131 context.invokeNext(data); 133 } 134 135 140 protected void execute(RunData data) 141 throws Exception 142 { 143 String target = data.getTarget(); 145 if ( target != null ) 146 { 147 data.getResponse().setLocale(data.getLocale()); 148 data.getResponse().setContentType(data.getContentType()); 149 150 TemplateContext context = Module.getTemplateContext( data ); 153 context.put( "template", target ); 154 155 157 String layout = Turbine.getResolver() 158 .getTemplate("layouts", target); 159 160 162 render( data, context, layout ); 163 } 164 else 165 { 166 if ( log.isDebugEnabled() ) 167 { 168 log.debug( "Target was null." ); 169 } 170 } 171 } 172 173 protected void render( RunData data, TemplateContext context, String target ) 174 throws Exception 175 { 176 if ( log.isDebugEnabled() ) 177 { 178 log.debug( "Rendering target " + target ); 179 } 180 181 Renderer r = new Renderer( data ); 182 183 185 context.put( "renderer", r ); 186 187 189 String out = r.render( target ); 190 191 193 data.getOut().print( out ); 194 } 195 } 196 197 | Popular Tags |