/*
 * Copyright 2002, 2003,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.vfs.provider;

import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

/**
 * A default URL stream handler that will work for most file systems.
 *
 * @author <a href="mailto:brian@mmmanager.org">Brian Olsen</a>
 * @version $Revision: 1.5 $ $Date: 2002/07/05 04:08:17 $
 */
public class DefaultURLStreamHandler
    extends URLStreamHandler
{
    private final VfsComponentContext context;

    public DefaultURLStreamHandler(final VfsComponentContext context)
    {
        this.context = context;
    }

    protected URLConnection openConnection(final URL url)
        throws IOException
    {
        final FileObject entry = context.resolveFile(url.toExternalForm(), null);
        return new DefaultURLConnection(url, entry.getContent());
    }

    protected void parseURL(final URL u,
                            final String spec,
                            final int start,
                            final int limit)
    {
        try
        {
            FileObject old = context.resolveFile(u.toExternalForm(), null);

            FileObject newURL;
            if (start > 0 && spec.charAt(start - 1) == ':')
            {
                newURL = context.resolveFile(old, spec, null);
            }
            else
            {
                newURL = old.resolveFile(spec);
            }

            final String url = newURL.getName().getURI();
            final StringBuffer filePart = new StringBuffer();
            final String protocolPart = UriParser.extractScheme(url, filePart);

            setURL(u, protocolPart, null, -1, null, null, filePart.toString(), null, null);
        }
        catch (FileSystemException fse)
        {
            // This is rethrown to MalformedURLException in URL anyway
            throw new RuntimeException(fse.getMessage());
        }
    }

    protected String toExternalForm(final URL u)
    {
        return u.getProtocol() + ":" + u.getFile();
    }
}

@@ -757,16 +757,105 @@
 ception;
+%0Aimport org.apache.commons.vfs.FileSystemOptions;%0Aimport org.apache.commons.vfs.FileType;
 %0A%0Aimport
@@ -1280,16 +1280,71 @@
 context;
+%0A    private final FileSystemOptions fileSystemOptions;
 %0A%0A    pu
@@ -1429,26 +1429,233 @@
 this
-.context = context
+(context, null);%0A    %7D%0A%0A    public DefaultURLStreamHandler(final VfsComponentContext context, final FileSystemOptions fileSystemOptions)%0A    %7B%0A        this.context = context;%0A        this.fileSystemOptions = fileSystemOptions
 ;%0A  
@@ -1825,20 +1825,33 @@
 Form(), 
-null
+fileSystemOptions
 );%0A     
@@ -2193,20 +2193,33 @@
 Form(), 
-null
+fileSystemOptions
 );%0A%0A    
@@ -2375,23 +2375,307 @@
 , spec, 
-null);%0A
+fileSystemOptions);%0A            %7D%0A            else%0A            %7B%0A                if (old.getType() == FileType.FILE && old.getParent() != null)%0A                %7B%0A                    // for files we have to resolve relative%0A                    newURL = old.getParent().resolveFile(spec);%0A    
         
@@ -2684,32 +2684,36 @@
   %7D%0A            
+ 
+   
 else%0A           
@@ -2705,34 +2705,41 @@
 lse%0A            
-%7B%0A
+    %7B%0A   
                 
@@ -2730,32 +2730,33 @@
                 
+ 
 newURL = old.res
@@ -2763,32 +2763,50 @@
 olveFile(spec);%0A
+                %7D%0A
             %7D%0A%0A 

handle filesystemoptions