Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-101

TransformerHandler not reusable

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.1.0
    • None
    • Security Level: No security risk; visible to anyone (Ordinary problems in Xalan projects. Anybody can view the issue.)
    • None
    • Operating System: All
      Platform: PC
    • 1205

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            slobo@matavnet.hu slobo
            Votes:
            5 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: