costin      01/01/24 11:54:14

  Modified:    java/src/org/apache/xalan/processor
                        TransformerFactoryImpl.java
  Log:
  Bug fix: the spec requires that if an ErrorListener is set on the
  TransformerFactory, it should receive notification of the errors,
  instead of throwing the exceptions.
  
  Since all exceptions in creating the transformer prevent further operation,
  fatalError() callback is used.
  
  The code is a bit complex - various exceptions are wrapped into
  TransformerException ( required by ErrorListener signature ) and the
  exception propagated by ErrorListener are re-wrapped in what the original
  method expects.
  ( an ErrorListener could either re-throw the original exception or do 
something
  else )
  
  ( this fix should solve the common case of an exception during Transformer
  creation. In future we may want to pass the ErrorListener and send
  warning notifications, etc - that would require too much change at this
  stage and it's not required by the spec. )
  
  Revision  Changes    Path
  1.21      +75 -18    
xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java
  
  Index: TransformerFactoryImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TransformerFactoryImpl.java       2001/01/04 17:04:49     1.20
  +++ TransformerFactoryImpl.java       2001/01/24 19:54:12     1.21
  @@ -210,12 +210,19 @@
       }
       catch (org.xml.sax.SAXException se)
       {
  -
  -      // Should remove this later... but right now diagnostics from 
  -      // TransformerConfigurationException are not good.
  -      // se.printStackTrace();
  -      throw new TransformerConfigurationException("processFromNode failed",
  -                                                  se);
  +      if( m_errorListener != null ) {
  +     try {
  +       m_errorListener.fatalError( new TransformerException( se ) );
  +     } catch( TransformerException ex ) {
  +       throw new TransformerConfigurationException( ex );
  +     }
  +     return null;
  +      } else
  +     // Should remove this later... but right now diagnostics from 
  +     // TransformerConfigurationException are not good.
  +     // se.printStackTrace();
  +     throw new TransformerConfigurationException("processFromNode failed",
  +                                                 se);
       }
     }
   
  @@ -495,7 +502,19 @@
     public XMLFilter newXMLFilter(Templates templates)
             throws TransformerConfigurationException
     {
  -    return new TrAXFilter(templates);
  +    try {
  +      return new TrAXFilter(templates);
  +    } catch( TransformerConfigurationException ex ) {
  +      if( m_errorListener != null) {
  +     try {
  +       m_errorListener.fatalError( ex );
  +       return null;
  +     } catch( TransformerException ex1 ) {
  +       new TransformerConfigurationException(ex1);
  +     }
  +      }
  +      throw ex;
  +    }
     }
   
     /**
  @@ -530,13 +549,25 @@
     public TransformerHandler newTransformerHandler(Templates templates)
             throws TransformerConfigurationException
     {
  -
  -    TransformerImpl transformer =
  -      (TransformerImpl) templates.newTransformer();
  -    TransformerHandler th =
  -      (TransformerHandler) transformer.getInputContentHandler(true);
  -
  -    return th;
  +    try {
  +      TransformerImpl transformer =
  +     (TransformerImpl) templates.newTransformer();
  +      TransformerHandler th =
  +     (TransformerHandler) transformer.getInputContentHandler(true);
  +
  +      return th;
  +    } catch( TransformerConfigurationException ex ) {
  +      if( m_errorListener != null ) {
  +     try {
  +       m_errorListener.fatalError( ex );
  +       return null;
  +     } catch (TransformerException ex1 ) {
  +       ex=new TransformerConfigurationException(ex1);
  +     }
  +      }
  +      throw ex;
  +    }
  +    
     }
   
   //  /** The identity transform string, for support of newTransformerHandler()
  @@ -597,8 +628,19 @@
     public Transformer newTransformer(Source source)
             throws TransformerConfigurationException
     {
  -
  -    return newTemplates(source).newTransformer();
  +    try {
  +      return newTemplates(source).newTransformer();
  +    } catch( TransformerConfigurationException ex ) {
  +      if( m_errorListener != null ) {
  +     try {
  +       m_errorListener.fatalError( ex );
  +       return null;
  +     } catch( TransformerException ex1 ) {
  +       ex=new TransformerConfigurationException( ex1 );
  +     }
  +      }
  +      throw ex;
  +    }
     }
   
     /**
  @@ -742,11 +784,26 @@
       }
       catch (IOException ioe)
       {
  -      throw new TransformerConfigurationException(ioe.getMessage(), ioe);
  +      if( m_errorListener != null ) {
  +     try {
  +       m_errorListener.fatalError( new TransformerException(ioe) );
  +       return null;
  +     } catch( TransformerException ex1 ) {
  +       throw new TransformerConfigurationException( ex1 );
  +     }
  +      } else 
  +     throw new TransformerConfigurationException(ioe.getMessage(), ioe);
       }
       catch (org.xml.sax.SAXException se)
       {
  -      throw new TransformerConfigurationException(se.getMessage(), se);
  +      if( m_errorListener != null ) {
  +     try {
  +       m_errorListener.fatalError( new TransformerException(se) );
  +     } catch( TransformerException ex1 ) {
  +       throw new TransformerConfigurationException( ex1 );
  +     }
  +      } else 
  +     throw new TransformerConfigurationException(se.getMessage(), se);
       }
   
       return builder.getTemplates();
  
  
  

Reply via email to