commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider DefaultURLStreamHandler.java
Date Thu, 20 May 2004 19:44:53 GMT
imario      2004/05/20 12:44:53

  Modified:    vfs/src/java/org/apache/commons/vfs/provider
                        DefaultURLStreamHandler.java
  Log:
  handle filesystemoptions
  
  if a new url should be resolved and the current is a file get the parent (=directory) to
correctly resolve relative urls.
  
  Also to make JEditorPane happy.
  
  Revision  Changes    Path
  1.13      +21 -4     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultURLStreamHandler.java
  
  Index: DefaultURLStreamHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultURLStreamHandler.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DefaultURLStreamHandler.java	20 May 2004 17:40:55 -0000	1.12
  +++ DefaultURLStreamHandler.java	20 May 2004 19:44:52 -0000	1.13
  @@ -17,6 +17,8 @@
   
   import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileSystemException;
  +import org.apache.commons.vfs.FileSystemOptions;
  +import org.apache.commons.vfs.FileType;
   
   import java.io.IOException;
   import java.net.URL;
  @@ -33,16 +35,23 @@
       extends URLStreamHandler
   {
       private final VfsComponentContext context;
  +    private final FileSystemOptions fileSystemOptions;
   
       public DefaultURLStreamHandler(final VfsComponentContext context)
       {
  +        this(context, null);
  +    }
  +
  +    public DefaultURLStreamHandler(final VfsComponentContext context, final FileSystemOptions
fileSystemOptions)
  +    {
           this.context = context;
  +        this.fileSystemOptions = fileSystemOptions;
       }
   
       protected URLConnection openConnection(final URL url)
           throws IOException
       {
  -        final FileObject entry = context.resolveFile(url.toExternalForm(), null);
  +        final FileObject entry = context.resolveFile(url.toExternalForm(), fileSystemOptions);
           return new DefaultURLConnection(url, entry.getContent());
       }
   
  @@ -53,16 +62,24 @@
       {
           try
           {
  -            FileObject old = context.resolveFile(u.toExternalForm(), null);
  +            FileObject old = context.resolveFile(u.toExternalForm(), fileSystemOptions);
   
               FileObject newURL;
               if (start > 0 && spec.charAt(start - 1) == ':')
               {
  -                newURL = context.resolveFile(old, spec, null);
  +                newURL = context.resolveFile(old, spec, fileSystemOptions);
               }
               else
               {
  -                newURL = old.resolveFile(spec);
  +                if (old.getType() == FileType.FILE && old.getParent() != null)
  +                {
  +                    // for files we have to resolve relative
  +                    newURL = old.getParent().resolveFile(spec);
  +                }
  +                else
  +                {
  +                    newURL = old.resolveFile(spec);
  +                }
               }
   
               final String url = newURL.getName().getURI();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message