cziegeler    02/02/15 03:54:29

  Modified:    src/scratchpad/org/apache/avalon/excalibur/source
                        SourceResolver.java SourceResolverImpl.java
  Log:
  adding baseURI to source resolver
  
  Revision  Changes    Path
  1.10      +11 -1     
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolver.java
  
  Index: SourceResolver.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolver.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SourceResolver.java       5 Feb 2002 13:06:35 -0000       1.9
  +++ SourceResolver.java       15 Feb 2002 11:54:29 -0000      1.10
  @@ -29,7 +29,7 @@
    * like Composable, Initializable, Disposable etc.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.9 $ $Date: 2002/02/05 13:06:35 $
  + * @version CVS $Revision: 1.10 $ $Date: 2002/02/15 11:54:29 $
    */
   
   public interface SourceResolver
  @@ -39,14 +39,24 @@
   
       /**
        * Get a <code>Source</code> object.
  +     * This is a shortcut for <code>resolve(location, null, null)</code>
        */
       Source resolve(String location)
       throws MalformedURLException, IOException, ComponentException;
   
       /**
        * Get a <code>Source</code> object.
  +     * @param location - the URI to resolve. If this is relative it is either
  +     *                   resolved relative to the base parameter (if not 
null)
  +     *                   or relative to a base setting of the source resolver
  +     *                   itself.
  +     * @param base - a base URI for resolving relative locations. This
  +     *               is optional and can be <code>null</code>.
  +     * @param parameters - Additional parameters for the URI. The parameters
  +     *                     are specific to the used protocol.
        */
       Source resolve(String location,
  +                   String base,
                      SourceParameters parameters)
       throws MalformedURLException, IOException, ComponentException;
   
  
  
  
  1.16      +21 -11    
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolverImpl.java
  
  Index: SourceResolverImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolverImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SourceResolverImpl.java   5 Feb 2002 20:45:16 -0000       1.15
  +++ SourceResolverImpl.java   15 Feb 2002 11:54:29 -0000      1.16
  @@ -52,7 +52,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @version $Id: SourceResolverImpl.java,v 1.15 2002/02/05 20:45:16 
bloritsch Exp $
  + * @version $Id: SourceResolverImpl.java,v 1.16 2002/02/15 11:54:29 
cziegeler Exp $
    */
   public class SourceResolverImpl
   extends AbstractLogEnabled
  @@ -140,46 +140,53 @@
       public Source resolve(String location)
       throws MalformedURLException, IOException, ComponentException
       {
  -        return this.resolve(location, null);
  +        return this.resolve(location, null, null);
       }
   
       /**
        * Get a <code>Source</code> object.
        */
       public Source resolve(String location,
  +                          String baseURI,
                             SourceParameters parameters)
       throws MalformedURLException, IOException, ComponentException
       {
           if ( this.getLogger().isDebugEnabled() ) {
  -            this.getLogger().debug("Resolving '"+location+"' in context '" + 
m_baseURL + "'");
  +            this.getLogger().debug("Resolving '"+location+"' with base 
'"+baseURI+"' in context '" + m_baseURL + "'");
           }
           if (location == null) throw new MalformedURLException("Invalid 
System ID");
  +        if ( null != baseURI && baseURI.indexOf(':') == -1)
  +        {
  +            throw new MalformedURLException("BaseURI is not valid, it must 
contain a protocol: " + baseURI);
  +        }
   
           // first step: create systemID
           String systemID;
   
  +        if (baseURI == null) baseURI = m_baseURL.toExternalForm();
  +
           if (location.length() == 0) {
  -            systemID = m_baseURL.toExternalForm();
  +            systemID = baseURI;
           } else if (location.indexOf(":") > 1)
           {
               systemID = location;
           }
           else if (location.charAt(0) == '/')
           {
  -            systemID = new StringBuffer(m_baseURL.getProtocol())
  -                           .append(":").append(location).toString();
  +            final int protocolEnd = baseURI.indexOf(':');
  +            systemID = new StringBuffer(baseURI.substring( protocolEnd + 1))
  +                               .append(location).toString();
           // windows: absolute paths can start with drive letter
           }
           else if (location.length() > 1 && location.charAt(1) == ':')
           {
  -            systemID = new StringBuffer(m_baseURL.getProtocol())
  -                           .append(":/").append(location).toString();
  +            systemID = new 
StringBuffer("file:/").append(location).toString();
           }
           else
           {
  -            if (m_baseURL.getProtocol().equals("file") == true)
  +            if (baseURI.startsWith("file:") == true)
               {
  -                File temp = new 
File(m_baseURL.toExternalForm().substring("file:".length()), location);
  +                File temp = new File(baseURI.substring("file:".length()), 
location);
                   String path = temp.getAbsolutePath();
                   // windows paths starts with drive letter
                   if (path.charAt(0) != File.separator.charAt(0))
  @@ -193,7 +200,10 @@
               }
               else
               {
  -                systemID = new URL(m_baseURL, location).toExternalForm();
  +                final StringBuffer buffer = new StringBuffer(baseURI);
  +                if ( !baseURI.endsWith("/") ) buffer.append('/');
  +                buffer.append(location);
  +                systemID = buffer.toString();
               }
           }
           if ( this.getLogger().isDebugEnabled() )
  
  
  

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

Reply via email to