1 16 package org.apache.cocoon.components.treeprocessor; 17 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 22 23 import org.apache.avalon.framework.configuration.Configurable; 24 import org.apache.avalon.framework.configuration.Configuration; 25 import org.apache.avalon.framework.configuration.ConfigurationException; 26 import org.apache.avalon.framework.thread.ThreadSafe; 27 28 34 35 public class CategoryNodeBuilder extends AbstractParentProcessingNodeBuilder 36 implements Configurable, ThreadSafe { 37 38 private static String PREFIX = CategoryNodeBuilder.class.getName() + "/"; 40 41 protected String name; 42 43 47 public void configure(Configuration config) throws ConfigurationException { 48 super.configure(config); 49 this.name = config.getChild("category-name").getValue(config.getAttribute("name")); 50 } 51 52 53 protected boolean hasParameters() { 54 return false; 55 } 56 57 public ProcessingNode buildNode(Configuration config) throws Exception { 58 59 CategoryNode node = new CategoryNode(); 60 this.treeBuilder.setupNode(node, config); 61 62 Map category = new HashMap (); 64 65 List children = buildChildNodesList(config); 66 Iterator iter = children.iterator(); 67 while(iter.hasNext()) { 68 NamedProcessingNode child = (NamedProcessingNode)iter.next(); 69 category.put(child.getName(), child); 70 } 71 72 node.setCategory(this.name, category); 73 74 if ( !this.treeBuilder.registerNode(PREFIX + this.name, node) ) { 76 throw new ConfigurationException("Only one <map:" + this.name + 77 "> is allowed in a sitemap. Another one is declared at " + 78 config.getLocation()); 79 } 80 81 return node; 82 } 83 84 public static CategoryNode getCategoryNode(TreeBuilder builder, String categoryName) { 85 return (CategoryNode)builder.getRegisteredNode(PREFIX + categoryName); 86 } 87 88 public static ProcessingNode getNamedNode(TreeBuilder builder, String categoryName, String nodeName) 89 throws Exception { 90 CategoryNode category = getCategoryNode(builder, categoryName); 91 92 return category.getNodeByName(nodeName); 93 } 94 } 95 | Popular Tags |