cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary L Peskin <ga...@firstech.com>
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!

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

Mime
View raw message