You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2001/04/04 01:43:31 UTC

[Bug 1205] New - TransformerHandler not reusable

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1205

*** shadow/1205	Tue Apr  3 16:43:31 2001
--- shadow/1205.tmp.22659	Tue Apr  3 16:43:31 2001
***************
*** 0 ****
--- 1,56 ----
+ +============================================================================+
+ | TransformerHandler not reusable                                            |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 1205                        Product: XalanJ2                 |
+ |       Status: NEW                         Version: 2.0.1                   |
+ |   Resolution:                            Platform: PC                      |
+ |     Severity: Normal                   OS/Version:                         |
+ |     Priority:                           Component: org.apache.xalan.transf |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: xalan-dev@xml.apache.org                                     |
+ |  Reported By: slobo@matavnet.hu                                            |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ import java.io.FileInputStream;
+ import javax.xml.transform.Templates;
+ import javax.xml.transform.sax.SAXTransformerFactory;
+ import javax.xml.transform.sax.TransformerHandler;
+ import javax.xml.transform.stream.StreamSource;
+ import javax.xml.transform.stream.StreamResult;
+ import org.xml.sax.helpers.AttributesImpl;
+ 
+ public class Test {
+ 
+ 	public static void main(String[] args) {
+ 		try {
+ 			SAXTransformerFactory f = (SAXTransformerFactory)
+ SAXTransformerFactory.newInstance();
+ 			Templates t = f.newTemplates(new StreamSource(new 
+ FileInputStream("in.xsl")));
+ 			TransformerHandler th = f.newTransformerHandler(t);
+ 			th.setResult(new StreamResult(System.out));
+ 
+ 			th.startDocument();
+ 			th.startElement("","foo","foo",new AttributesImpl());
+ 			th.endElement("","foo","foo");
+ 			th.endDocument();
+ 
+ 			th.startDocument();
+ 			th.startElement("","foo","foo",new AttributesImpl());
+ 			th.endElement("","foo","foo");
+ 			th.endDocument();
+ 		} catch(Exception e) {
+ 			e.printStackTrace();
+ 		}
+ 	}
+ }
+ 
+ If you run this code with any valid in.xsl file, the template is instantiated 
+ only once.
+ It's true, that in JAXP-1.1 specification it is not explicitly stated that 
+ TransformerHandlers should be reusable, but it is stated that Transformers 
+ should be reusable, and my opinion is that it would be reasonable and natural 
+ to be able to reuse TransformerHandlers as well.