1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 import org.apache.cocoon.acting.Action; 21 import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder; 22 import org.apache.cocoon.components.treeprocessor.CategoryNode; 23 import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder; 24 import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder; 25 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 26 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory; 27 28 33 public class ActNodeBuilder extends AbstractParentProcessingNodeBuilder 34 implements LinkedProcessingNodeBuilder { 35 36 private ActSetNode actSetNode; 37 private String actSetName; 38 39 public ProcessingNode buildNode(Configuration config) throws Exception { 40 41 boolean inActionSet = this.treeBuilder.getAttribute(ActionSetNodeBuilder.IN_ACTION_SET) != null; 42 43 this.actSetName = config.getAttribute("set", null); 45 if (actSetName == null) { 46 47 if (inActionSet) { 48 Configuration children[] = config.getChildren(); 50 for (int i = 0; i < children.length; i++) { 51 String name = children[i].getName(); 52 if (!"act".equals(name) && !"parameter".equals(name)) { 53 throw new ConfigurationException("An action set can only contain actions and not '" 54 + name + "' at " + children[i].getLocation()); 55 } 56 } 57 } 58 59 String name = config.getAttribute("name", null); 60 String source = config.getAttribute("src", null); 61 String type = this.treeBuilder.getTypeForStatement(config, Action.ROLE + "Selector"); 62 63 ActTypeNode actTypeNode = new ActTypeNode( 64 type, 65 VariableResolverFactory.getResolver(source, this.manager), 66 name, 67 inActionSet 68 ); 69 this.treeBuilder.setupNode(actTypeNode, config); 70 71 actTypeNode.setChildren(buildChildNodes(config)); 72 73 return actTypeNode; 74 75 } else { 76 77 if (inActionSet) { 78 throw new ConfigurationException("Cannot call an action set from an action set at " + config.getLocation()); 79 } 80 81 if (config.getAttribute("src", null) != null) { 83 getLogger().warn("The 'src' attribute is ignored for action-set call at " + config.getLocation()); 84 } 85 this.actSetNode = new ActSetNode(); 86 this.treeBuilder.setupNode(this.actSetNode, config); 87 88 this.actSetNode.setChildren(buildChildNodes(config)); 89 90 return this.actSetNode; 91 } 92 } 93 94 public void linkNode() throws Exception { 95 96 if (this.actSetNode != null) { 97 CategoryNode actionSets = CategoryNodeBuilder.getCategoryNode(this.treeBuilder, "action-sets"); 99 100 if (actionSets == null) 101 throw new ConfigurationException("This sitemap contains no action sets. Cannot call at " + actSetNode.getLocation()); 102 103 ActionSetNode actionSetNode = (ActionSetNode)actionSets.getNodeByName(this.actSetName); 104 105 this.actSetNode.setActionSet(actionSetNode); 106 } 107 } 108 } 109 | Popular Tags |