avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/repository/api/src/java/org/apache/avalon/repository ArtifactReference.java
Date Mon, 17 Nov 2003 08:09:38 GMT
mcconnell    2003/11/17 00:09:38

  Added:       repository/api/src/java/org/apache/avalon/repository
                        ArtifactReference.java
  Log:
  An artifact resolvable to a URL.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/ArtifactReference.java
  
  Index: ArtifactReference.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 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 "Jakarta", "Apache Avalon", "Avalon Framework" 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. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.repository ;
  
  
  import java.io.Serializable ;
  import java.text.ParseException ;
  
  
  /**
   * A reference to an artifact.
   *  
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $
   */
  public class ArtifactReference extends Artifact
  {
      // ------------------------------------------------------------------------
      // static
      // ------------------------------------------------------------------------
  
      public static final String SEP = "/";
  
      // ------------------------------------------------------------------------
      // state
      // ------------------------------------------------------------------------
  
     /** 
      * the artifact base path 
      */
      private final String m_base;
  
     /** 
      * the name of the the artifact relative to the base 
      */
      private final String m_filename;
  
     /** 
      * the computed path
      */
      private final String m_path;
  
      
      // ------------------------------------------------------------------------
      // constructors
      // ------------------------------------------------------------------------
          
      /**
       * Creation of a new artifact reference.
       *
       * @param base the base path to the artifact 
       * @param filename the artifact filename
       */
      public ArtifactReference( String base, String filename )
      {
          if ( null == base ) throw new NullPointerException( "base" );
          if ( null == filename ) throw new NullPointerException( "filename" );
          
          m_base = getCleanPath( base );
          if( filename.indexOf( SEP ) > 0 )
          {
              final String error = "Invalid name - illegal character '/' in filename: " +
filename;
              throw new IllegalArgumentException( error );
          }
  
          m_filename = filename;
          m_path = m_base + SEP + m_filename;   
      }
      
      // ------------------------------------------------------------------------
      // accessors
      // ------------------------------------------------------------------------
  
      /**
       * Return the base path to the artifact. This is equivelent to the 
       * containing directory without a leading or trailing seperator.
       *
       * @return the base path.
       */
      public String getBase()
      {
          return m_base;
      }
      
      /**
       * Return the name of the artifact.
       * @return the name.
       */
      public String getFilename()
      {
          return m_filename ;
      }
      
      /**
       * Gets the artifact path.  The value returned is equal to 
       * BASE/FILENAME
       *
       * @return the artifact path
       */
      public String getPath()
      {
          return m_path;
      }
      
      // ------------------------------------------------------------------------
      // Object
      // ------------------------------------------------------------------------    
      
      /**
       * Returns the artifact specification String.
       * 
       * @see java.lang.Object#toString()
       */
      public String toString()
      {
          return getPath() ;
      }
      
      /**
       * Gets the URL to the artifact given a base URL for the repository.
       * 
       * @param a_repository the base URL to the repository
       * @return the full URL to the artifact
       */
      public String getURL( final String repository )
      {
          if( repository.endsWith( SEP ) )
          {
              return repository + getPath();
          }
          else
          {
              return repository + SEP + getPath();
          }
      }
  
     /**
      * Remove leading and trainly seperators.
      * @param the path value to clean
      * @return the clean path
      */
      private String getCleanPath( final String path )
      {
          if( path.startsWith( SEP ) ) return getCleanPath( path.substring( 1, path.length()
) );
          if( path.endsWith( SEP ) ) return getCleanPath( path.substring( 0, path.length()
-1 ) );
          return path;
      }
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message