01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.sitemap;
18:
19: import org.apache.cocoon.components.treeprocessor.InvokeContext;
20: import org.apache.cocoon.components.treeprocessor.sitemap.ErrorHandlerHelper;
21: import org.apache.cocoon.components.pipeline.ProcessingPipeline;
22: import org.apache.cocoon.environment.Environment;
23:
24: /**
25: * Class providing error handling capabilities to the pipeline
26: * as configured in the sitemap.
27: *
28: * @since 2.1.7
29: * @version $Id: SitemapErrorHandler.java 433543 2006-08-22 06:22:54Z crossley $
30: */
31: public class SitemapErrorHandler {
32: /**
33: * Error handler helper of the pipeline node
34: */
35: private ErrorHandlerHelper handler;
36:
37: /**
38: * Environment of the pipeline node
39: */
40: private Environment environment;
41:
42: /**
43: * Sitemap invocation context
44: */
45: private InvokeContext context;
46:
47: // Environment state
48: private String envPrefix;
49: private String envURI;
50: private String envContext;
51:
52: /**
53: * Construct error handler with everything needed to handle an error.
54: */
55: public SitemapErrorHandler(ErrorHandlerHelper handler,
56: Environment environment, InvokeContext context) {
57: this .handler = handler;
58: this .environment = environment;
59: this .context = context;
60:
61: this .envPrefix = environment.getURIPrefix();
62: this .envURI = environment.getURI();
63: this .envContext = environment.getContext();
64: }
65:
66: /**
67: * Handle an error.
68: * @return true if error was handled.
69: */
70: public boolean handleError(Exception e) throws Exception {
71: // Restore environment state
72: this .environment.setContext(this .envPrefix, this .envURI,
73: this .envContext);
74:
75: return this .handler.invokeErrorHandler(e, this .environment,
76: this .context);
77: }
78:
79: /**
80: * Build error handling pipeline.
81: * @return error handling pipeline, or null if error was not handled.
82: */
83: public ProcessingPipeline prepareErrorPipeline(Exception e)
84: throws Exception {
85: // Restore environment state
86: this.environment.setContext(this.envPrefix, this.envURI,
87: this.envContext);
88:
89: return this.handler.prepareErrorHandler(e, this.environment,
90: this.context);
91: }
92: }
|