1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import org.apache.avalon.framework.activity.Initializable; 19 import org.apache.avalon.framework.component.ComponentException; 20 import org.apache.avalon.framework.component.ComponentManager; 21 import org.apache.avalon.framework.component.Composable; 22 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode; 23 import org.apache.cocoon.components.treeprocessor.CategoryNode; 24 import org.apache.cocoon.components.treeprocessor.InvokeContext; 25 import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode; 26 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 27 import org.apache.cocoon.components.treeprocessor.variables.VariableResolver; 28 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory; 29 import org.apache.cocoon.environment.Environment; 30 31 import java.util.Map ; 32 33 38 39 public class CallNode extends AbstractProcessingNode 40 implements Initializable, ParameterizableProcessingNode, Composable { 41 42 private ComponentManager manager; 43 44 45 private Map parameters; 46 47 48 private String resourceName; 49 50 private VariableResolver resourceResolver; 51 52 53 private CategoryNode resources; 54 55 private ProcessingNode resourceNode; 56 57 public void compose(ComponentManager manager) throws ComponentException { 58 this.manager = manager; 59 } 60 61 public void setParameters(Map parameterMap) { 62 this.parameters = parameterMap; 63 } 64 65 public void setResource(CategoryNode resources, String resourceName) throws Exception { 66 this.resourceName = resourceName; 67 this.resources = resources; 68 } 69 70 public void initialize() throws Exception { 71 if (VariableResolverFactory.needsResolve(this.resourceName)) { 72 this.resourceResolver = VariableResolverFactory.getResolver(this.resourceName, this.manager); 74 } else { 75 this.resourceNode = this.resources.getNodeByName(VariableResolverFactory.unescape(this.resourceName)); 77 } 78 } 79 80 public final boolean invoke(Environment env, InvokeContext context) 81 throws Exception { 82 83 Map objectModel = env.getObjectModel(); 84 Map params = VariableResolver.buildMap(this.parameters, context, objectModel); 87 88 if (this.resourceNode != null) { 89 context.pushMap(null,params); 91 92 try { 93 return this.resourceNode.invoke(env, context); 94 } finally { 95 context.popMap(); 96 } 97 98 } else { 99 String name = this.resourceResolver.resolve(context, objectModel); 101 if (getLogger().isDebugEnabled()) { 102 getLogger().debug("Calling resource " + name); 103 } 104 105 context.pushMap(null,params); 107 108 try { 109 return this.resources.invokeByName(name, env, context); 110 } finally { 111 context.popMap(); 112 } 113 } 114 } 115 } 116 | Popular Tags |