KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > sitemap > SitemapErrorHandler


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.sitemap;
17
18 import org.apache.cocoon.components.treeprocessor.InvokeContext;
19 import org.apache.cocoon.components.treeprocessor.sitemap.ErrorHandlerHelper;
20 import org.apache.cocoon.components.pipeline.ProcessingPipeline;
21 import org.apache.cocoon.environment.Environment;
22
23 /**
24  * Class providing error handling capabilities to the pipeline
25  * as configured in the sitemap.
26  *
27  * @since 2.1.7
28  * @version $Id: SitemapErrorHandler.java 157541 2005-03-15 14:26:31Z vgritsenko $
29  */

30 public class SitemapErrorHandler {
31     /**
32      * Error handler helper of the pipeline node
33      */

34     private ErrorHandlerHelper handler;
35
36     /**
37      * Environment of the pipeline node
38      */

39     private Environment environment;
40
41     /**
42      * Sitemap invocation context
43      */

44     private InvokeContext context;
45
46     // Environment state
47
private String JavaDoc envPrefix;
48     private String JavaDoc envURI;
49     private String JavaDoc envContext;
50
51     /**
52      * Construct error handler with everything needed to handle an error.
53      */

54     public SitemapErrorHandler(ErrorHandlerHelper handler,
55                                Environment environment,
56                                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 JavaDoc e) throws Exception JavaDoc {
71         // Restore environment state
72
this.environment.setContext(this.envPrefix, this.envURI, this.envContext);
73
74         return this.handler.invokeErrorHandler(e, this.environment, this.context);
75     }
76
77     /**
78      * Build error handling pipeline.
79      * @return error handling pipeline, or null if error was not handled.
80      */

81     public ProcessingPipeline prepareErrorPipeline(Exception JavaDoc e) throws Exception JavaDoc {
82         // Restore environment state
83
this.environment.setContext(this.envPrefix, this.envURI, this.envContext);
84
85         return this.handler.prepareErrorHandler(e, this.environment, this.context);
86     }
87 }
88
Popular Tags