Return-Path: Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Delivered-To: mailing list cocoon-dev@xml.apache.org Delivered-To: moderator for cocoon-dev@xml.apache.org Received: (qmail 29499 invoked from network); 10 Nov 2000 01:58:24 -0000 Received: from chicken.prod.itd.earthlink.net (207.217.120.114) by locus.apache.org with SMTP; 10 Nov 2000 01:58:24 -0000 Received: from firstech.com (hsa018.pool012.at001.earthlink.net [216.249.75.18]) by chicken.prod.itd.earthlink.net (8.9.3/8.9.3) with ESMTP id RAA26487; Thu, 9 Nov 2000 17:58:21 -0800 (PST) Message-ID: <3A0B5617.B42422C8@firstech.com> Date: Thu, 09 Nov 2000 17:57:43 -0800 From: Gary L Peskin Organization: The Firstech Corporation X-Mailer: Mozilla 4.76 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 To: xalan-dev@xml.apache.org, Davanum Srinivas CC: cocoon-dev@xml.apache.org Subject: Re: [XalanJ2][C2] javax.xml.tranform API References: <20001109142632.15088.qmail@web115.yahoomail.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N 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