Hello.

"toadie D" <[EMAIL PROTECTED]> wrote on 2006-05-01 01:39:39 PM:
> Thanks for your reply.  I've tested out your suggestions by
> using an ErrorHandler
> (import org.apache.xml.utils.DefaultErrorHandler). 
>
> // get a Transformer
> SAXTransformerFactory tf = (SAXTransformerFactory)
> SAXTransformerFactory.newInstance();
> 
> // Make sure we trap all errors
> DefaultErrorHandler erh = new DefaultErrorHandler(); 
> tf.setErrorListener(erh);
> 
> as well as
> 
> TransformerHandler th = tf.newTransformerHandler(template);
> Transformer t = th.getTransformer();
> DefaultErrorHandler erh2 = new DefaultErrorHandler();
> t.setErrorListener(erh2);
> 
> and 
>   protected Templates getTemplates (InputStream in)
>   throws SAXException, TransformerConfigurationException
>   {
>     StreamSource ss = new StreamSource(in);
>     TransformerFactory tf = TransformerFactory.newInstance ();
>     DefaultErrorHandler erh = new DefaultErrorHandler(false);
>     tf.setErrorListener(erh); 
>     Templates t = tf.newTemplates(ss);
>     return (t);
>   } 
> 
> The same NPE is being thrown even with the ErrorHandler set.

     The argument to the DefaultErrorHandler(boolean) constructor 
indicates whether the TransformerException passed to either of the 
error(TransformerException) or fatalError(TransformerException) methods 
should be thrown.  Passing the value false suppresses the exceptions, 
which is the configuration of DefaultErrorHandler that the processor uses 
internally.

     By suppressing the exception, the processor is forced by the JAXP 1.3 
specification to create a Templates object that is meaningless, due to the 
parser error which occurs.

> 
> So out of curiosity, i changed the way i create a Transformer. 
> Instead of using Templates, i used StreamSource instead.
> 
>         // Templates  template = getTemplates(xsltStream);
>         // TransformerHandler th = tf.newTransformerHandler(template);
>         TransformerHandler th = tf.newTransformerHandler( new 
> StreamSource( xsltStream ) );
> 
> The NPE goes away and I am back to 2.5.1 behavior which is getting a
> javax.xml.transform.TransformerConfigurationException instead of NPE.
> 
> Any further thoughts ? 

In this, you used the zero-argument DefaultErrorHandler() constructor to 
set an error handler on the SAXTranformerFactory.  That constructor 
invokes the DefaultErrorHandler(boolean) constructor with the boolean 
value true, so it throws exceptions - in particular, the same 
TransformerConfigurationException you observed with 2.5.1.

     Use that same constructor in your getTemplates method, and you should 
get a TransformerConfigurationException.

     By the way, DefaultErrorHandler is not a public API of Xalan-Java, so 
it would be best not to rely on it for anything other than 
experimentation.

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro      Xalan development
IBM SWS Toronto Lab   T/L 969-6044;  Phone +1 905 413-6044
mailto:[EMAIL PROTECTED]


Reply via email to