// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 10/2/2001 11:02:55
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/protocol/fgjava/FgjavaURLConnection

package com.macromedia.generator.protocol.fgjava;

import com.macromedia.generator.utils.GenInfo;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.util.Hashtable;
import java.util.StringTokenizer;

public class FgjavaURLConnection extends URLConnection
{

    FgjavaURLConnection(URL url)
    {
        super(url);
        ED = null;
    }

    public void connect()
        throws IOException
    {
        String s = url.getFile();
        String s1 = _mth017A(s);
        if(s1.charAt(0) == '/')
            s1 = s1.substring(1, s1.length());
        Hashtable hashtable = _mth017C(s);
        _fld0178 = _mth017D(s1, hashtable);
        if(_fld0178 == null)
        {
            throw new IOException("Error processing Java stream in URL: " + url.toExternalForm());
        } else
        {
            connected = true;
            return;
        }
    }

    public synchronized InputStream getInputStream()
        throws IOException
    {
        if(!connected)
            connect();
        return _fld0178;
    }

    private InputStream _mth0178(Class class1, Hashtable hashtable)
    {
        InputStream inputstream = null;
        try
        {
            Class aclass[] = new Class[2];
            aclass[0] = Class.forName("java.util.Hashtable");
            aclass[1] = Class.forName("com.macromedia.generator.utils.GenInfo");
            Method method = class1.getMethod("getStreamEx", aclass);
            Object aobj[] = new Object[2];
            aobj[0] = hashtable;
            aobj[1] = ED;
            inputstream = (InputStream)method.invoke(null, aobj);
        }
        catch(Exception _ex) { }
        catch(Error _ex) { }
        return inputstream;
    }

    private static synchronized Class _mth0179(String s)
        throws IOException
    {
        if(loadedClasses == null)
            loadedClasses = new Hashtable();
        Class class1;
        try
        {
            class1 = (Class)loadedClasses.get(s);
            if(class1 == null)
            {
                class1 = Class.forName(s);
                loadedClasses.put(s, class1);
            }
        }
        catch(ClassNotFoundException _ex)
        {
            throw new IOException("Class loading failed for class " + s + ": ClassNotFoundException");
        }
        catch(ClassCastException _ex)
        {
            throw new IOException("Class loading failed for class " + s + ": ClassCastException");
        }
        catch(Exception _ex)
        {
            throw new IOException("Class loading failed for class " + s + ": Exception");
        }
        return class1;
    }

    private static String _mth017A(String s)
    {
        if(s == null)
            throw new IllegalArgumentException();
        int i = s.indexOf(63);
        if(i == -1)
            i = s.length();
        String s1 = s.substring(0, i);
        return s1;
    }

    private static String _mth017B(String s, StringBuffer stringbuffer)
    {
        stringbuffer.setLength(0);
        for(int i = 0; i < s.length(); i++)
        {
            char c = s.charAt(i);
            switch(c)
            {
            case 43: // '+'
                stringbuffer.append(' ');
                break;

            case 37: // '%'
                try
                {
                    stringbuffer.append((char)Integer.parseInt(s.substring(i + 1, i + 3), 16));
                }
                catch(NumberFormatException _ex)
                {
                    throw new IllegalArgumentException();
                }
                i += 2;
                break;

            default:
                stringbuffer.append(c);
                break;
            }
        }

        return stringbuffer.toString();
    }

    private static Hashtable _mth017C(String s)
    {
        if(s == null)
            throw new IllegalArgumentException();
        Hashtable hashtable = new Hashtable();
        int i = s.indexOf(63);
        if(i > -1)
        {
            String s1 = s.substring(i + 1, s.length());
            StringBuffer stringbuffer = new StringBuffer();
            for(StringTokenizer stringtokenizer = new StringTokenizer(s1, "&"); stringtokenizer.hasMoreTokens();)
            {
                String s2 = stringtokenizer.nextToken();
                int j = s2.indexOf(61);
                if(j > 0)
                {
                    String s3 = _mth017B(s2.substring(0, j), stringbuffer);
                    String s4 = _mth017B(s2.substring(j + 1, s2.length()), stringbuffer);
                    hashtable.put(s3, s4);
                }
            }

        }
        return hashtable;
    }

    private InputStream _mth017D(String s, Hashtable hashtable)
        throws IOException
    {
        InputStream inputstream = null;
        Class class1 = _mth0179(s);
        if(class1 != null)
        {
            inputstream = _mth0178(class1, hashtable);
            if(inputstream == null)
                try
                {
                    Class aclass[] = new Class[1];
                    aclass[0] = Class.forName("java.util.Hashtable");
                    Method method = class1.getMethod("getStream", aclass);
                    Object aobj[] = new Object[1];
                    aobj[0] = hashtable;
                    inputstream = (InputStream)method.invoke(null, aobj);
                }
                catch(ClassNotFoundException _ex)
                {
                    throw new IOException("Class loading failed for class " + s + ": ClassNotFoundException");
                }
                catch(NoSuchMethodException _ex)
                {
                    throw new IOException("Class loading failed for class " + s + ": NoSuchMethodException");
                }
                catch(IllegalAccessException _ex)
                {
                    throw new IOException("Class loading failed for class " + s + ": IllegalAccessException");
                }
                catch(IllegalArgumentException _ex)
                {
                    throw new IOException("Class loading failed for class " + s + ": IllegalArgumentException");
                }
                catch(InvocationTargetException _ex)
                {
                    throw new IOException("Class loading failed for class " + s + ": InvocationTargetException");
                }
        }
        return inputstream;
    }

    public void setGenInfo(GenInfo geninfo)
    {
        ED = geninfo;
    }

    InputStream _fld0178;
    protected static Hashtable loadedClasses;
    private GenInfo ED;
}