cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davanum Srinivas <d...@yahoo.com>
Subject Re: [XalanJ2][C2] javax.xml.tranform API
Date Fri, 10 Nov 2000 12:44:43 GMT
Gary,
The newTransformerHandler/SAXResult combination worked. The XMLFilter code for replacing
TRaXFilter didn't. So changed our sources to use the newTransformerHandler/SAXResult combination
and cleaned up references to org.apache.xalan in C2.

Thanks,
dims
--- Gary L Peskin <garyp@firstech.com> wrote:
> Dims --
> 
> I was very unhappy with my original answer to you.  I really didn't know
> very much about the javax.xml.transform package when I wrote my answer. 
> So, your email spurred me on to sitting down and figuring it all out. 
> So, at least now, I've read everything through.  Please see my new
> answers below.
> 
> I apologize for giving you bad information and I thank you for inspiring
> me to figure this stuff out!
> 
> Gary
> 
> Davanum Srinivas wrote:
> > 
> > Thanks Scott. We bave updated C2 to use the new API. But there are some concerns.
I want to
> see if
> > i can use only the java.xml.transform package and nothing else. Right now this is
not
> possible,
> > Here's why...
> > 
> > Problem #1: We need an explicit import of "org.apache.xalan.transformer.TrAXFilter"
as we
> cache
> > templates and need to get an XMLFilter to work with in our code. We do this as follows:
> > 
> >     public XMLFilter getXMLFilter() throws TransformerConfigurationException
> >     {
> >        return new TrAXFilter(templates);
> >     }
> 
> My first answer here was obviously totally wrong.  I think you could
> implement this with cached templates like this:
> 
>   private SAXTransformerFactory transformerFactory = 
>                  (SAXTransformerFactory)
> TransformerFactory.newInstance();
> 
>   public XMLFilter getXMLFilter() throws
> TransformerConfigurationException
>   {
>     XMLFilter retFilter = new XMLFilterImpl();
>     TransformerHandler th =
> transformerFactory.newTransformerHandler(templates);
>     retFilter.setContentHandler(th);
>     return retFilter;
>   }
> 
> To improve performance, you might want to consider caching a pool of
> TransformerHandlers as well as templates.  TransformerHandler is not
> thread-safe so you'd need to maintain a pool of these.  Might be more
> trouble than it's worth in your environment.
> 
> > Problem #2: We need an explicit import of "org.apache.xalan.transformer.TransformerImpl"
as we
> > need access to getInputContentHandler() and setContentHandler(). We type cast as
shown below.
> > 
> >      ContentHandler chandler = ((TransformerImpl)transformer).getInputContentHandler();
> >      ....
> >      ((TransformerImpl)transformer).setContentHandler(content);
> >      ....
> 
> Another bogus answer from me.  I think here that you should be working
> with a TransformerHandler in the first place and not a Transformer. 
> Since TransformerHandler already extends ContentHandler, this should not
> be a problem.  If you're using a Transformer, I'd switch to a
> TransformerHandler.  You can always get a transformer from that by
> calling its getTransformer() method.
> 
> To set the TransformerHandler's ContentHandler, you need to use
> SAXResult as shown below.
> 
> So, if we have:
> 
>     private TransformerHandler th;
> 
> then
> 
>     ContentHandler chandler = th;
>     ....
>     th.setResult(new SAXResult(content));
>     ....
> 
> > 
> > To eliminate #1 and #2, Is it possible to do the following
> > 
> > - Add a newXMLFilter() in Templates which returns an XMLFilter
> > - Add a getInputContentHandler in Transformer which returns the ContentHandler
> > - Add a setContentHandler in Transformer which can take a ContentHandler as a parameter.
> 
> I don't think you need these anymore.
> 
> I feel much better about these answers and I'd appreciate any feedback
> that you could give.
> 
> Gary


=====
Davanum Srinivas, JNI-FAQ Manager
http://www.jGuru.com/faq/JNI

__________________________________________________
Do You Yahoo!?
Thousands of Stores.  Millions of Products.  All in one Place.
http://shopping.yahoo.com/

Mime
View raw message