cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript ListInputStream.java
Date Wed, 26 Feb 2003 13:58:05 GMT
cziegeler    2003/02/26 05:58:05

  Modified:    src/java/org/apache/cocoon/xml/dom DocumentWrapper.java
               src/java/org/apache/cocoon/serialization
                        ZipArchiveSerializer.java
               src/java/org/apache/cocoon/components/flow/javascript
                        ListInputStream.java
  Added:       src/scratchpad/src/org/apache/cocoon/components/source/impl
                        SourceFactoryWrapper.java URLFactoryWrapper.java
               src/scratchpad/src/org/apache/cocoon/components/source
                        CocoonSourceFactory.java FileSourceFactory.java
                        FileSource.java
  Removed:     src/java/org/apache/cocoon/components/source
                        CocoonSourceFactory.java FileSourceFactory.java
                        FileSource.java
               src/java/org/apache/cocoon/components/source/impl
                        URLFactoryWrapper.java SourceFactoryWrapper.java
  Log:
  Updating code; removing dependencies on deprecated code
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/impl/SourceFactoryWrapper.java
  
  Index: SourceFactoryWrapper.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.source.impl;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.apache.avalon.framework.activity.Disposable;
  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.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.CascadingIOException;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.components.CocoonComponentManager;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.util.ClassUtils;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceFactory;
  
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.util.Map;
  
  /**
   * This class wraps a Cocoon SourceFactory and makes it
   * usable within the Avalon Excalibur source resolving architecure.
   * The main purpose is to avoid recoding existing factories.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: SourceFactoryWrapper.java,v 1.1 2003/02/26 13:58:04 cziegeler Exp $
   */
  public final class SourceFactoryWrapper
      extends AbstractLogEnabled
      implements SourceFactory,
                 ThreadSafe,
                 Configurable,
                 Disposable,
                 Composable,
                 Contextualizable
  {
      /** The <code>ComponentManager</code> */
      private ComponentManager manager;
  
      /** The special Source factories */
      private org.apache.cocoon.components.source.SourceFactory sourceFactory;
  
      /** The context */
      private Context context;
  
      /**
       * Configure the SourceFactories
       */
      public void configure(final Configuration conf)
      throws ConfigurationException {
  
          try {
              final Configuration factoryConf = conf.getChild("source-factory");
              final String className = factoryConf.getAttribute("class");
              if (this.getLogger().isDebugEnabled()) {
                  this.getLogger().debug("Getting the SourceFactory " + className);
              }
              this.sourceFactory = (org.apache.cocoon.components.source.SourceFactory)
                           ClassUtils.newInstance(className);
              this.init(this.sourceFactory, factoryConf);
          } catch (ConfigurationException e) {
              throw e;
          } catch (Exception e) {
              throw new ConfigurationException("Could not get parameters because: " +
                                             e.getMessage(), e);
          }
      }
  
      /**
       * Get the context
       */
      public void contextualize(Context context)
      throws ContextException {
          this.context = context;
      }
  
      /**
       * Set the current <code>ComponentManager</code> instance used by this
       * <code>Composable</code>.
       */
      public void compose(ComponentManager manager)
      throws ComponentException {
          this.manager = manager;
      }
  
      /**
       * Dispose
       */
      public void dispose() {
          if (this.sourceFactory != null) {
              this.deinit(this.sourceFactory);
          }
          this.sourceFactory = null;
      }
  
  
      /**
       * Get a <code>Source</code> object.
       * @param parameters This is optional.
       */
      public Source getSource( String location, Map parameters )
          throws MalformedURLException, IOException
      {
          if( getLogger().isDebugEnabled() )
          {
              getLogger().debug( "Creating source object for " + location );
          }
  
          final Environment currentEnv = CocoonComponentManager.getCurrentEnvironment();
          org.apache.cocoon.environment.Source source;
          try {
              source = this.sourceFactory.getSource(currentEnv, location);
          } catch (ProcessingException pe) {
              throw new CascadingIOException("ProcessingException: " + pe.getMessage(), pe);
          }
          return new CocoonToAvalonSource( location, source );
      }
  
      /**
       * Init a source factory
       */
      private void init(org.apache.cocoon.components.source.SourceFactory factory,
                        Configuration config)
      throws ContextException, ComponentException, ConfigurationException {
          if (factory instanceof LogEnabled) {
              ((LogEnabled) factory).enableLogging(getLogger());
          }
          if (factory instanceof Contextualizable) {
              ((Contextualizable) factory).contextualize (this.context);
          }
          if (factory instanceof Composable) {
              ((Composable) factory).compose(this.manager);
          }
          if (config != null && factory instanceof Configurable) {
              ((Configurable) factory).configure(config);
          }
      }
  
      /**
       * Deinit a source factory
       */
      private void deinit(org.apache.cocoon.components.source.SourceFactory factory) {
          if (factory instanceof Disposable) {
              ((Disposable) factory).dispose();
          }
      }
      
      /**
       * Release a {@link Source} object.
       */
      public void release( Source source ) {
          if ( null != source ) {
              if ( this.getLogger().isDebugEnabled() ) {
                  this.getLogger().debug("Releasing source " + source.getURI());
              }
              ((Recyclable)source).recycle();
          }
      }
  
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/impl/URLFactoryWrapper.java
  
  Index: URLFactoryWrapper.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.source.impl;
  
  import org.apache.avalon.framework.activity.Disposable;
  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.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.components.url.URLFactory;
  import org.apache.cocoon.util.ClassUtils;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceFactory;
  import org.apache.excalibur.source.impl.URLSource;
  
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.Map;
  
  /**
   * This class wraps a Cocoon URLFactory and makes it
   * usable within the Avalon Excalibur source resolving architecure.
   * The main purpose is to avoid recoding existing factories.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: URLFactoryWrapper.java,v 1.1 2003/02/26 13:58:04 cziegeler Exp $
   */
  
  public final class URLFactoryWrapper
      extends AbstractLogEnabled
      implements SourceFactory,
                 ThreadSafe,
                 Configurable,
                 Disposable,
                 Composable,
                 Contextualizable
  {
      /** The <code>ComponentManager</code> */
      private ComponentManager manager;
  
      /** The special Source factories */
      private URLFactory urlFactory;
  
      /** The context */
      private Context context;
  
      /**
       * Configure the SourceFactories
       */
      public void configure(final Configuration conf)
      throws ConfigurationException {
  
          try {
              final Configuration factoryConf = conf.getChild("url-factory");
              final String className = factoryConf.getAttribute("class");
              if (this.getLogger().isDebugEnabled()) {
                  this.getLogger().debug("Getting the URLFactory " + className);
              }
              this.urlFactory = (URLFactory)ClassUtils.newInstance(className);
              this.init(this.urlFactory, factoryConf);
          } catch (ConfigurationException e) {
              throw e;
          } catch (Exception e) {
              throw new ConfigurationException("Could not get parameters because: " +
                                             e.getMessage(), e);
          }
      }
  
      /**
       * Get the context
       */
      public void contextualize(Context context)
      throws ContextException {
          this.context = context;
      }
  
      /**
       * Set the current <code>ComponentManager</code> instance used by this
       * <code>Composable</code>.
       */
      public void compose(ComponentManager manager)
      throws ComponentException {
          this.manager = manager;
      }
  
      /**
       * Dispose
       */
      public void dispose() {
          if (this.urlFactory != null) {
              this.deinit(this.urlFactory);
          }
          this.urlFactory = null;
      }
  
  
      /**
       * Get a <code>Source</code> object.
       * @param parameters This is optional.
       */
      public Source getSource( String location, Map parameters )
          throws MalformedURLException, IOException
      {
          if( this.getLogger().isDebugEnabled() ) {
              this.getLogger().debug( "Creating source object for " + location );
          }
  
          final int protocolPos = location.indexOf("://");
          final URL url = this.urlFactory.getURL(location.substring(protocolPos+3));
          final URLSource source = new org.apache.excalibur.source.impl.URLSource();
          source.init(url, parameters);
          return source;
      }
  
      /**
       * Init a url factory
       */
      private void init(URLFactory factory,
                        Configuration config)
      throws ContextException, ComponentException, ConfigurationException {
          if (factory instanceof LogEnabled) {
              ((LogEnabled) factory).enableLogging(getLogger());
          }
          if (factory instanceof Contextualizable) {
              ((Contextualizable) factory).contextualize (this.context);
          }
          if (factory instanceof Composable) {
              ((Composable) factory).compose(this.manager);
          }
          if (config != null && factory instanceof Configurable) {
              ((Configurable) factory).configure(config);
          }
      }
  
      /**
       * Deinit a url factory
       */
      private void deinit(URLFactory factory) {
          if (factory instanceof Disposable) {
              ((Disposable) factory).dispose();
          }
      }
  
      /**
       * Release a {@link Source} object.
       */
      public void release( Source source ) {
          if ( null != source ) {
              if ( this.getLogger().isDebugEnabled() ) {
                  this.getLogger().debug("Releasing source " + source.getURI());
              }
              // do simply nothing
          }
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/CocoonSourceFactory.java
  
  Index: CocoonSourceFactory.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.source;
  
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Source;
  import org.apache.cocoon.Processor;
  
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  /**
   * This class implements the cocoon: protocol.
   * It cannot be configured like the other source factories
   * as it needs the current <code>Sitemap</code> as input.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: CocoonSourceFactory.java,v 1.1 2003/02/26 13:58:04 cziegeler Exp $
   */
  public final class CocoonSourceFactory
  extends AbstractLogEnabled
  implements SourceFactory {
  
      /** The component manager */
      private ComponentManager  manager;
  
      public CocoonSourceFactory(Processor processor,
                                 ComponentManager manager) {
          this.manager = manager;
      }
  
      /**
       * Resolve the source
       */
      public Source getSource(Environment environment, String location)
      throws ProcessingException, IOException, MalformedURLException {
          if (environment == null)
              throw new ProcessingException("CocoonSourceFactory: environment is required.");
          return new SitemapSource(this.manager,
                                   location,
                                   this.getLogger());
      }
  
      /**
       * Resolve the source
       */
      public Source getSource(Environment environment, URL base, String location)
      throws ProcessingException, IOException, MalformedURLException {
          if (environment == null)
              throw new ProcessingException("CocoonSourceFactory: environment is required.");
          return this.getSource(environment, base.toExternalForm() + location);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/FileSourceFactory.java
  
  Index: FileSourceFactory.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache Cocoon" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.cocoon.components.source;
  
  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.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.components.source.SourceFactory;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Source;
  import org.apache.cocoon.ProcessingException;
  
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  /**
   * A factory for 'file:' sources.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version $Id: FileSourceFactory.java,v 1.1 2003/02/26 13:58:04 cziegeler Exp $
   * @deprecated Use the new avalon source resolving instead
   */
  
  public class FileSourceFactory extends AbstractLogEnabled
      implements SourceFactory, Composable, ThreadSafe {
      
      private ComponentManager manager;
  
      public void compose(ComponentManager manager) throws ComponentException {
          this.manager = manager;
      }
      
      public Source getSource(Environment environment, String location)
        throws ProcessingException, MalformedURLException, IOException {
          Source result = new FileSource(location, this.manager);
          setupLogger(result);
          return result;
      }
  
      public Source getSource(Environment environment, URL base, String location)
        throws ProcessingException, MalformedURLException, IOException {
          return getSource(environment, new URL(base, location).toExternalForm());
      }
  }
      
  
  
  
  1.1                  xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/FileSource.java
  
  Index: FileSource.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache Cocoon" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.components.source;
  
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.ResourceNotFoundException;
  
  import java.io.*;
  import java.net.MalformedURLException;
  import java.util.ConcurrentModificationException;
  
  /**
   * A <code>org.apache.cocoon.environment.WriteableSource</code> for 'file:/' system IDs.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version $Id: FileSource.java,v 1.1 2003/02/26 13:58:04 cziegeler Exp $
   * @deprecated Use the new avalon source resolving instead
   */
  
  public class FileSource extends AbstractStreamWriteableSource
      implements org.apache.cocoon.environment.WriteableSource {
  
      /** The underlying file. */
      private File file;
  
      /** The system ID for this source (lazily created by getSystemId()) */
      private String systemId = null;
  
      /** Is this an html file ? */
      private boolean isHTMLContent;
  
      /**
       * Create a file source from a 'file:' url and a component manager.
       */
      public FileSource(String url, ComponentManager manager) {
  
          super(manager);
  
          if (!url.startsWith("file:")) {
              throw new IllegalArgumentException("Malformed url for a file source : " + url);
          }
  
          if (url.endsWith(".htm") || url.endsWith(".html")) {
              this.isHTMLContent = true;
          }
  
          this.file = new File(url.substring(5)); // 5 == "file:".length()
      }
  
      public boolean exists() {
          return this.file.exists();
      }
  
      /**
       * Returns <code>true</code> if the file name ends with ".htm" or ".html".
       */
      protected boolean isHTMLContent() {
          return this.isHTMLContent;
      }
  
      /**
       * Return the unique identifer for this source
       */
      public String getSystemId() {
          if (this.systemId == null) {
              try {
                  this.systemId = this.file.toURL().toExternalForm();
              } catch(MalformedURLException mue) {
                  // Can this really happen ?
                  this.systemId = "file:" + this.file.getPath();
              }
          }
          return this.systemId;
      }
  
      /**
       * Get the input stream for this source.
       */
      public InputStream getInputStream() throws IOException, ProcessingException {
          try {
              return new FileInputStream(this.file);
          } catch (FileNotFoundException e) {
              throw new ResourceNotFoundException("Resource not found "
                                                  + getSystemId(), e);
          }
      }
  
      public long getLastModified() {
          return this.file.lastModified();
      }
  
      public long getContentLength() {
          return this.file.length();
      }
  
      /**
       * Get an output stream to write to this source. The output stream returned
       * actually writes to a temp file that replaces the real one on close. This
       * temp file is used as lock to forbid multiple simultaneous writes. The
       * real file is updated atomically when the output stream is closed.
       *
       * @throws ConcurrentModificationException if another thread is currently
       *         writing to this file.
       */
      public OutputStream getOutputStream() throws IOException, ProcessingException {
  
          // Create a temp file. It will replace the right one when writing terminates,
          // and serve as a lock to prevent concurrent writes.
          File tmpFile = new File(this.file.getPath() + ".tmp");
  
          // Ensure the directory exists
          tmpFile.getParentFile().mkdirs();
  
          // Can we write the file ?
          if (this.file.exists() && !this.file.canWrite()) {
              throw new IOException("Cannot write to file " + this.file.getPath());
          }
  
          // Check if it temp file already exists, meaning someone else currently writing
          if (!tmpFile.createNewFile()) {
              throw new ConcurrentModificationException("File " + this.file.getPath() +
                " is already being written by another thread");
          }
  
          // Return a stream that will rename the temp file on close.
          return new FileSourceOutputStream(tmpFile);
      }
  
      /**
       * Always return <code>false</code>. To be redefined by implementations that support
       * <code>cancel()</code>.
       */
      public boolean canCancel(OutputStream stream) {
          if (stream instanceof FileSourceOutputStream) {
              FileSourceOutputStream fsos = (FileSourceOutputStream)stream;
              if (fsos.getSource() == this) {
                  return fsos.canCancel();
              }
          }
  
          // Not a valid stream for this source
          throw new IllegalArgumentException("The stream is not associated to this source");
      }
  
      /**
       * Cancels the output stream.
       */
      public void cancel(OutputStream stream) throws Exception {
          if (stream instanceof FileSourceOutputStream) {
              FileSourceOutputStream fsos = (FileSourceOutputStream)stream;
              if (fsos.getSource() == this) {
                  fsos.cancel();
                  return;
              }
          }
  
          // Not a valid stream for this source
          throw new IllegalArgumentException("The stream is not associated to this source");
      }
  
      /**
       * A file outputStream that will rename the temp file to the destination file upon close()
       * and discard the temp file upon cancel().
       */
      private class FileSourceOutputStream extends FileOutputStream {
  
          private File tmpFile;
          private boolean isClosed = false;
  
          public FileSourceOutputStream(File tmpFile) throws IOException {
              super(tmpFile);
              this.tmpFile = tmpFile;
          }
  
          public FileSource getSource() {
              return FileSource.this;
          }
  
          public void close() throws IOException {
              super.close();
  
              try {
                  // Delete destination file
                  if (FileSource.this.file.exists()) {
                      FileSource.this.file.delete();
                  }
                  // Rename temp file to destination file
                  tmpFile.renameTo(FileSource.this.file);
  
              } finally {
                  // Ensure temp file is deleted, ie lock is released.
                  // If there was a failure above, written data is lost.
                  if (tmpFile.exists()) {
                      tmpFile.delete();
                  }
                  this.isClosed = true;
              }
          }
  
          public boolean canCancel() {
              return !this.isClosed;
          }
  
          public void cancel() throws Exception {
              if (this.isClosed) {
                  throw new IllegalStateException("Cannot cancel : outputstrem is already closed");
              }
  
              this.isClosed = true;
              super.close();
              this.tmpFile.delete();
          }
  
          public void finalize() {
              if (!this.isClosed && tmpFile.exists()) {
                  // Something wrong happened while writing : delete temp file
                  tmpFile.delete();
              }
          }
      }
  }
  
  
  
  1.5       +2 -2      xml-cocoon2/src/java/org/apache/cocoon/xml/dom/DocumentWrapper.java
  
  Index: DocumentWrapper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/xml/dom/DocumentWrapper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DocumentWrapper.java	31 Jan 2003 22:52:00 -0000	1.4
  +++ DocumentWrapper.java	26 Feb 2003 13:58:04 -0000	1.5
  @@ -77,7 +77,7 @@
    * @author <a href="mailto:haul@apache.org">Christian Haul</a>
    * @version CVS $Id$
   */
  -public class DocumentWrapper implements org.w3c.dom.Document, XMLizable, org.apache.cocoon.xml.XMLizable {
  +public class DocumentWrapper implements org.w3c.dom.Document, XMLizable {
   
       Document document = null;
       
  
  
  
  1.7       +6 -3      xml-cocoon2/src/java/org/apache/cocoon/serialization/ZipArchiveSerializer.java
  
  Index: ZipArchiveSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/serialization/ZipArchiveSerializer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ZipArchiveSerializer.java	31 Jan 2003 22:51:55 -0000	1.6
  +++ ZipArchiveSerializer.java	26 Feb 2003 13:58:04 -0000	1.7
  @@ -56,8 +56,8 @@
   import org.apache.avalon.framework.component.ComponentSelector;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.cocoon.components.CocoonComponentManager;
  -import org.apache.cocoon.environment.Source;
   import org.apache.cocoon.environment.SourceResolver;
  +import org.apache.excalibur.source.Source;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.NamespaceSupport;
  @@ -264,6 +264,7 @@
                   "Cannot specify both 'src' and 'serializer' on a Zip entry '" + name + "'");
           }
   
  +        Source source = null;
           try {
               // Create a new Zip entry
               ZipEntry entry = new ZipEntry(name);
  @@ -271,7 +272,7 @@
   
               if (src != null) {
                   // Get the source and its data
  -                Source source = resolver.resolve(src);
  +                source = resolver.resolveURI(src);
                   InputStream sourceInput = source.getInputStream();
   
                   // Copy the source to the zip
  @@ -324,6 +325,8 @@
               throw se;
           } catch (Exception e) {
               throw new SAXException(e);
  +        } finally {
  +            this.resolver.release( source );
           }
       }
   
  
  
  
  1.8       +149 -172  xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/ListInputStream.java
  
  Index: ListInputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/ListInputStream.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ListInputStream.java	26 Feb 2003 13:28:19 -0000	1.7
  +++ ListInputStream.java	26 Feb 2003 13:58:05 -0000	1.8
  @@ -46,15 +46,14 @@
   
   package org.apache.cocoon.components.flow.javascript;
   
  -import org.apache.cocoon.CascadingIOException;
  -import org.apache.cocoon.ProcessingException;
  -import org.apache.excalibur.source.Source;
  -
   import java.io.IOException;
   import java.io.InputStream;
   import java.util.ArrayList;
   import java.util.List;
   
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.excalibur.source.Source;
  +
   /**
    * Maintains a list of {@link org.apache.cocoon.environment.Source}
    * objects to read the input from. This class keeps track of the
  @@ -64,176 +63,154 @@
    * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
    * @since August 15, 2002
    */
  -public class ListInputStream extends InputStream
  -{
  -  /**
  -   * The <code>List</code> of {@link
  -   * org.apache.cocoon.environment.Source} objects.
  -   */
  -  List sourcesList;
  -
  -  /**
  -   * Location information on each <code>Source</code> object part of
  -   * <code>sourcesList</code>.
  -   */
  -  List sourcesInfo;
  -
  -  /**
  -   * Indicates whether we read all the streams.
  -   */
  -  boolean eof = false;
  -
  -  /**
  -   * The total number of elements in the <code>sourcesList</code> list.
  -   */
  -  private int size;
  -
  -  /**
  -   * What is the current <code>Source</code> object being read from.
  -   */
  -  private int currentIndex;
  -
  -  /**
  -   * The current <code>Source</code> object being read from.
  -   */
  -  protected SourceInfo currentSourceInfo;
  -
  -  /**
  -   * The current <code>InputStream</code> object being read from.
  -   */
  -  private InputStream currentStream;
  -
  -  /**
  -   * Given a <code>List</code> of {@link
  -   * org.apache.cocoon.environment.Source} objects, creates a new
  -   * <code>ListInputStream</code> instance.
  -   *
  -   * @param sources a <code>List</code> of {@link
  -   * org.apache.cocoon.environment.Source}
  -   */
  -  public ListInputStream(List sources)
  -    throws ProcessingException, IOException
  -  {
  -    sourcesList = sources;
  -    currentIndex = 0;
  -    size = sources.size();
  -
  -    sourcesInfo = new ArrayList(size);
  -    for (int i = 0; i < size; i++)
  -      sourcesInfo.add(new SourceInfo((Source)sources.get(i)));
  -
  -    currentSourceInfo = (SourceInfo)sourcesInfo.get(0);
  -    currentStream = ((Source)sources.get(0)).getInputStream();
  -  }
  -
  -  /**
  -   * Simplistic implementation: return the number of number of bytes
  -   * that can be read only from the current stream, without bothering
  -   * to check the remaining streams.
  -   *
  -   * @return an <code>int</code> value
  -   */
  -  public int available()
  -    throws IOException
  -  {
  -    return currentStream.available();
  -  }
  -
  -  public void close()
  -    throws IOException
  -  {
  -    try {
  -      for (int i = 0; i < size; i++)
  -        ((Source)sourcesList.get(i)).getInputStream().close();
  -    }
  -    catch (ProcessingException ex) {
  -      throw new CascadingIOException(ex);
  -    }
  -    finally {
  -      currentStream = null;
  -      eof = true;
  -    }
  -  }
  -
  -  public int read()
  -    throws IOException
  -  {
  -    if (eof)
  -      return -1;
  -
  -    // Read a character from the current stream
  -    int ch = currentStream.read();
  -
  -    // If we reached the end of the stream, try moving to the next one
  -    if (ch == -1) {
  -      currentIndex++;
  -
  -      // If there are no more streams to read, indicate that to our caller
  -      if (currentIndex == size) {
  -        eof = true;
  -        return -1;
  -      }
  -
  -      currentSourceInfo = (SourceInfo)sourcesInfo.get(currentIndex);
  -      try {
  -        currentStream
  -          = ((Source)sourcesList.get(currentIndex)).getInputStream();
  -      }
  -      catch (ProcessingException ex) {
  -        throw new CascadingIOException(ex.toString(), ex);
  -      }
  -    }
  -
  -    // FIXME: I18N
  -    if (ch == '\n')
  -      currentSourceInfo.lineNumbers++;
  -
  -    return ch;
  -  }
  -
  -  public int read(byte[] array)
  -    throws IOException
  -  {
  -    return read(array, 0, array.length);
  -  }
  -
  -  public int read(byte[] array, int offset, int len)
  -    throws IOException
  -  {
  -    if (eof)
  -      return -1;
  -
  -    if (len == 0)
  -      return 0;
  -
  -    int numberOfCharsRead = 0;
  -
  -    for (int i = offset; numberOfCharsRead < len; numberOfCharsRead++, i++) {
  -      int ch = read();
  -      if (ch == -1)
  -        return numberOfCharsRead;
  +public class ListInputStream extends InputStream {
  +    /**
  +     * The <code>List</code> of {@link
  +     * org.apache.cocoon.environment.Source} objects.
  +     */
  +    List sourcesList;
  +
  +    /**
  +     * Location information on each <code>Source</code> object part of
  +     * <code>sourcesList</code>.
  +     */
  +    List sourcesInfo;
  +
  +    /**
  +     * Indicates whether we read all the streams.
  +     */
  +    boolean eof = false;
  +
  +    /**
  +     * The total number of elements in the <code>sourcesList</code> list.
  +     */
  +    private int size;
  +
  +    /**
  +     * What is the current <code>Source</code> object being read from.
  +     */
  +    private int currentIndex;
  +
  +    /**
  +     * The current <code>Source</code> object being read from.
  +     */
  +    protected SourceInfo currentSourceInfo;
  +
  +    /**
  +     * The current <code>InputStream</code> object being read from.
  +     */
  +    private InputStream currentStream;
  +
  +    /**
  +     * Given a <code>List</code> of {@link
  +     * org.apache.cocoon.environment.Source} objects, creates a new
  +     * <code>ListInputStream</code> instance.
  +     *
  +     * @param sources a <code>List</code> of {@link
  +     * org.apache.cocoon.environment.Source}
  +     */
  +    public ListInputStream(List sources)
  +        throws ProcessingException, IOException {
  +        sourcesList = sources;
  +        currentIndex = 0;
  +        size = sources.size();
  +
  +        sourcesInfo = new ArrayList(size);
  +        for (int i = 0; i < size; i++)
  +            sourcesInfo.add(new SourceInfo((Source) sources.get(i)));
   
  -      array[i] = (byte)ch;
  +        currentSourceInfo = (SourceInfo) sourcesInfo.get(0);
  +        currentStream = ((Source) sources.get(0)).getInputStream();
       }
   
  -    return numberOfCharsRead;
  -  }
  +    /**
  +     * Simplistic implementation: return the number of number of bytes
  +     * that can be read only from the current stream, without bothering
  +     * to check the remaining streams.
  +     *
  +     * @return an <code>int</code> value
  +     */
  +    public int available() throws IOException {
  +        return currentStream.available();
  +    }
   
  -  public boolean markSupported()
  -  {
  -    return false;
  -  }
  -
  -  /**
  -   * Return a <code>List</code> of {@link SourceInfo} objects which
  -   * maintains the line number information of a {@link
  -   * org.apache.cocoon.environment.Source} object.
  -   *
  -   * @return a <code>List</code> value
  -   */
  -  public List getSourceInfo()
  -  {
  -    return sourcesInfo;
  -  }
  -}
  +    public void close() throws IOException {
  +        try {
  +            for (int i = 0; i < size; i++)
  +                 ((Source) sourcesList.get(i)).getInputStream().close();
  +        } finally {
  +            currentStream = null;
  +            eof = true;
  +        }
  +    }
  +
  +    public int read() throws IOException {
  +        if (eof)
  +            return -1;
  +
  +        // Read a character from the current stream
  +        int ch = currentStream.read();
  +
  +        // If we reached the end of the stream, try moving to the next one
  +        if (ch == -1) {
  +            currentIndex++;
  +
  +            // If there are no more streams to read, indicate that to our caller
  +            if (currentIndex == size) {
  +                eof = true;
  +                return -1;
  +            }
  +
  +            currentSourceInfo = (SourceInfo) sourcesInfo.get(currentIndex);
  +            currentStream =
  +                ((Source) sourcesList.get(currentIndex)).getInputStream();
  +        }
  +
  +        // FIXME: I18N
  +        if (ch == '\n')
  +            currentSourceInfo.lineNumbers++;
  +
  +        return ch;
  +    }
  +
  +    public int read(byte[] array) throws IOException {
  +        return read(array, 0, array.length);
  +    }
  +
  +    public int read(byte[] array, int offset, int len) throws IOException {
  +        if (eof)
  +            return -1;
  +
  +        if (len == 0)
  +            return 0;
  +
  +        int numberOfCharsRead = 0;
  +
  +        for (int i = offset;
  +            numberOfCharsRead < len;
  +            numberOfCharsRead++, i++) {
  +            int ch = read();
  +            if (ch == -1)
  +                return numberOfCharsRead;
  +
  +            array[i] = (byte) ch;
  +        }
  +
  +        return numberOfCharsRead;
  +    }
  +
  +    public boolean markSupported() {
  +        return false;
  +    }
   
  +    /**
  +     * Return a <code>List</code> of {@link SourceInfo} objects which
  +     * maintains the line number information of a {@link
  +     * org.apache.cocoon.environment.Source} object.
  +     *
  +     * @return a <code>List</code> value
  +     */
  +    public List getSourceInfo() {
  +        return sourcesInfo;
  +    }
  +}
  
  
  

Mime
View raw message