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:
18: package org.apache.cocoon.generation;
19:
20: import net.sourceforge.chaperon.process.ParseException;
21:
22: import org.apache.cocoon.ProcessingException;
23: import org.apache.cocoon.environment.ObjectModelHelper;
24:
25: import org.apache.commons.lang.exception.ExceptionUtils;
26:
27: import org.exolab.castor.xml.MarshalException;
28: import org.exolab.castor.xml.Marshaller;
29: import org.exolab.castor.xml.ValidationException;
30:
31: import org.xml.sax.SAXException;
32:
33: import java.io.IOException;
34:
35: /**
36: * Exception generator.
37: *
38: * @version CVS $Id: ParseExceptionGenerator.java 433543 2006-08-22 06:22:54Z crossley $
39: */
40: public class ParseExceptionGenerator extends AbstractGenerator {
41: public void generate() throws IOException, SAXException,
42: ProcessingException {
43: Throwable throwable = ObjectModelHelper
44: .getThrowable(objectModel);
45:
46: while ((!(throwable instanceof ParseException))
47: && (ExceptionUtils.getCause(throwable) != null))
48: throwable = ExceptionUtils.getCause(throwable);
49:
50: if (!(throwable instanceof ParseException)) {
51: ((ParseException) throwable).toXML(super .contentHandler);
52: return;
53: }
54:
55: Marshaller marshaller = new Marshaller(super .contentHandler);
56:
57: try {
58: marshaller.marshal(throwable);
59: } catch (MarshalException me) {
60: throw new ProcessingException(me);
61: } catch (ValidationException ve) {
62: throw new ProcessingException(ve);
63: }
64: }
65: }
|