1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.thread.ThreadSafe; 20 import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder; 21 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 22 import org.apache.cocoon.components.treeprocessor.SimpleSelectorProcessingNode; 23 import org.apache.cocoon.components.treeprocessor.variables.VariableResolver; 24 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory; 25 import org.apache.cocoon.matching.Matcher; 26 import org.apache.cocoon.matching.PreparableMatcher; 27 28 33 34 public class MatchNodeBuilder extends AbstractParentProcessingNodeBuilder 35 implements ThreadSafe { 36 37 private static final String SELECTOR_ROLE = Matcher.ROLE + "Selector"; 38 39 public ProcessingNode buildNode(Configuration config) throws Exception { 40 41 String pattern = config.getAttribute("pattern", null); 42 String name = config.getAttribute("name", null); 43 44 String type = this.treeBuilder.getTypeForStatement(config, SELECTOR_ROLE); 45 46 ComponentsSelector selector = (ComponentsSelector)this.manager.lookup(SELECTOR_ROLE); 48 49 Class clazz = null; 50 try { 51 Matcher matcher = (Matcher)selector.select(type); 53 clazz = matcher.getClass(); 54 selector.release(matcher); 55 } finally { 56 this.manager.release(selector); 57 } 58 59 boolean preparable = 61 PreparableMatcher.class.isAssignableFrom(clazz) && 62 !VariableResolverFactory.needsResolve(pattern); 63 64 SimpleSelectorProcessingNode node; 66 VariableResolver patternResolver = VariableResolverFactory.getResolver(pattern, this.manager); 67 68 if (preparable) { 69 node = new PreparableMatchNode(type, VariableResolverFactory.unescape(pattern),name); 70 } else { 71 node = new MatchNode(type, patternResolver,name); 72 } 73 74 this.treeBuilder.setupNode(node, config); 75 76 ProcessingNode[] children = buildChildNodes(config); 78 79 node.setChildren(children); 80 81 return node; 82 } 83 } 84 | Popular Tags |