1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import java.util.ArrayList ; 19 import java.util.List ; 20 21 import org.apache.avalon.framework.configuration.Configuration; 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 import org.apache.avalon.framework.thread.ThreadSafe; 24 import org.apache.cocoon.components.pipeline.ProcessingPipeline; 25 import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder; 26 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 27 import org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder; 28 29 36 public class PipelineNodeBuilder extends AbstractParentProcessingNodeBuilder 37 implements ThreadSafe { 38 39 40 protected boolean hasParameters() { 41 return true; 42 } 43 44 public ProcessingNode buildNode(Configuration config) 45 throws Exception { 46 String type = this.treeBuilder.getTypeForStatement(config, ProcessingPipeline.ROLE + "Selector"); 47 PipelineNode node = new PipelineNode(type); 48 49 this.treeBuilder.setupNode(node, config); 50 node.setInternalOnly(config.getAttributeAsBoolean("internal-only", false)); 51 52 ProcessingNode mainHandler = null; 54 55 ProcessingNode error404Handler = null; 57 ProcessingNode error500Handler = null; 58 59 Configuration[] childConfigs = config.getChildren(); 60 List children = new ArrayList (); 61 for (int i = 0; i < childConfigs.length; i++) { 62 Configuration childConfig = childConfigs[i]; 63 if (isChild(childConfig)) { 64 65 ProcessingNodeBuilder builder = this.treeBuilder.createNodeBuilder(childConfig); 66 if (builder instanceof HandleErrorsNodeBuilder) { 67 HandleErrorsNode handler = (HandleErrorsNode)builder.buildNode(childConfig); 69 int status = handler.getStatusCode(); 70 71 switch(status) { 72 case -1: if (mainHandler != null) { 74 throw new ConfigurationException("Duplicate <handle-errors> at " + handler.getLocation()); 75 } else if (error500Handler != null || error404Handler != null) { 76 throw new ConfigurationException("Cannot mix <handle-errors> with and without 'type' attribute at " + 77 handler.getLocation()); 78 } else { 79 mainHandler = handler; 80 } 81 break; 82 83 case 404: 84 if (error404Handler != null) { 85 throw new ConfigurationException("Duplicate <handle-errors type='404' at " + handler.getLocation()); 86 } else if(mainHandler != null) { 87 throw new ConfigurationException("Cannot mix <handle-errors> with and without 'type' attribute at " + 88 handler.getLocation()); 89 } else { 90 error404Handler = handler; 91 } 92 break; 93 94 case 500: 95 if (error500Handler != null) { 96 throw new ConfigurationException("Duplicate <handle-errors type='500' at " + handler.getLocation()); 97 } else if (mainHandler != null) { 98 throw new ConfigurationException("Cannot mix <handle-errors> with and without 'type' attribute at " + 99 handler.getLocation()); 100 } else { 101 error500Handler = handler; 102 } 103 break; 104 105 default: 106 throw new ConfigurationException("Unknown handle-errors type (" + type + ") at " + handler.getLocation()); 107 } 108 } else { 109 children.add(builder.buildNode(childConfig)); 111 } 112 } 113 } 114 115 node.setChildren(toNodeArray(children)); 116 node.set404Handler(error404Handler); 117 node.set500Handler(error500Handler == null ? mainHandler : error500Handler); 119 120 return node; 121 } 122 } 123 | Popular Tags |