1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import org.apache.avalon.framework.configuration.Configurable; 19 import org.apache.avalon.framework.configuration.Configuration; 20 import org.apache.avalon.framework.configuration.ConfigurationException; 21 import org.apache.cocoon.components.flow.Interpreter; 22 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder; 23 import org.apache.cocoon.components.treeprocessor.CategoryNode; 24 import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder; 25 import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder; 26 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 27 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory; 28 29 35 public class CallNodeBuilder extends AbstractProcessingNodeBuilder 36 implements LinkedProcessingNodeBuilder { 37 38 protected ProcessingNode node; 39 protected String resourceName; 40 protected String functionName; 41 protected String continuationId; 42 43 public ProcessingNode buildNode(Configuration config) 44 throws Exception { 45 resourceName = config.getAttribute("resource", null); 46 functionName = config.getAttribute("function", null); 47 continuationId = config.getAttribute("continuation", null); 48 49 if (resourceName == null) { 50 if (functionName == null && continuationId == null) { 52 throw new ConfigurationException( 53 "<map:call> must have either a 'resource', 'function' or 'continuation' attribute, at " + 54 config.getLocation()); 55 } 56 57 node = new CallFunctionNode( 58 VariableResolverFactory.getResolver(functionName, this.manager), 59 VariableResolverFactory.getResolver(continuationId, this.manager) 60 ); 61 62 } else { 63 if (functionName != null || continuationId != null) { 65 throw new ConfigurationException( 66 "<map:call> cannot have both a 'resource' and a 'function' or 'continuation' attribute, at " 67 + config.getLocation() 68 ); 69 } 70 node = new CallNode(); 71 } 72 73 this.treeBuilder.setupNode(this.node, config); 74 if (node instanceof Configurable) { 75 ((Configurable)this.node).configure(config); 76 } 77 78 return this.node; 79 } 80 81 public void linkNode() throws Exception { 82 if (resourceName != null) { 83 CategoryNode resources 85 = CategoryNodeBuilder.getCategoryNode(treeBuilder, "resources"); 86 87 if (resources == null) 88 throw new ConfigurationException("This sitemap contains no resources. Cannot call at " + node.getLocation()); 89 90 ((CallNode)this.node).setResource(resources, this.resourceName); 91 } 92 else { 93 96 FlowNode flow = (FlowNode)treeBuilder.getRegisteredNode("flow"); 98 if (flow == null) 99 throw new ConfigurationException("This sitemap contains no control flows defined, cannot call at " + node.getLocation() + ". Define a control flow using <map:flow>, with embedded <map:script> elements."); 100 101 Interpreter interpreter = flow.getInterpreter(); 104 ((CallFunctionNode)node).setInterpreter(interpreter); 105 } 106 } 107 } 108 | Popular Tags |