dims        01/08/14 04:19:54

  Modified:    src/org/apache/cocoon cocoon.roles
               src/org/apache/cocoon/transformation TraxTransformer.java
               webapp   cocoon.xconf
  Added:       src/org/apache/cocoon/components/xslt XSLTProcessor.java
                        XSLTProcessorImpl.java
  Log:
  Patch(es) from Ovidiu Predescu <[EMAIL PROTECTED]> for a new XSLTProcessor component
  
  Revision  Changes    Path
  1.18      +4 -0      xml-cocoon2/src/org/apache/cocoon/cocoon.roles
  
  Index: cocoon.roles
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/cocoon.roles,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- cocoon.roles      2001/08/09 14:37:38     1.17
  +++ cocoon.roles      2001/08/14 11:19:54     1.18
  @@ -5,6 +5,10 @@
          shorthand="parser"
          default-class="org.apache.cocoon.components.parser.JaxpParser"/>
   
  + <role name="org.apache.cocoon.components.xslt.XSLTProcessor"
  +       shorthand="xslt-processor"
  +       default-class="org.apache.cocoon.components.xslt.XSLTProcessorImpl"/>
  +
    <role name="org.apache.cocoon.components.browser.Browser"
          shorthand="browser"
          default-class="org.apache.cocoon.components.browser.BrowserImpl"/>
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessor.java
  
  Index: XSLTProcessor.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xslt;
  
  import javax.xml.transform.sax.TransformerHandler;
  import javax.xml.transform.TransformerConfigurationException;
  import javax.xml.transform.Result;
  import java.io.IOException;
  
  import org.xml.sax.SAXException;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.environment.Source;
  import org.apache.cocoon.ProcessingException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  /**
   * This is the interface of the XSLT processor in Cocoon.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Ovidiu Predescu</a>
   * @version 1.0
   * @since   July 11, 2001
   */
  public interface XSLTProcessor
  {
    /**
     * The role implemented by an <code>XSLTProcessor</code>.
     */
    String ROLE = "org.apache.cocoon.components.xslt.XSLTProcessor";
  
    /**
     * Set the {@link org.apache.cocoon.environment.SourceResolver} for
     * this instance. The <code>resolver</code> is invoked to return a
     * <code>Source</code> object, given an HREF.
     *
     * @param resolver a <code>SourceResolver</code> value
     */
    public void setSourceResolver(SourceResolver resolver);
    
    /**
     * Return a <code>TransformerHandler</code> for a given stylesheet
     * <code>Source</code>. This can be used in a pipeline to handle the
     * transformation of a stream of SAX events. See {@link
     * org.apache.cocoon.transformation.TraxTransformer#setConsumer} for
     * an example of how to use this method.
     *
     * @param stylesheet a <code>Source</code> value
     * @return a <code>TransformerHandler</code> value
     * @exception ProcessingException if an error occurs
     * @see org.apache.cocoon.transformation.TraxTransformer#setConsumer
     */
    public TransformerHandler getTransformerHandler(Source stylesheet)
      throws ProcessingException;
  
    /**
     * Applies an XSLT stylesheet to an XML document. The source and
     * stylesheet documents are specified as <code>Source</code>
     * objects. The result of the transformation is placed in
     * <code>result</code>, which should be properly initialized before
     * invoking this method. Any additional parameters passed in
     * <code>params</code> will become arguments to the stylesheet.
     *
     * @param source a <code>Source</code> value
     * @param stylesheet a <code>Source</code> value
     * @param params a <code>Parameters</code> value
     * @param result a <code>Result</code> value
     * @exception ProcessingException if an error occurs
     */
    public void transform(Source source, Source stylesheet, Parameters params,
                          Result result)
      throws ProcessingException;
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java
  
  Index: XSLTProcessorImpl.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xslt;
  
  import javax.xml.transform.stream.StreamSource;
  import javax.xml.transform.stream.StreamResult;
  import javax.xml.transform.sax.TransformerHandler;
  import javax.xml.transform.sax.TemplatesHandler;
  import javax.xml.transform.sax.SAXTransformerFactory;
  import javax.xml.transform.sax.SAXSource;
  import javax.xml.transform.URIResolver;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.TransformerException;
  import javax.xml.transform.TransformerConfigurationException;
  import javax.xml.transform.Transformer;
  import javax.xml.transform.Templates;
  import javax.xml.transform.Result;
  import java.util.Map;
  import java.util.Iterator;
  import java.util.HashMap;
  import java.io.Writer;
  import java.io.StringWriter;
  import java.io.IOException;
  import java.io.File;
  
  import org.xml.sax.helpers.XMLReaderFactory;
  import org.xml.sax.XMLReader;
  import org.xml.sax.SAXException;
  import org.xml.sax.InputSource;
  import org.apache.cocoon.util.TraxErrorHandler;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.environment.Source;
  import org.apache.cocoon.components.store.Store;
  import org.apache.cocoon.Roles;
  import org.apache.cocoon.ProcessingException;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.activity.Disposable;
  
  /**
   * This class defines the implementation of the {@link XSLTProcessor}
   * component.
   *
   * To configure it, add the following lines in the
   * <file>cocoon.xconf</file> file:
   *
   * <pre>
   * &lt;xslt-processor class="org.apache.cocoon.components.xslt.XSLTProcessorImpl"&gt;
   *    &lt;parameter name="use-store" value="true"/&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.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Ovidiu Predescu</a>
   * @version 1.0
   * @since   July 11, 2001
   */
  public class XSLTProcessorImpl
    extends AbstractLoggable
    implements XSLTProcessor, Composable, Disposable, Configurable, URIResolver, 
Component
  {
    protected ComponentManager manager;
  
    /** The store service instance */
    Store store;
  
    /** The trax TransformerFactory */
    SAXTransformerFactory tfactory;
  
    /** Is the store turned on? (default is on) */
    boolean useStore = true;
  
    SourceResolver resolver;
  
    public void compose(ComponentManager manager)
      throws ComponentException
    {
      this.manager = manager;
      getLogger().debug("XSLTProcessorImpl component initialized.");
      store = (Store)manager.lookup(Store.ROLE);
    }
  
  
    public void dispose()
    {
      if (this.manager != null)
        this.manager.release((Component)store);
    }
  
    public void configure(Configuration conf)
      throws ConfigurationException
    {
      Parameters params = Parameters.fromConfiguration(conf);
      useStore = params.getParameterAsBoolean("use-store", true);
    }
  
    public TransformerHandler getTransformerHandler(Source stylesheet)
      throws ProcessingException
    {
      try {
        Templates templates = getTemplates(stylesheet);
        if(templates == null) {
          getLogger().debug("Creating new Templates in " + this + " for "
                            + stylesheet.getInputSource().getSystemId());
          InputSource is = stylesheet.getInputSource();
          //templates = getTransformerFactory().newTemplates(new SAXSource(is));
  
          // Create a Templates ContentHandler to handle parsing of the
          // stylesheet.
          TemplatesHandler templatesHandler
            = getTransformerFactory().newTemplatesHandler();
  
          // Create an XMLReader and set its ContentHandler.
          XMLReader reader = XMLReaderFactory.createXMLReader();
          reader.setFeature("http://xml.org/sax/features/namespace-prefixes";,
                            true);
          reader.setContentHandler(templatesHandler);
  
          getLogger().debug("InputSource = " + is
                            + ", templatesHandler = " + templatesHandler
                            + ", reader = " + reader);
          // Parse the stylesheet.
          reader.parse(is);
  
          // Get the Templates object (generated during the parsing of
          // the stylesheet) from the TemplatesHandler.
          templates = templatesHandler.getTemplates();
          putTemplates (templates, stylesheet);
        } else {
          getLogger().debug("Reusing Templates in " + this + " for "
                            + stylesheet.getInputSource().getSystemId());
        }
  
        TransformerHandler handler
          = getTransformerFactory().newTransformerHandler(templates);
        if (handler == null) {
          /* If there is a problem in getting the handler, try using a
           * brand new Templates object */
          getLogger().debug("Re-creating new Templates in " + this + " for"
                            + stylesheet.getInputSource().getSystemId());
          InputSource is = stylesheet.getInputSource();
          templates = getTransformerFactory().newTemplates(new SAXSource(is));
          putTemplates (templates, stylesheet);
          handler = getTransformerFactory().newTransformerHandler(templates);
        }
  
        handler.getTransformer()
          .setErrorListener(new TraxErrorHandler(getLogger()));
        return handler;
      }
      catch (Exception e) {
        throw new ProcessingException("Error in creating Transform Handler", e);
      }
    }
  
    public void transform(Source source, Source stylesheet, Parameters params,
                          Result result)
      throws ProcessingException
    {
      try {
        getLogger().debug("XSLTProcessorImpl: transform source = " + source
                          + ", stylesheet = " + stylesheet
                          + ", parameters = " + params
                          + ", result = " + result);
        TransformerHandler handler = getTransformerHandler(stylesheet);
        Transformer transformer = handler.getTransformer();
  
        if (params != null) {
          transformer.clearParameters();
          String[] names = params.getNames();
          for (int i = names.length -1 ; i >= 0; i--) {
            transformer.setParameter(names[i], params.getParameter(names[i]));
          }
        }
        InputSource is = source.getInputSource();
        getLogger().debug("XSLTProcessorImpl: starting transform");
        transformer.transform(new StreamSource(is.getByteStream(),
                                               is.getSystemId()),
                              result);
        getLogger().debug("XSLTProcessorImpl: transform done");
        if (result instanceof StreamResult) {
          Writer writer = ((StreamResult)result).getWriter();
          getLogger().debug("XSLTProcessorImpl: transform result = "
                            + writer);
          if (writer instanceof StringWriter) {
            StringBuffer stringBuffer = ((StringWriter)writer).getBuffer();
            getLogger().debug("XSLTProcessorImpl: transform result = "
                              + stringBuffer);
          }
        }
      }
      catch (Exception e) {
        throw new ProcessingException("Error in running Transformation", e);
      }
    }
  
    /**
     * Helper for TransformerFactory.
     */
    private SAXTransformerFactory getTransformerFactory()
    {
      if(tfactory == null) {
        tfactory = (SAXTransformerFactory)TransformerFactory.newInstance();
        tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
        tfactory.setURIResolver(this);
      }
      return tfactory;
    }
  
    private Templates getTemplates(Source stylesheet)
      throws IOException, ProcessingException
    {
      Templates templates = null;
      InputSource is = stylesheet.getInputSource();
  
      if (useStore == false)
        return null;
  
      // only stylesheets with a last modification date are stored
      if (stylesheet.getLastModified() != 0) {
  
        // Stored is an array of the template and the caching time
        if (store.containsKey(is.getSystemId())) {
          Object[] templateAndTime
            = (Object[])store.get(is.getSystemId());
  
          if(templateAndTime != null && templateAndTime[1] != null) {
            long storedTime = ((Long)templateAndTime[1]).longValue();
  
            if (storedTime < stylesheet.getLastModified()) {
              store.remove(is.getSystemId());
            }
            else {
              templates = (Templates)templateAndTime[0];
            }
          }
        }
      }
      else {
        // remove an old template if it exists
        if (store.containsKey(is.getSystemId())) {
          store.remove(is.getSystemId());
        }
      }
      return templates;
    }
  
    private void putTemplates (Templates templates, Source stylesheet)
      throws IOException, ProcessingException
    {
      if (useStore == false)
        return;
  
      // only stylesheets with a last modification date are stored
      if (stylesheet.getLastModified() != 0) {
  
        // Stored is an array of the template and the current time
        Object[] templateAndTime = new Object[2];
        templateAndTime[0] = templates;
        templateAndTime[1] = new Long(stylesheet.getLastModified());
        store.hold(stylesheet.getInputSource().getSystemId(), templateAndTime);
      }
    }
  
    /**
     * Called by the processor when it encounters
     * an xsl:include, xsl:import, or document() function.
     *
     * @param href An href attribute, which may be relative or absolute.
     * @param base The base URI in effect when the href attribute
     * was encountered.
     *
     * @return A Source object, or null if the href cannot be resolved,
     * and the processor should try to resolve the URI itself.
     *
     * @throws TransformerException if an error occurs when trying to
     * resolve the URI.
     */
    public javax.xml.transform.Source resolve(String href, String base)
      throws TransformerException
    {
      getLogger().debug("XSLTProcessorImpl: resolve(href = " + href
                        + ", base = " + base + "); resolver = " + resolver);
  
      try {
        Source xslSource;
        if (href.indexOf(":") > 1) {
          xslSource = resolver.resolve(href);
        }
        else {
          // patch for a null pointer passed as base
          if (base == null)
            throw new IllegalArgumentException("Null pointer passed as base");
  
          // is the base a file or a real url
          if (!base.startsWith("file:")) {
            int lastPathElementPos = base.lastIndexOf('/');
            if (lastPathElementPos == -1) {
              // this should never occur as the base should
              // always be protocol:/....
              return null; // we can't resolve this
            }
            else {
              xslSource = resolver.resolve(base.substring(0, lastPathElementPos)
                                           + "/" + href);
            }
          }
          else {
            File parent = new File(base.substring(5));
            File parent2 = new File(parent.getParentFile(), href);
            xslSource = resolver.resolve("file:/" + parent2.getAbsolutePath());
          }
        }
        InputSource is = xslSource.getInputSource();
        getLogger().debug("xslSource = " + xslSource
                          + ", system id = " + is.getSystemId());
        return new StreamSource(is.getByteStream(),
                                is.getSystemId());
      } catch (Exception e) {
        throw new TransformerException(e);
      }
    }
  
    public void setSourceResolver(SourceResolver resolver)
    {
      this.resolver = resolver;
    }
  }
  
  
  
  1.27      +46 -218   
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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- TraxTransformer.java      2001/08/08 20:07:06     1.26
  +++ TraxTransformer.java      2001/08/14 11:19:54     1.27
  @@ -13,18 +13,21 @@
   import java.text.StringCharacterIterator;
   import java.util.Enumeration;
   import java.util.HashMap;
  +import java.util.Hashtable;
   import java.util.Iterator;
   import java.util.Iterator;
   import java.util.Map;
  -import java.util.Set;
   import javax.xml.transform.Templates;
   import javax.xml.transform.TransformerConfigurationException;
   import javax.xml.transform.TransformerFactory;
  +import javax.xml.transform.URIResolver;
   import javax.xml.transform.sax.SAXResult;
   import javax.xml.transform.sax.SAXSource;
  -import javax.xml.transform.sax.SAXTransformerFactory;
   import javax.xml.transform.sax.TransformerHandler;
  -import javax.xml.transform.URIResolver;
  +import org.apache.avalon.excalibur.pool.Poolable;
  +import org.apache.avalon.excalibur.pool.Poolable;
  +import org.apache.avalon.excalibur.pool.Recyclable;
  +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;
  @@ -34,8 +37,6 @@
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.logger.Loggable;
   import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.avalon.excalibur.pool.Poolable;
  -import org.apache.avalon.excalibur.pool.Recyclable;
   import org.apache.cocoon.Constants;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.caching.CacheValidity;
  @@ -44,10 +45,10 @@
   import org.apache.cocoon.caching.ParametersCacheValidity;
   import org.apache.cocoon.caching.TimeStampCacheValidity;
   import org.apache.cocoon.components.browser.Browser;
  -import org.apache.cocoon.components.store.Store;
  +import org.apache.cocoon.components.xslt.XSLTProcessor;
   import org.apache.cocoon.environment.Request;
  -import org.apache.cocoon.environment.Cookie;
   import org.apache.cocoon.environment.Source;
  +import org.apache.cocoon.environment.Cookie;
   import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.util.HashUtil;
   import org.apache.cocoon.util.TraxErrorHandler;
  @@ -57,6 +58,7 @@
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   import org.xml.sax.ext.LexicalHandler;
  +import java.util.Set;
   
   /**
    * This Transformer is used to transform this incomming SAX stream using
  @@ -66,15 +68,10 @@
    * <b>In the map:sitemap/map:components/map:transformers:</b><br>
    *
    * &lt;map:transformer name="xslt" 
src="org.apache.cocoon.transformation.TraxTransformer"&gt;<br>
  - *   &lt;use-store map:value="true"/&gt;
    *   &lt;use-request-parameters map:value="false"/&gt;
    *   &lt;use-browser-capabilities-db map:value="false"/&gt;
    * &lt;/map:transformer&gt;
    *
  - * 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.
  - *
    * 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.
  @@ -100,224 +97,65 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Davanum Srinivas</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Id: TraxTransformer.java,v 1.26 2001/08/08 20:07:06 vgritsenko Exp 
$
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Ovidiu Predescu</a>
  + * @version CVS $Id: TraxTransformer.java,v 1.27 2001/08/14 11:19:54 dims Exp $
    */
   public class TraxTransformer extends AbstractTransformer
  -implements Transformer, Composable, Recyclable, Configurable, Cacheable, 
Disposable, URIResolver {
  +implements Transformer, Composable, Recyclable, Configurable, Cacheable, Disposable 
{
   
  -    /** The store service instance */
  -    private Store store = null;
  +    private static final String FILE = "file:";
   
       /** The Browser service instance */
       private Browser browser = null;
   
  -    /** The trax TransformerFactory */
  -    private SAXTransformerFactory tfactory = null;
  -
  -    /** The trax TransformerHandler */
  -    private TransformerHandler transformerHandler = null;
  -
  -    /** Is the store turned on? (default is on) */
  -    private boolean useStore = true;
  -
       /** Should we make the request parameters available in the stylesheet? (default 
is off) */
       private boolean useParameters = false;
       private boolean _useParameters = false;
   
  -    /** Should we make the cookies availalbe in the stylesheet? (default is off) **/
  -    private boolean useCookies = false;
  -    private boolean _useCookies = false;
  -
       /** Should we make the browser capability properties available in the 
stylesheet? (default is off) */
       private boolean useBrowserCap = false;
       private boolean _useBrowserCap = false;
   
  +    /** Should we make the cookies availalbe in the stylesheet? (default is off) */
  +    private boolean useCookies = false;
  +    private boolean _useCookies = false;
  +
       private ComponentManager manager;
   
  +    /** The trax TransformerHandler */
  +    TransformerHandler transformerHandler;
       /** The Source */
       private Source inputSource;
       /** The parameters */
       private Parameters par;
       /** The object model */
       private Map objectModel;
  -    /** The source resolver */
  -    SourceResolver resolver;
  -
  -    TransformerHandler getTransformerHandler()
  -    throws SAXException, ProcessingException, IOException, 
TransformerConfigurationException {
  -        Templates templates = getTemplates();
  -        if(templates == null) {
  -            getLogger().debug("Creating new Templates in " + this + " for " + 
this.inputSource.getSystemId());
  -            InputSource is = this.inputSource.getInputSource();
  -            //templates = getTransformerFactory().newTemplates(new SAXSource(is));
  -
  -            // Create a Templates ContentHandler to handle parsing of the
  -            // stylesheet.
  -            javax.xml.transform.sax.TemplatesHandler templatesHandler =
  -                                                
getTransformerFactory().newTemplatesHandler();
  -
  -            // Create an XMLReader and set its ContentHandler.
  -            org.xml.sax.XMLReader reader =
  -                           org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
  -            reader.setFeature("http://xml.org/sax/features/namespace-prefixes";, 
true);
  -            reader.setContentHandler(templatesHandler);
  -
  -            // Parse the stylesheet.
  -            reader.parse(is);
  -
  -            // Get the Templates object (generated during the parsing of the 
stylesheet)
  -            // from the TemplatesHandler.
  -            templates = templatesHandler.getTemplates();
   
  +    /** The XSLTProcessor */
  +    XSLTProcessor xsltProcessor;
   
  -            putTemplates (templates);
  -        } else {
  -            getLogger().debug("Reusing Templates in " + this + " for " + 
this.inputSource.getSystemId());
  -        }
  -
  -        TransformerHandler handler = 
getTransformerFactory().newTransformerHandler(templates);
  -        if(handler == null) {
  -            /* If there is a problem in getting the handler, try using a brand new 
Templates object */
  -            getLogger().debug("Re-creating new Templates in " + this + " for" + 
this.inputSource.getSystemId());
  -            InputSource is = this.inputSource.getInputSource();
  -            templates = getTransformerFactory().newTemplates(new SAXSource(is));
  -            putTemplates (templates);
  -            handler = getTransformerFactory().newTransformerHandler(templates);
  -        }
  -
  -        handler.getTransformer().setErrorListener(new 
TraxErrorHandler(getLogger()));
  -        return handler;
  -    }
  -
  -    private Templates getTemplates ()
  -    throws IOException {
  -        Templates templates = null;
  -        if (this.useStore == false)
  -            return null;
  -
  -        // only stylesheets with a last modification date are stored
  -        if (this.inputSource.getLastModified() != 0) {
  -
  -            // Stored is an array of the template and the caching time
  -            if (store.containsKey(this.inputSource.getSystemId()) == true) {
  -                Object[] templateAndTime = 
(Object[])store.get(this.inputSource.getSystemId());
  -                if(templateAndTime != null && templateAndTime[1] != null) {
  -                    long storedTime = ((Long)templateAndTime[1]).longValue();
  -                    if (storedTime < this.inputSource.getLastModified()) {
  -                        store.remove(this.inputSource.getSystemId());
  -                    } else {
  -                        templates = (Templates)templateAndTime[0];
  -                    }
  -                }
  -            }
  -        } else {
  -            // remove an old template if it exists
  -            if (store.containsKey(this.inputSource.getSystemId()) == true) {
  -               store.remove(this.inputSource.getSystemId());
  -            }
  -        }
  -        return templates;
  -    }
  -
  -    private void putTemplates (Templates templates)
  -    throws IOException {
  -        if (this.useStore == false)
  -            return;
  -
  -        // only stylesheets with a last modification date are stored
  -        if (this.inputSource.getLastModified() != 0) {
  -
  -            // Stored is an array of the template and the current time
  -            Object[] templateAndTime = new Object[2];
  -            templateAndTime[0] = templates;
  -            templateAndTime[1] = new Long(this.inputSource.getLastModified());
  -            store.hold(this.inputSource.getSystemId(), templateAndTime);
  -        }
  -    }
  -
  -    /**
  -     * Called by the processor when it encounters
  -     * an xsl:include, xsl:import, or document() function.
  -     *
  -     * @param href An href attribute, which may be relative or absolute.
  -     * @param base The base URI in effect when the href attribute
  -     * was encountered.
  -     *
  -     * @return A Source object, or null if the href cannot be resolved,
  -     * and the processor should try to resolve the URI itself.
  -     *
  -     * @throws TransformerException if an error occurs when trying to
  -     * resolve the URI.
  -     */
  -    public javax.xml.transform.Source resolve(String href, String base)
  -    throws javax.xml.transform.TransformerException {
  -        try {
  -            Source xslSource;
  -            if (href.indexOf(":") > 1) {
  -                xslSource = this.resolver.resolve(href);
  -            } else {
  -                // patch for a null pointer passed as base
  -                if (base == null) base = this.inputSource.getSystemId();
  -
  -                // is the base a file or a real url
  -                if (base.startsWith("file:") == false) {
  -                    int lastPathElementPos = base.lastIndexOf('/');
  -                    if (lastPathElementPos == -1) {
  -                        // this should never occur as the base should
  -                        // always be protol:/....
  -                        return null; // we can't resolve this
  -                    } else {
  -                        xslSource = this.resolver.resolve(base.substring(0, 
lastPathElementPos)
  -                                                       + "/" + href);
  -                    }
  -                } else {
  -                    File parent = new File(base.substring(5));
  -                    xslSource = this.resolver.resolve("file:/"
  -                               + new File(parent.getParentFile(), 
href).getAbsolutePath());
  -                }
  -            }
  -            return new 
javax.xml.transform.stream.StreamSource(xslSource.getInputStream(), 
xslSource.getSystemId());
  -       } catch (IOException e) {
  -            throw new javax.xml.transform.TransformerException(e);
  -       } catch (SAXException e) {
  -           throw new javax.xml.transform.TransformerException(e);
  -        } catch (ProcessingException e) {
  -            throw new javax.xml.transform.TransformerException(e);
  -        }
  -    }
  -    /**
  -     * Helper for TransformerFactory.
  -     */
  -    private SAXTransformerFactory getTransformerFactory() {
  -        if(tfactory == null)  {
  -            tfactory = (SAXTransformerFactory) TransformerFactory.newInstance();
  -            tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
  -            tfactory.setURIResolver(this);
  -        }
  -        return tfactory;
  -    }
  -
       /**
        * Configure this transformer.
        */
       public void configure(Configuration conf)
       throws ConfigurationException {
           if (conf != null) {
  -            Configuration child = conf.getChild("use-store");
  -            this.useStore = child.getValueAsBoolean(true);
  -            getLogger().debug("Use store is " + this.useStore + " for " + this);
  -            child = conf.getChild("use-request-parameters");
  -            this.useParameters = child.getValueAsBoolean(false);
  -            this._useParameters = this.useParameters;
  -            getLogger().debug("Use parameters is " + this.useParameters + " for " + 
this);
  -            child = conf.getChild("use-cookies");
  -            this.useCookies = child.getValueAsBoolean(false);
  -            this._useCookies = this.useCookies;
  -            getLogger().debug("Use cookies is " + this.useCookies + " for " + this);
  -            child = conf.getChild("use-browser-capabilities-db");
  -            this.useBrowserCap = child.getValueAsBoolean(false);
  -            this._useBrowserCap = this.useBrowserCap;
  -            getLogger().debug("Use browser capabilities is " + this.useBrowserCap + 
" for " + this);
  +          Configuration child;
  +
  +          child = conf.getChild("use-request-parameters");
  +          this.useParameters = child.getValueAsBoolean(false);
  +          this._useParameters = this.useParameters;
  +          getLogger().debug("Use parameters is " + this.useParameters + " for " + 
this);
  +
  +          child = conf.getChild("use-cookies");
  +          this.useCookies = child.getValueAsBoolean(false);
  +          this._useCookies = this.useCookies;
  +          getLogger().debug("Use cookies is " + this.useCookies + " for " + this);
  +
  +          child = conf.getChild("use-browser-capabilities-db");
  +          this.useBrowserCap = child.getValueAsBoolean(false);
  +          this._useBrowserCap = this.useBrowserCap;
  +          getLogger().debug("Use browser capabilities is " + this.useBrowserCap + " 
for " + this);
           }
       }
   
  @@ -328,10 +166,11 @@
       public void compose(ComponentManager manager) {
           try {
               this.manager = manager;
  -            getLogger().debug("Looking up " + Store.ROLE);
  -            this.store = (Store) this.manager.lookup(Store.ROLE);
  +            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) this.manager.lookup(Browser.ROLE);
  +            this.browser = (Browser) manager.lookup(Browser.ROLE);
           } catch (Exception e) {
               getLogger().error("Could not find component", e);
           }
  @@ -352,11 +191,11 @@
           this.par = par;
           this.objectModel = objectModel;
           this.inputSource = resolver.resolve(src);
  -        this.resolver = resolver;
  +        xsltProcessor.setSourceResolver(resolver);
           getLogger().debug("Using stylesheet: '"+this.inputSource.getSystemId()+"' 
in " + this + ", last modified: " + this.inputSource.getLastModified());
           _useParameters = par.getParameterAsBoolean("use-request-parameters", 
this.useParameters);
  -        _useCookies = par.getParameterAsBoolean("use-cookies", this.useCookies);
           _useBrowserCap = par.getParameterAsBoolean("use-browser-capabilities-db", 
this.useBrowserCap);
  +        _useCookies = par.getParameterAsBoolean("use-cookies", this.useCookies);
       }
   
       /**
  @@ -413,17 +252,9 @@
   
           /** Get a Transformer Handler */
           try {
  -            transformerHandler = getTransformerHandler();
  -        } catch (TransformerConfigurationException e){
  -            getLogger().error("Problem in getTransformer:", e);
  -            throw new RuntimeException("Problem in getTransformer:" + 
e.getMessage());
  -        } catch (SAXException e){
  -            getLogger().error("Problem in getTransformer:", e);
  -            throw new RuntimeException("Problem in getTransformer:" + 
e.getMessage());
  -        } catch (IOException e){
  -            getLogger().error("Problem in getTransformer:", e);
  -            throw new RuntimeException("Problem in getTransformer:" + 
e.getMessage());
  -        } catch (ProcessingException e){
  +            transformerHandler
  +              = xsltProcessor.getTransformerHandler(inputSource);
  +        } catch (Exception e){
               getLogger().error("Problem in getTransformer:", e);
               throw new RuntimeException("Problem in getTransformer:" + 
e.getMessage());
           }
  @@ -570,8 +401,6 @@
   
       public void dispose()
       {
  -        if(this.store != null)
  -            this.manager.release((Component)this.store);
           if(this.browser != null)
               this.manager.release((Component)this.browser);
       }
  @@ -601,7 +430,6 @@
           this.objectModel = null;
           this.inputSource = null;
           this.par = null;
  -        this.resolver = null;
           this._useParameters = this.useParameters;
           this._useCookies = this.useCookies;
           this._useBrowserCap = this.useBrowserCap;
  
  
  
  1.28      +4 -0      xml-cocoon2/webapp/cocoon.xconf
  
  Index: cocoon.xconf
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/cocoon.xconf,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- cocoon.xconf      2001/08/09 10:51:33     1.27
  +++ cocoon.xconf      2001/08/14 11:19:54     1.28
  @@ -42,6 +42,10 @@
        <parameter name="filesystem" value="true"/>
     </store>
   
  +  <xslt-processor class="org.apache.cocoon.components.xslt.XSLTProcessorImpl">
  +     <parameter name="use-store" value="true"/>
  +  </xslt-processor>
  +
     <!-- The url factory adds special url protocols to the system, they
          are then available inside Cocoon, e.g. as a source argument
          for one of the sitemap components -->
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to