Author: pier Date: Wed Sep 29 03:08:38 2004 New Revision: 47479 Added: cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/ErrorAwareTraxTransformer.java Log: A simple test that should improve error messages with xalan (for example, using this transformer the output of <xsl:message terminate="yes"/> becomes the message of the exception)
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/ErrorAwareTraxTransformer.java ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/ErrorAwareTraxTransformer.java Wed Sep 29 03:08:38 2004 @@ -0,0 +1,84 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cocoon.transformation; + +import javax.xml.transform.ErrorListener; +import javax.xml.transform.TransformerException; + +import org.apache.cocoon.xml.XMLConsumer; + +/** + * <p>An error aware TRAX-based transformer.</p> + * + * <p>This might be a very stupid extension to the [EMAIL PROTECTED] TraxTransformer}, but in + * some very specific cases (for example when using Apache Xalan-J 2), the message + * output of the stylesheets, and error messages, can be greatly improved by just + * using this class instead of the default one.</p> + * + * <p>Using this transformer with Apache Xalan-J 2, for example, will allow Cocoon + * to capture the output of <code><xsl:message&#nbsp;terminate="yes"/></code> + * and to serve it up using the standard error handling pipelines.</p> + * + * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a> + */ +public class ErrorAwareTraxTransformer extends TraxTransformer +implements ErrorListener { + + /** + * <p>Handle an error notification from the original TRAX transformer.</p> + * + * <p>This method simply throws the same exception passed in as a parameter.</p> + * + * @see ErrorListener#error(TransformerException) + */ + public void error(TransformerException exception) + throws TransformerException { + if (exception != null) throw(exception); + } + + /** + * <p>Handle an error notification from the original TRAX transformer.</p> + * + * <p>This method simply throws the same exception passed in as a parameter.</p> + * + * @see ErrorListener#fatalError(TransformerException) + */ + public void fatalError(TransformerException exception) + throws TransformerException { + if (exception != null) throw(exception); + } + + /** + * <p>Handle an error notification from the original TRAX transformer.</p> + * + * <p>This method simply throws the same exception passed in as a parameter.</p> + * + * @see ErrorListener#warning(TransformerException) + */ + public void warning(TransformerException exception) + throws TransformerException { + if (exception != null) throw(exception); + } + + /** + * Set the <code>XMLConsumer</code> that will receive XML data. + */ + public void setConsumer(XMLConsumer consumer) { + super.setConsumer(consumer); + super.transformerHandler.getTransformer().setErrorListener(this); + } +}