View Javadoc
1 /* 2 * Angkor Web Framework 3 * 4 * Distributable under LGPL license. 5 * See terms of license at gnu.org. 6 */ 7 8 package com.tirsen.angkor.jsp; 9 10 import com.tirsen.angkor.Application; 11 import com.tirsen.angkor.Debug; 12 import com.tirsen.angkor.RenderContext; 13 import com.tirsen.angkor.View; 14 import com.tirsen.angkor.ViewFactory; 15 import com.tirsen.angkor.process.ExecuteContext; 16 import com.tirsen.angkor.process.Pipeline; 17 import com.tirsen.angkor.process.RenderValve; 18 import com.tirsen.angkor.process.Valve; 19 import org.apache.log4j.Category; 20 21 import java.util.Iterator; 22 import java.util.Map; 23 24 /*** 25 * <!-- $Id: PrerenderValve.java,v 1.3 2002/10/09 21:37:37 tirsen Exp $ --> 26 * <!-- $Author: tirsen $ --> 27 * 28 * @author Jon Tirs´n (tirsen@users.sourceforge.net) 29 * @version $Revision: 1.3 $ 30 */ 31 public class PrerenderValve extends RenderValve 32 { 33 private static final Category logger = Debug.getCategory(); 34 35 /*** 36 * The resulting {@link PrerenderedComponentsRegistry} resulting from this valve. 37 */ 38 public static final ExecuteContext.Attribute PrerenderedComponentsRegistryAttribute = new ExecuteContext.Attribute("PrerenderedComponentsRegistry"); 39 40 /*** 41 * Name of the component to be prerendered in the registry. 42 */ 43 private static final ExecuteContext.Attribute RegistryNameAttribute = new ExecuteContext.Attribute("RegistryName"); 44 45 public static class DoPrerenderValve implements Valve 46 { 47 public void execute(ExecuteContext exec) throws Exception 48 { 49 PrerenderedComponentsRegistry registry = (PrerenderedComponentsRegistry) exec.getAttribute(PrerenderedComponentsRegistryAttribute); 50 String name = (String) exec.getAttribute(RegistryNameAttribute); 51 View view = (View) exec.getAttribute(ExecuteContext.CurrentViewAttribute); 52 53 logger.debug("prerendering view " + name + " = " + view); 54 registry.prerender(name, view); 55 56 exec.executeNext(); 57 } 58 } 59 60 protected Pipeline createRenderPipeline() 61 { 62 Pipeline pipeline = super.createRenderPipeline(); 63 pipeline.addValve(new DoPrerenderValve()); 64 return pipeline; 65 } 66 67 public void execute(ExecuteContext exec) throws Exception 68 { 69 RenderContext context = (RenderContext) exec.getAttribute(ExecuteContext.RenderContextAttribute); 70 Application application = (Application) exec.getAttribute(ExecuteContext.ApplicationAttribute); 71 72 PrerenderedComponentsRegistry registry = new PrerenderedComponentsRegistry(context); 73 exec.setAttribute(PrerenderedComponentsRegistryAttribute, registry); 74 75 Map components = application.getComponentsToPrerender(); 76 Pipeline subPipeline = createRenderPipeline(); 77 for (Iterator iterator = components.entrySet().iterator(); iterator.hasNext();) 78 { 79 Map.Entry entry = (Map.Entry) iterator.next(); 80 ExecuteContext subExec = subPipeline.createSubContext(exec); 81 String name = (String) entry.getKey(); 82 subExec.setAttribute(RegistryNameAttribute, name); 83 if (entry.getValue() instanceof View) 84 { 85 subExec.setAttribute(ExecuteContext.CurrentViewAttribute, entry.getValue()); 86 } 87 else if (entry.getValue() instanceof ViewFactory) 88 { 89 subExec.setAttribute(ViewFactoryAttribute, entry.getValue()); 90 } 91 92 subPipeline.execute(subExec); 93 } 94 95 exec.executeNext(); 96 } 97 }

This page was automatically generated by Maven