cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary L Peskin <>
Subject Re: [XalanJ2][C2] javax.xml.tranform API
Date Fri, 10 Nov 2000 01:57:43 GMT
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!


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
> 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 = 

  public XMLFilter getXMLFilter() throws
    XMLFilter retFilter = new XMLFilterImpl();
    TransformerHandler 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
>      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;


    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.


View raw message