You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Davanum Srinivas <di...@yahoo.com> on 2000/11/09 15:26:32 UTC

[XalanJ2][C2] javax.xml.tranform API

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);
    }
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);
     ....

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.

Thanks,
dims

--- Scott_Boag@lotus.com wrote:
> 
> You should be able to check out now and have 1:1 correspondence with the
> Xalan1 output for simple.xsp->xsp.xsl.  I'll be stepping through the
> conformance tests today to see if I can discover any more regressions.
> 
> -scott


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

Re: [XalanJ2][C2] javax.xml.tranform API

Posted by Gary L Peskin <ga...@firstech.com>.
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);
>     }
> 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);
>      ....
> 
> 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.


Dims --

I had these same problems when I first started working with the new
structure.  Have a look in javax.xml.transform.sax.  I think it has what
you're looking for.  For problem #2, look at

	ContentHander chandler = SAXTransformerFactory.newTemplatesHandler();
	...
	SAXResult.setHandler(content);
	...

You'll need to rework things a little but I think what you want will all
be in that package.

For problem #1, look at

	return SAXTransformerFactory.newXMLFilter(null);

or something like that.

Look at samples/trax/Examples.java.  It has lots of examples on using
the new classes.

HTH,
Gary

Re: [XalanJ2][C2] javax.xml.tranform API

Posted by Gary L Peskin <ga...@firstech.com>.
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

Re: [XalanJ2][C2] javax.xml.tranform API

Posted by Gary L Peskin <ga...@firstech.com>.
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