1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import org.apache.avalon.framework.component.ComponentManager; 19 import org.apache.avalon.framework.component.Composable; 20 import org.apache.avalon.framework.logger.Logger; 21 22 import org.apache.cocoon.ConnectionResetException; 23 import org.apache.cocoon.ResourceNotFoundException; 24 import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode; 25 import org.apache.cocoon.components.treeprocessor.InvokeContext; 26 import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode; 27 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 28 import org.apache.cocoon.environment.Environment; 29 import org.apache.cocoon.sitemap.SitemapErrorHandler; 30 31 import java.util.Map ; 32 33 43 public class PipelineNode extends AbstractParentProcessingNode 44 implements Composable, ParameterizableProcessingNode { 45 46 49 private ProcessingNode[] children; 50 51 private ErrorHandlerHelper errorHandlerHelper; 52 53 private boolean internalOnly; 54 55 56 private boolean isLast; 57 58 59 protected String processingPipeline; 60 61 62 protected Map parameters; 63 64 68 public PipelineNode(String name) { 69 this.processingPipeline = name; 70 this.errorHandlerHelper = new ErrorHandlerHelper(); 71 } 72 73 76 public void compose(ComponentManager manager) { 77 this.errorHandlerHelper.compose(manager); 78 } 79 80 public void enableLogging(Logger logger) { 81 super.enableLogging(logger); 82 this.errorHandlerHelper.enableLogging(logger); 83 } 84 85 public void setChildren(ProcessingNode[] nodes) { 86 this.children = nodes; 87 } 88 89 public void setParameters(Map parameterMap) { 90 this.parameters = parameterMap; 91 } 92 93 public void setLast(boolean isLast) { 94 this.isLast = isLast; 95 } 96 97 public void set404Handler(ProcessingNode node) { 98 this.errorHandlerHelper.set404Handler(node); 99 } 100 101 public void set500Handler(ProcessingNode node) { 102 this.errorHandlerHelper.set500Handler(node); 103 } 104 105 public void setInternalOnly(boolean internalOnly) { 106 this.internalOnly = internalOnly; 107 } 108 109 public final boolean invoke(Environment env, InvokeContext context) 110 throws Exception { 111 boolean passThrough; 112 Object passThroughRaw = env.getAttribute(MountNode.COCOON_PASS_THROUGH); 113 if (passThroughRaw == null) { 114 passThrough = false; 116 } else { 117 passThrough = ((Boolean ) passThroughRaw).booleanValue(); 118 } 119 120 if (this.internalOnly && env.isExternal()) { 122 if (!this.isLast || passThrough) { 123 return false; 124 } 125 126 throw new ResourceNotFoundException("No pipeline matched request: " + 128 env.getURIPrefix() + env.getURI()); 129 } 130 131 context.inform(this.processingPipeline, this.parameters, env.getObjectModel()); 132 try { 133 if (this.errorHandlerHelper.isInternal()) { 134 context.setErrorHandler( 136 new SitemapErrorHandler(this.errorHandlerHelper, env, context)); 137 } else { 138 context.setErrorHandler(null); 140 } 141 142 if (invokeNodes(children, env, context)) { 143 return true; 144 } else if (!this.isLast || passThrough) { 145 return false; 146 } 147 148 throw new ResourceNotFoundException("No pipeline matched request: " + 149 env.getURIPrefix() + env.getURI()); 150 151 } catch (ConnectionResetException e) { 152 throw e; 154 } catch (Exception e) { 155 return this.errorHandlerHelper.invokeErrorHandler(e, env, context); 157 } 158 } 159 } 160 | Popular Tags |