cziegeler    2002/06/12 02:24:14

  Modified:    monitor/src/java/org/apache/avalon/excalibur/monitor
                        MonitorableURLSource.java
               sourceresolve/src/java/org/apache/excalibur/source
                        Source.java
               sourceresolve/src/java/org/apache/excalibur/source/impl
                        ResourceSource.java URLSource.java
  Added:       sourceresolve/src/java/org/apache/excalibur/source/impl
                        AbstractSource.java
  Log:
  Adding getLastModified, getContentLength to Source interface
  
  Revision  Changes    Path
  1.5       +2 -2      
jakarta-avalon-excalibur/monitor/src/java/org/apache/avalon/excalibur/monitor/MonitorableURLSource.java
  
  Index: MonitorableURLSource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/monitor/src/java/org/apache/avalon/excalibur/monitor/MonitorableURLSource.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MonitorableURLSource.java 4 Jun 2002 06:26:03 -0000       1.4
  +++ MonitorableURLSource.java 12 Jun 2002 09:24:14 -0000      1.5
  @@ -34,7 +34,7 @@
       public Resource getResource()
           throws Exception
       {
  -        this.getInfos();
  +        this.checkInfos();
           if( null == this.file )
           {
               return new FileResource( this.file.getAbsolutePath() );
  
  
  
  1.5       +37 -2     
jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/Source.java
  
  Index: Source.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/Source.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Source.java       13 May 2002 12:17:40 -0000      1.4
  +++ Source.java       12 Jun 2002 09:24:14 -0000      1.5
  @@ -9,6 +9,7 @@
   
   import java.io.IOException;
   import java.io.InputStream;
  +import java.util.Iterator;
   
   /**
    * Description of a source. This interface provides a simple interface
  @@ -86,7 +87,41 @@
       /**
        * The mime-type of the content described by this object.
        * If the source is not able to determine the mime-type by itself
  -     * this can be null.
  +     * this can be <code>null</code>.
        */
       String getMimeType();
  +
  +    /**
  +     * Return the content length of the content or -1 if the length is
  +     * unknown
  +     */
  +    long getContentLength();
  +
  +    /**
  +     * Get the last modification date.
  +     * @return The last modification in milliseconds since January 1, 1970 
GMT
  +     *         or 0 if it is unknown
  +     */
  +    long getLastModified();
  +
  +    /**
  +     * Get the value of a parameter.
  +     * Using this it is possible to get custom information provided by the
  +     * source implementation, like an expires date, HTTP headers etc.
  +     */
  +    String getParameter(String name);
  +
  +    /**
  +     * Get the value of a parameter.
  +     * Using this it is possible to get custom information provided by the
  +     * source implementation, like an expires date, HTTP headers etc.
  +     */
  +    long getParameterAsLong(String name);
  +
  +    /**
  +     * Get parameter names
  +     * Using this it is possible to get custom information provided by the
  +     * source implementation, like an expires date, HTTP headers etc.
  +     */
  +    Iterator getParameterNames();
   }
  
  
  
  1.3       +3 -32     
jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/ResourceSource.java
  
  Index: ResourceSource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/ResourceSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ResourceSource.java       13 May 2002 12:17:40 -0000      1.2
  +++ ResourceSource.java       12 Jun 2002 09:24:14 -0000      1.3
  @@ -16,17 +16,16 @@
   /**
    * Description of a source which is described by the resource protocol
    * which gets a resource from the classloader.
  + * FIXME: Get mime-type, content-length, lastModified
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @version CVS $Revision$ $Date$
    */
   
   public final class ResourceSource
  +    extends AbstractSource
       implements Source
   {
  -    /** The system identifier */
  -    private String systemId;
  -
       /** Location of the resource */
       private String location;
   
  @@ -55,14 +54,6 @@
       }
   
       /**
  -     * Return the unique identifer for this source
  -     */
  -    public String getSystemId()
  -    {
  -        return this.systemId;
  -    }
  -
  -    /**
        *  Get the Validity object. This can either wrap the last modification
        *  date or the expires information or...
        *  If it is currently not possible to calculate such an information
  @@ -72,26 +63,6 @@
       {
           // we are always valid
           return NOPValidity.SHARED_INSTANCE;
  -    }
  -
  -    /**
  -     * Refresh this object and update the last modified date
  -     * and content length.
  -     */
  -    public void discardValidity()
  -    {
  -        // nothing to do
  -    }
  -
  -    /**
  -     * The mime-type of the content described by this object.
  -     * If the source is not able to determine the mime-type by itself
  -     * this can be null.
  -     */
  -    public String getMimeType()
  -    {
  -        // FIXME
  -        return null;
       }
   
   }
  
  
  
  1.12      +28 -64    
jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/URLSource.java
  
  Index: URLSource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/URLSource.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- URLSource.java    3 Jun 2002 12:11:10 -0000       1.11
  +++ URLSource.java    12 Jun 2002 09:24:14 -0000      1.12
  @@ -29,12 +29,14 @@
   
   /**
    * Description of a source which is described by an URL.
  + * FIXME: Get mime-type
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @version CVS $Revision$ $Date$
    */
   
   public class URLSource
  +    extends AbstractSource
       implements Source
   {
   
  @@ -51,12 +53,6 @@
       /** Identifier for file urls */
       protected final String FILE = "file:";
   
  -    /** The last modification date or 0 */
  -    protected long lastModificationDate;
  -
  -    /** The system id */
  -    protected String systemId;
  -
       /** The URL of the source */
       protected URL url;
   
  @@ -66,9 +62,6 @@
       /** The file, if URL is a file */
       protected File file;
   
  -    /** Are we initialized? */
  -    protected boolean gotInfos;
  -
       /** The <code>SourceParameters</code> used for a post*/
       protected SourceParameters parameters;
   
  @@ -149,58 +142,47 @@
       /**
        * Get the last modification date and content length of the source.
        * Any exceptions are ignored.
  +     * Override this to get the real information
        */
       protected void getInfos()
       {
  -        if( !this.gotInfos )
  +        if( null != this.file )
           {
  -            if( null != this.file )
  -            {
  -                this.lastModificationDate = this.file.lastModified();
  -            }
  -            else
  +            this.lastModificationDate = this.file.lastModified();
  +            this.contentLength = this.file.length();
  +        }
  +        else
  +        {
  +            if( !this.isPost )
               {
  -                if( !this.isPost )
  +                try
                   {
  -                    try
  +                    if( null == this.connection )
                       {
  -                        if( null == this.connection )
  +                        this.connection = this.url.openConnection();
  +                        String userInfo = this.getUserInfo();
  +                        if( this.url.getProtocol().startsWith( "http" ) && 
userInfo != null )
                           {
  -                            this.connection = this.url.openConnection();
  -                            String userInfo = this.getUserInfo();
  -                            if( this.url.getProtocol().startsWith( "http" ) 
&& userInfo != null )
  -                            {
  -                                this.connection.setRequestProperty( 
"Authorization", "Basic " + SourceUtil.encodeBASE64( userInfo ) );
  -                            }
  +                            this.connection.setRequestProperty( 
"Authorization", "Basic " + SourceUtil.encodeBASE64( userInfo ) );
                           }
  -                        this.lastModificationDate = 
this.connection.getLastModified();
  -                    }
  -                    catch( IOException ignore )
  -                    {
  -                        this.lastModificationDate = 0;
                       }
  +                    this.lastModificationDate = 
this.connection.getLastModified();
  +                    this.contentLength = this.connection.getContentLength();
                   }
  -                else
  +                catch( IOException ignore )
                   {
  -                    // do not open connection when using post!
  -                    this.lastModificationDate = 0;
  +                    super.getInfos();
                   }
               }
  -            this.gotInfos = true;
  +            else
  +            {
  +                // do not open connection when using post!
  +                super.getInfos();
  +            }
           }
       }
   
       /**
  -     * Get the last modification date of the source or 0 if it
  -     * is not possible to determine the date.
  -     */
  -    public long getLastModified()
  -    {
  -        getInfos();
  -        return this.lastModificationDate;
  -    }
  -
  -    /**
        * Return an <code>InputStream</code> object to read from the source.
        *
        * @throws ResourceNotFoundException if file not found or
  @@ -212,7 +194,7 @@
       {
           try
           {
  -            getInfos();
  +            this.checkInfos();
               InputStream input = null;
               if( null != this.file )
               {
  @@ -334,14 +316,6 @@
       }
   
       /**
  -     * Return the unique identifer for this source
  -     */
  -    public String getSystemId()
  -    {
  -        return this.systemId;
  -    }
  -
  -    /**
        *  Get the Validity object. This can either wrap the last modification
        *  date or the expires information or...
        *  If it is currently not possible to calculate such an information
  @@ -377,17 +351,7 @@
       {
           // reset connection
           this.connection = null;
  -        this.gotInfos = false;
  +        super.discardValidity();
       }
   
  -    /**
  -     * The mime-type of the content described by this object.
  -     * If the source is not able to determine the mime-type by itself
  -     * this can be null.
  -     */
  -    public String getMimeType()
  -    {
  -        // FIXME
  -        return null;
  -    }
   }
  
  
  
  1.1                  
jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/AbstractSource.java
  
  Index: AbstractSource.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.txt file.
   */
  package org.apache.excalibur.source.impl;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.Iterator;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceException;
  import org.apache.excalibur.source.SourceParameters;
  import org.apache.excalibur.source.SourceValidity;
  
  /**
   * Abstract base class for a source implementation.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/06/12 09:24:14 $
   */
  
  public abstract class AbstractSource
      implements Source
  {
  
      protected boolean gotInfos = false;
  
      protected long lastModificationDate;
  
      protected long contentLength;
  
      protected String systemId;
  
      /**
       * Get the last modification date and content length of the source.
       * Any exceptions are ignored.
       * Override this to get the real information
       */
      protected void getInfos()
      {
          this.contentLength = -1;
          this.lastModificationDate = 0;
      }
  
      protected void checkInfos()
      {
          if( !this.gotInfos )
          {
              this.getInfos();
              this.gotInfos = true;
          }
      }
  
      /**
       * Return an <code>InputStream</code> object to read from the source.
       *
       * @throws ResourceNotFoundException if file not found or
       *         HTTP location does not exist.
       * @throws IOException if I/O error occured.
       */
      public InputStream getInputStream()
          throws IOException, SourceException
      {
          return null;
      }
  
  
      /**
       * Return the unique identifer for this source
       */
      public String getSystemId()
      {
          return this.systemId;
      }
  
      /**
       *  Get the Validity object. This can either wrap the last modification
       *  date or the expires information or...
       *  If it is currently not possible to calculate such an information
       *  <code>null</code> is returned.
       */
      public SourceValidity getValidity()
      {
          return null;
      }
  
      /**
       * Refresh this object and update the last modified date
       * and content length.
       */
      public void discardValidity()
      {
          this.gotInfos = false;
      }
  
      /**
       * The mime-type of the content described by this object.
       * If the source is not able to determine the mime-type by itself
       * this can be null.
       */
      public String getMimeType()
      {
          return null;
      }
  
      /**
       * Return the content length of the content or -1 if the length is
       * unknown
       */
      public long getContentLength()
      {
          this.checkInfos();
          return this.contentLength;
      }
  
      /**
       * Get the last modification date of the source or 0 if it
       * is not possible to determine the date.
       */
      public long getLastModified()
      {
          this.checkInfos();
          return this.lastModificationDate;
      }
  
      /**
       * Get the value of a parameter.
       * Using this it is possible to get custom information provided by the
       * source implementation, like an expires date, HTTP headers etc.
       */
      public String getParameter(String name) {
          this.checkInfos();
          return null;
      }
  
      /**
       * Get the value of a parameter.
       * Using this it is possible to get custom information provided by the
       * source implementation, like an expires date, HTTP headers etc.
       */
      public long getParameterAsLong(String name) {
          this.checkInfos();
          return 0;
      }
  
      /**
       * Get parameter names
       * Using this it is possible to get custom information provided by the
       * source implementation, like an expires date, HTTP headers etc.
       */
      public Iterator getParameterNames() {
          this.checkInfos();
          return emptyIterator;
      }
  
      protected static EmptyIterator emptyIterator = new EmptyIterator();
  
  }
  
  class EmptyIterator implements Iterator {
      public boolean hasNext() { return false; }
      public Object next() { return null; }
      public void remove() {}
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to