1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import org.apache.avalon.framework.parameters.Parameters; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 21 import org.apache.cocoon.ProcessingException; 22 import org.apache.cocoon.Constants; 23 import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode; 24 import org.apache.cocoon.components.treeprocessor.InvokeContext; 25 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 26 import org.apache.cocoon.environment.Environment; 27 import org.apache.commons.lang.SystemUtils; 28 29 35 public final class HandleErrorsNode extends AbstractParentProcessingNode { 36 37 private ProcessingNode[] children; 38 private int statusCode; 39 private boolean internal; 40 private boolean external; 41 42 46 public HandleErrorsNode(int statusCode, String scope) 47 throws ConfigurationException { 48 this.statusCode = statusCode; 49 if ("internal".equals(scope)) { 50 this.internal = true; 51 } else if ("external".equals(scope)) { 52 this.external = true; 53 } else if ("always".equals(scope)) { 54 this.internal = true; 55 this.external = true; 56 } else { 57 throw new ConfigurationException("Unrecognized value of when attribute on <handle-errors> at " + 58 getLocation()); 59 } 60 } 61 62 public int getStatusCode() { 63 return this.statusCode; 64 } 65 66 public boolean isInternal() { 67 return this.internal; 68 } 69 70 public boolean isExternal() { 71 return this.external; 72 } 73 74 public void setChildren(ProcessingNode[] nodes) { 75 this.children = nodes; 76 } 77 78 public final boolean invoke(Environment env, InvokeContext context) 79 throws Exception { 80 81 if (getLogger().isInfoEnabled()) { 82 getLogger().info("Processing handle-errors at " + getLocation()); 83 } 84 85 if (statusCode == -1) { 86 try { 88 return invokeNodes(this.children, env, context); 89 90 } catch (ProcessingException e) { 91 if (e.getMessage().indexOf("Must set a generator before adding") != -1) { 94 95 env.getObjectModel().remove(Constants.NOTIFYING_OBJECT); 96 throw new ProcessingException( 97 "Incomplete pipeline: 'handle-error' without a 'type' must include a generator, at " + 98 getLocation() + SystemUtils.LINE_SEPARATOR + 99 "Either add a generator (preferred) or a type='500' attribute (deprecated) on 'handle-errors'"); 100 } 101 102 throw e; 104 } 105 } else { 106 context.getProcessingPipeline().setGenerator("<notifier>", "", Parameters.EMPTY_PARAMETERS, Parameters.EMPTY_PARAMETERS); 108 109 try { 110 return invokeNodes(this.children, env, context); 111 } catch (ProcessingException e) { 112 if (e.getMessage().indexOf("Generator already set") != -1){ 113 114 env.getObjectModel().remove(Constants.NOTIFYING_OBJECT); 115 throw new ProcessingException( 116 "Error: 'handle-error' with a 'type' attribute has an implicit generator, at " + 117 getLocation() + SystemUtils.LINE_SEPARATOR + 118 "Please remove the 'type' attribute on 'handle-error'"); 119 } 120 throw e; 122 } 123 } 124 } 125 } 126 | Popular Tags |