cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/transformation TraxTransformer.java
Date Wed, 10 Oct 2001 17:03:39 GMT
sylvain     01/10/10 10:03:39

  Modified:    documentation/xdocs/userdocs/transformers
                        xslt-transformer.xml
               src/org/apache/cocoon/components/xslt XSLTProcessorImpl.java
               src/org/apache/cocoon/transformation TraxTransformer.java
  Log:
  Small changes to allow to use simultaneously xalan and saxon in a controlled way.
  
  Revision  Changes    Path
  1.2       +15 -0     xml-cocoon2/documentation/xdocs/userdocs/transformers/xslt-transformer.xml
  
  Index: xslt-transformer.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/documentation/xdocs/userdocs/transformers/xslt-transformer.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- xslt-transformer.xml	2001/09/28 13:41:31	1.1
  +++ xslt-transformer.xml	2001/10/10 17:03:39	1.2
  @@ -9,6 +9,7 @@
   		<type>Technical document</type>
   		<authors>
   			<person name="Carsten Ziegeler" email="cziegeler@apache.org"/>
  +			<person name="Sylvain Wallez" email="sylvain@apache.org"/>
   		 </authors>
   		 <abstract>This document describes the xslt transformer of @docname@.</abstract>
   	</header>
  @@ -37,6 +38,15 @@
                           Note that this might have issues concerning cachability of the
generated output of this
                           transformer as the caching algorithm adds this values to the validation
phase.
                           The default for this property is false.</li>
  +				<li>use-cookies: true|false - This configuration forces the transformer to make
all
  +								cookies from the request available in the XSLT stylesheetas.
  +								Note that this might have issues concerning cachability of the generated output
of this
  +								transformer. This property is false by default.</li>
  +				<li>xslt-processor: [role name] - This configuration allows to specify the XSLT
processor (see below)
  +			 		that will be used by its role name. This allows to have several XSLT processors in
the configuration
  +					(e.g. Xalan and Saxon) and choose one or the other depending on the needs of stylesheet
  +					specificities. This property defaults to "org.apache.cocoon.components.xslt.XSLTProcessor"
  +					which is the standard role name for an XSLTProcessor.</li>
   			</ul>
   			<p>The "use-request-parameters" and "use-browser-capabilities-db" configuration
                        of a transformer can be changed for one single pipeline by specifying
  @@ -68,6 +78,11 @@
   				<li>use-store: true|false -  If set to true it forces the xslt processor 
                           to put the generated templates from the XSLT stylesheet into the
    				system store. This property is true by default.</li>
  +				<li>transformer-factory: [class name] - tells the transformer to use a particular
  +					implementation of javax.xml.transform.TransformerFactory. This allows to force the
use of
  +					a given TRAX implementation (e.g. xalan or saxon) if several are available in the
classpath.
  +					If this property is not set, the transformer uses the standard TRAX mechanism
  +					(TransformerFactory.newInstance()).</li>
   			</ul>
   		</s1>
   	</body>
  
  
  
  1.8       +68 -33    xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java
  
  Index: XSLTProcessorImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XSLTProcessorImpl.java	2001/10/08 20:03:16	1.7
  +++ XSLTProcessorImpl.java	2001/10/10 17:03:39	1.8
  @@ -7,36 +7,37 @@
    *****************************************************************************/
   package org.apache.cocoon.components.xslt;
   
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.logger.AbstractLoggable;
  -import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.components.store.Store;
  -import org.apache.cocoon.environment.Source;
  -import org.apache.cocoon.environment.SourceResolver;
  -import org.apache.cocoon.util.TraxErrorHandler;
  -import org.xml.sax.InputSource;
  -import org.xml.sax.XMLFilter;
  -import org.xml.sax.XMLReader;
  -import org.xml.sax.helpers.XMLReaderFactory;
  -
  -import javax.xml.transform.*;
  -import javax.xml.transform.sax.SAXSource;
  -import javax.xml.transform.sax.SAXTransformerFactory;
  -import javax.xml.transform.sax.TemplatesHandler;
  -import javax.xml.transform.sax.TransformerHandler;
  -import javax.xml.transform.stream.StreamResult;
  -import javax.xml.transform.stream.StreamSource;
  -import java.io.File;
  -import java.io.IOException;
  -import java.io.StringWriter;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.component.ComponentException;
  +import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.component.Composable;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.logger.AbstractLoggable;
  +import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.components.store.Store;
  +import org.apache.cocoon.environment.Source;
  +import org.apache.cocoon.environment.SourceResolver;
  +import org.apache.cocoon.util.ClassUtils;
  +import org.apache.cocoon.util.TraxErrorHandler;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.XMLFilter;
  +import org.xml.sax.XMLReader;
  +import org.xml.sax.helpers.XMLReaderFactory;
  +
  +import javax.xml.transform.*;
  +import javax.xml.transform.sax.SAXSource;
  +import javax.xml.transform.sax.SAXTransformerFactory;
  +import javax.xml.transform.sax.TemplatesHandler;
  +import javax.xml.transform.sax.TransformerHandler;
  +import javax.xml.transform.stream.StreamResult;
  +import javax.xml.transform.stream.StreamSource;
  +import java.io.File;
  +import java.io.IOException;
  +import java.io.StringWriter;
   import java.io.Writer;
   
   /**
  @@ -49,12 +50,19 @@
    * <pre>
    * &lt;xslt-processor class="org.apache.cocoon.components.xslt.XSLTProcessorImpl"&gt;
    *    &lt;parameter name="use-store" value="true"/&gt;
  + *    &lt;parameter name="transformer-factory" value="org.apache.xalan.processor.TransformerFactoryImpl"/&gt;
    * &lt;/xslt-processor&gt;
    * </pre>
    *
    * The &lt;use-store&gt; configuration forces the transformer to put the
    * <code>Templates</code> generated from the XSLT stylesheet into the
    * <code>Store</code>. This property is true by default.
  + * <p>
  + * The &lt;transformer-factory&gt; configuration tells the transformer to use a
particular
  + * implementation of <code>javax.xml.transform.TransformerFactory</code>. This
allows to force
  + * the use of a given TRAX implementation (e.g. xalan or saxon) if several are available
in the
  + * classpath. If this property is not set, the transformer uses the standard TRAX mechanism
  + * (<code>TransformerFactory.newInstance()</code>).
    *
    * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
    * @version 1.0
  @@ -71,6 +79,9 @@
   
     /** The trax TransformerFactory */
     SAXTransformerFactory tfactory;
  +  
  +  /** The factory class used to create tfactory */
  +  Class tfactoryClass;
   
     /** Is the store turned on? (default is on) */
     boolean useStore = true;
  @@ -97,6 +108,26 @@
     {
       Parameters params = Parameters.fromConfiguration(conf);
       useStore = params.getParameterAsBoolean("use-store", true);
  +    
  +    String factoryName = params.getParameter("transformer-factory", null);
  +    
  +    if (factoryName == null) {
  +      // Will use default TRAX mechanism
  +      this.tfactoryClass = null;
  +      
  +    } else {
  +      // Will use specific class
  +      getLogger().debug("Using factory " + factoryName);
  +      try {
  +        this.tfactoryClass = ClassUtils.loadClass(factoryName);
  +      } catch(ClassNotFoundException cnfe) {
  +        throw new ConfigurationException("Cannot load TransformerFactory class", cnfe);
  +      }
  +    
  +      if (! TransformerFactory.class.isAssignableFrom(tfactoryClass)) {
  +        throw new ConfigurationException("Class " + factoryName + " isn't a TransformerFactory");
  +      }
  +    }
     }
   
     public TransformerHandler getTransformerHandler(Source stylesheet)
  @@ -217,10 +248,14 @@
     /**
      * Helper for TransformerFactory.
      */
  -  private SAXTransformerFactory getTransformerFactory()
  +  private SAXTransformerFactory getTransformerFactory() throws Exception
     {
       if(tfactory == null) {
  -      tfactory = (SAXTransformerFactory)TransformerFactory.newInstance();
  +      if (tfactoryClass == null) {
  +        tfactory = (SAXTransformerFactory)TransformerFactory.newInstance();
  +      } else {
  +        tfactory = (SAXTransformerFactory)tfactoryClass.newInstance();
  +      }
         tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
         tfactory.setURIResolver(this);
       }
  @@ -265,7 +300,7 @@
           store.remove(is.getSystemId());
         }
       }
  -    return templates;
  +   return templates;
     }
   
     private void putTemplates (Templates templates, Source stylesheet)
  
  
  
  1.34      +68 -48    xml-cocoon2/src/org/apache/cocoon/transformation/TraxTransformer.java
  
  Index: TraxTransformer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/TraxTransformer.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- TraxTransformer.java	2001/10/08 20:03:21	1.33
  +++ TraxTransformer.java	2001/10/10 17:03:39	1.34
  @@ -7,35 +7,36 @@
    *****************************************************************************/
   package org.apache.cocoon.transformation;
   
  -import org.apache.avalon.excalibur.pool.Recyclable;
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.logger.Loggable;
  -import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.cocoon.Constants;
  -import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.caching.CacheValidity;
  -import org.apache.cocoon.caching.Cacheable;
  -import org.apache.cocoon.caching.TimeStampCacheValidity;
  -import org.apache.cocoon.components.browser.Browser;
  -import org.apache.cocoon.components.xslt.XSLTProcessor;
  -import org.apache.cocoon.environment.Cookie;
  -import org.apache.cocoon.environment.Request;
  -import org.apache.cocoon.environment.Source;
  -import org.apache.cocoon.environment.SourceResolver;
  -import org.apache.cocoon.util.HashUtil;
  -import org.apache.cocoon.xml.XMLConsumer;
  -import org.xml.sax.SAXException;
  -
  -import javax.xml.transform.sax.SAXResult;
  -import javax.xml.transform.sax.TransformerHandler;
  -import java.io.IOException;
  -import java.text.StringCharacterIterator;
  +import org.apache.avalon.excalibur.pool.Recyclable;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.component.ComponentException;
  +import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.component.Composable;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.logger.Loggable;
  +import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.cocoon.Constants;
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.caching.CacheValidity;
  +import org.apache.cocoon.caching.Cacheable;
  +import org.apache.cocoon.caching.TimeStampCacheValidity;
  +import org.apache.cocoon.components.browser.Browser;
  +import org.apache.cocoon.components.xslt.XSLTProcessor;
  +import org.apache.cocoon.environment.Cookie;
  +import org.apache.cocoon.environment.Request;
  +import org.apache.cocoon.environment.Source;
  +import org.apache.cocoon.environment.SourceResolver;
  +import org.apache.cocoon.util.HashUtil;
  +import org.apache.cocoon.xml.XMLConsumer;
  +import org.xml.sax.SAXException;
  +
  +import javax.xml.transform.sax.SAXResult;
  +import javax.xml.transform.sax.TransformerHandler;
  +import java.io.IOException;
  +import java.text.StringCharacterIterator;
   import java.util.*;
   
   /**
  @@ -44,30 +45,45 @@
    * and parameterize it:
    *
    * <b>In the map:sitemap/map:components/map:transformers:</b><br>
  - *
  + * <pre>
    * &lt;map:transformer name="xslt" src="org.apache.cocoon.transformation.TraxTransformer"&gt;<br>
    *   &lt;use-request-parameters&gt;false&lt;/use-request-parameters&gt;
    *   &lt;use-browser-capabilities-db&gt;false&lt;/use-browser-capabilities-db&gt;
  + *   &lt;xslt-processor&gt;org.apache.cocoon.components.xslt.XSLTProcessor&lt;/xslt-processor&gt;
    * &lt;/map:transformer&gt;
  + * </pre>
    *
    * The &lt;use-request-parameter&gt; configuration forces the transformer to make
all
    * request parameters available in the XSLT stylesheet. Note that this might have issues
  - * concerning cachability of the generated output of this transformer.
  + * concerning cachability of the generated output of this transformer.<br>
    * This property is false by default.
  - *
  + * <p>
    * The &lt;use-browser-capabilities-db&gt; configuration forces the transformer
to make all
    * properties from the browser capability database available in the XSLT stylesheetas.
  + * Note that this might have issues concerning cachability of the generated output of this
  + * transformer.<br>
  + * This property is false by default.
  + * <p>
  + * The &lt;use-cookies&gt; configuration forces the transformer to make all
  + * cookies from the request available in the XSLT stylesheetas.
    * Note that this might have issues concerning cachability of the generated output of this
  - * transformer.
  + * transformer.<br>
    * This property is false by default.
    *
  + * The &lt;xslt-processor&gt; configuration allows to specify the XSLT processor
that will be
  + * used by its role name. This allows to have several XSLT processors in the configuration
  + * (e.g. Xalan and Saxon) and choose one or the other depending on the needs of stylesheet
  + * specificities.<br>
  + * This property defaults to "org.apache.cocoon.components.xslt.XSLTProcessor" which is
the
  + * standard role name for an XSLTProcessor.
  + * <p>
    * <b>In a map:sitemap/map:pipelines/map:pipeline:</b><br>
  - *
  + * <pre>
    * &lt;map:transform type="xslt" src="stylesheets/yours.xsl"&gt;<br>
    *   &lt;parameter name="myparam" value="myvalue"/&gt;
    * &lt;/map:transform&gt;
  - *
  - * All <parameter> declarations will be made available in the XSLT stylesheet as
  + * </pre>
  + * All &lt;parameter&gt; declarations will be made available in the XSLT stylesheet
as
    * xsl:variables.
    *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  @@ -76,7 +92,7 @@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
    * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
  - * @version CVS $Id: TraxTransformer.java,v 1.33 2001/10/08 20:03:21 bloritsch Exp $
  + * @version CVS $Id: TraxTransformer.java,v 1.34 2001/10/10 17:03:39 sylvain Exp $
    */
   public class TraxTransformer extends AbstractTransformer
   implements Transformer, Composable, Recyclable, Configurable, Cacheable, Disposable {
  @@ -134,6 +150,16 @@
             this.useBrowserCap = child.getValueAsBoolean(false);
             this._useBrowserCap = this.useBrowserCap;
             getLogger().debug("Use browser capabilities is " + this.useBrowserCap + " for
" + this);
  +          
  +          child = conf.getChild("xslt-processor");
  +          String xsltRole = child.getValue(XSLTProcessor.ROLE);
  +          getLogger().debug("Use XSLTProcessor of role " + xsltRole);
  +          
  +          try {
  +            this.xsltProcessor = (XSLTProcessor)this.manager.lookup(xsltRole);
  +          } catch(Exception e) {
  +            throw new ConfigurationException("Cannot load XSLT processor", e);
  +          }
           }
       }
   
  @@ -141,17 +167,11 @@
        * Set the current <code>ComponentManager</code> instance used by this
        * <code>Composable</code>.
        */
  -    public void compose(ComponentManager manager) {
  -        try {
  -            this.manager = manager;
  -            getLogger().debug("Looking up " + XSLTProcessor.ROLE);
  -            xsltProcessor = (XSLTProcessor)manager.lookup(XSLTProcessor.ROLE);
  -            getLogger().debug("XSLTProcessor = " + xsltProcessor);
  -            getLogger().debug("Looking up " + Browser.ROLE);
  -            this.browser = (Browser) manager.lookup(Browser.ROLE);
  -        } catch (Exception e) {
  -            getLogger().error("Could not find component", e);
  -        }
  +    public void compose(ComponentManager manager) throws ComponentException {
  +        this.manager = manager;
  +        getLogger().debug("Looking up " + XSLTProcessor.ROLE);
  +        getLogger().debug("Looking up " + Browser.ROLE);
  +        this.browser = (Browser) manager.lookup(Browser.ROLE);
       }
   
       /**
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message