You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by hu...@apache.org on 2002/08/04 19:54:10 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon ProcessingException.java

huber       2002/08/04 10:54:09

  Modified:    src/java/org/apache/cocoon ProcessingException.java
  Log:
  examine included throwable, for SAXParseException, and TransformerException output location information
  
  Revision  Changes    Path
  1.7       +66 -22    xml-cocoon2/src/java/org/apache/cocoon/ProcessingException.java
  
  Index: ProcessingException.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/ProcessingException.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ProcessingException.java	22 Feb 2002 07:03:48 -0000	1.6
  +++ ProcessingException.java	4 Aug 2002 17:54:09 -0000	1.7
  @@ -1,36 +1,36 @@
   /*
  -
  + 
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  -
  + 
    Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  -
  + 
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  -
  + 
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  -
  + 
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  -
  + 
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  -
  + 
    4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
       used to  endorse or promote  products derived from  this software without
       prior written permission. For written permission, please contact
       apache@apache.org.
  -
  + 
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  -
  + 
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -41,13 +41,13 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  + 
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
    Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  + 
  + */
   package org.apache.cocoon;
   
   import org.apache.avalon.framework.CascadingException;
  @@ -55,6 +55,10 @@
   import java.io.PrintStream;
   import java.io.PrintWriter;
   
  +import org.xml.sax.SAXParseException;
  +import javax.xml.transform.TransformerException;
  +import javax.xml.transform.SourceLocator;
  +
   /**
    * This Exception is thrown every time there is a problem in processing
    * a request.
  @@ -64,14 +68,14 @@
    * @version CVS $Id$
    */
   public class ProcessingException extends CascadingException {
  -
  +    
       /**
        * Construct a new <code>ProcessingException</code> instance.
        */
       public ProcessingException(String message) {
           super(message, null);
       }
  -
  +    
       /**
        * Creates a new <code>ProcessingException</code> instance.
        *
  @@ -80,7 +84,7 @@
       public ProcessingException(Exception ex) {
           super(ex.getMessage(), ex);
       }
  -
  +    
       /**
        * Construct a new <code>ProcessingException</code> that references
        * a parent Exception.
  @@ -88,29 +92,69 @@
       public ProcessingException(String message, Throwable t) {
           super(message, t);
       }
  -
  +    
       public String toString() {
           StringBuffer s = new StringBuffer();
           s.append(super.toString());
  -        if(getCause()!=null) {
  +        final Throwable t = getCause();
  +        if(t!=null) {
               s.append(": ");
  -            s.append(getCause().toString());
  +            // be more verbose try to get location info
  +            s.append( extraInfo(t) );
  +            s.append(t.toString());
           }
           return s.toString();
       }
  -
  +    
  +    /**
  +     * Examine Throwable and try to figure out location information.
  +     * <p>
  +     *   At the moment only SAXParseException, and TransformerException
  +     *   are considered.
  +     * </p>
  +     *
  +     * @return String containing location information of the format
  +     *  <code>{file-name}:{line}:{column}:</code>, if no location info is 
  +     *  available return empty string
  +     */
  +    private String extraInfo( Throwable t ) {
  +        StringBuffer sb = new StringBuffer();
  +        if (t instanceof SAXParseException) {
  +            SAXParseException spe = (SAXParseException)t;
  +            sb.append( String.valueOf(spe.getSystemId()));
  +            sb.append( ":" );
  +            sb.append( String.valueOf(spe.getLineNumber()));
  +            sb.append( ":" );
  +            sb.append( String.valueOf(spe.getColumnNumber()));
  +            sb.append( ":" );
  +        } else if (t instanceof TransformerException) {
  +            TransformerException transformerException = (TransformerException) t;
  +            SourceLocator sourceLocator = transformerException.getLocator();
  +            
  +            if( null != sourceLocator ) {
  +                sb.append( String.valueOf(sourceLocator.getSystemId()));
  +                sb.append( ":" );
  +                sb.append( String.valueOf(sourceLocator.getLineNumber()));
  +                sb.append( ":" );
  +                sb.append( String.valueOf(sourceLocator.getColumnNumber()));
  +                sb.append( ":" );
  +            }
  +        }
  +        return sb.toString();
  +    }
  +    
       public void printStackTrace() {
           super.printStackTrace();
           if(getCause()!=null)
               getCause().printStackTrace();
       }
  -
  +    
       public void printStackTrace( PrintStream s ) {
           super.printStackTrace(s);
           if(getCause()!=null)
               getCause().printStackTrace(s);
       }
  -
  +    
       public void printStackTrace( PrintWriter s ) {
           super.printStackTrace(s);
           if(getCause()!=null)
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org