Cocoon 3
  1. Cocoon 3
  2. COCOON3-6

The org.apache.cocoon.pipeline.component.sax.XSLTTransformer can be optimized

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0.0-alpha-2
    • Fix Version/s: 3.0.0-alpha-2
    • Component/s: cocoon-sax
    • Labels:
      None

      Description

      Every time the XSLTTransformer#setXMLConsumer method is called, the XSLT is parsed reading the URL source and used to create the javax.xml.transform.sax.TransformerHandler: to be more clear

      [...]
      XSLTTransformer xsltTransformer = new
      XSLTTransformer(getClass().getResource("myXSLT.xsl"));

      Pipeline pipeline1 = new NonCachingPipeline();
      pipeline1.addComponent(new StringGenerator("<x><y/></x>"));
      pipeline1.addComponent(xsltTransformer);
      pipeline1.addComponent(new XMLSerializer());
      pipeline1.setup(System.out);
      pipeline1.execute();

      Pipeline pipeline2 = new NonCachingPipeline();
      pipeline2.addComponent(new StringGenerator("<z><w/></z>"));
      pipeline2.addComponent(xsltTransformer); <========================== the URL pointed by getClass().getResource("myXSLT.xsl") will be parsed again!!!
      pipeline2.addComponent(new XMLSerializer());
      pipeline2.setup(System.out);
      pipeline2.execute();

      As a quick solution we can store the Template to build the transformer handler objects in a static hashmap, but in the future we should introduce stores.
      1. XSLTTransformerOptimization.patch
        8 kB
        Simone Tripodi
      2. OptimizedXSLT+xsltcTransformer.patch
        20 kB
        Simone Tripodi

        Activity

        Hide
        Simone Tripodi added a comment -
        The provided patch implements a static storage when Templates will be stored and retrieved to perform transformation operations.

        In that way, same transformers that point at same URL source, don't parse same URL twice; the Templates objects will be created just if it wasn't previously stored.
        Show
        Simone Tripodi added a comment - The provided patch implements a static storage when Templates will be stored and retrieved to perform transformation operations. In that way, same transformers that point at same URL source, don't parse same URL twice; the Templates objects will be created just if it wasn't previously stored.
        Hide
        Sylvain Wallez added a comment -
        This feature has been available in Cocoon for ages, storing Template objects in a LRU cache, and reloading stylesheets as needed when they have changed.

        Writing a new Cocoon is fine, but it should learn from the old one and reuse some of it.
        Show
        Sylvain Wallez added a comment - This feature has been available in Cocoon for ages, storing Template objects in a LRU cache, and reloading stylesheets as needed when they have changed. Writing a new Cocoon is fine, but it should learn from the old one and reuse some of it.
        Hide
        Simone Tripodi added a comment -
        Salut Sylvain!

        you're absolutely right! - can you suggest us please the oldest classes that can be reusable in this context? I'm new in Cocoon - and I'm not an Apache Committer - but I'm interested in helping you. Thank you in advance.

        A bientot!
        Show
        Simone Tripodi added a comment - Salut Sylvain! you're absolutely right! - can you suggest us please the oldest classes that can be reusable in this context? I'm new in Cocoon - and I'm not an Apache Committer - but I'm interested in helping you. Thank you in advance. A bientot!
        Show
        Sylvain Wallez added a comment - Have a look at http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-components/src/main/java/org/apache/cocoon/transformation/XSLTTransformer.java and all its dependencies.
        Hide
        Simone Tripodi added a comment -
        I developed a modified version of c3-sax default XSLT Transormer (see OptimizedXSLT+xsltcTransformer.patch) that allows component be reusable, i.e.

        XSLTTransformer xsltTransformer = new XSLTTransformer(getClass().getResource("myXSLT.xsl"));

        Pipeline pipeline1 = new NonCachingPipeline();
        pipeline1.addComponent(new StringGenerator("<x><y/></x>"));
        pipeline1.addComponent(xsltTransformer);
        pipeline1.addComponent(new XMLSerializer());
        pipeline1.setup(System.out);
        pipeline1.execute();

        Pipeline pipeline2 = new NonCachingPipeline();
        pipeline2.addComponent(new StringGenerator("<z><w/></z>"));
        pipeline2.addComponent(xsltTransformer); // the XSLT source URL won't be parsed again
        pipeline2.addComponent(new XMLSerializer());
        pipeline2.setup(System.out);
        pipeline2.execute();

        Moreover, it supports Xalan XSLTC (see http://xml.apache.org/xalan-j/xsltc_usage.html).

        Patch contains test cases and the useless cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTProcessorErrorListener.java has been removed since it was a TraxErrorListener 'clone' and not used.
        Show
        Simone Tripodi added a comment - I developed a modified version of c3-sax default XSLT Transormer (see OptimizedXSLT+xsltcTransformer.patch) that allows component be reusable, i.e. XSLTTransformer xsltTransformer = new XSLTTransformer(getClass().getResource("myXSLT.xsl")); Pipeline pipeline1 = new NonCachingPipeline(); pipeline1.addComponent(new StringGenerator("<x><y/></x>")); pipeline1.addComponent(xsltTransformer); pipeline1.addComponent(new XMLSerializer()); pipeline1.setup(System.out); pipeline1.execute(); Pipeline pipeline2 = new NonCachingPipeline(); pipeline2.addComponent(new StringGenerator("<z><w/></z>")); pipeline2.addComponent(xsltTransformer); // the XSLT source URL won't be parsed again pipeline2.addComponent(new XMLSerializer()); pipeline2.setup(System.out); pipeline2.execute(); Moreover, it supports Xalan XSLTC (see http://xml.apache.org/xalan-j/xsltc_usage.html) . Patch contains test cases and the useless cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTProcessorErrorListener.java has been removed since it was a TraxErrorListener 'clone' and not used.
        Hide
        Reinhard Poetz added a comment -
        Thanks Simone four your work on this next step in order to improve the XSLT transformer.
        Show
        Reinhard Poetz added a comment - Thanks Simone four your work on this next step in order to improve the XSLT transformer.

          People

          • Assignee:
            Reinhard Poetz
            Reporter:
            Simone Tripodi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development