// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:43:29
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/app/UrlDataSource

package com.macromedia.generator.app;

import com.macromedia.generator.platform.Mac;
import com.macromedia.generator.protocol.fgjava.FgjavaURLConnection;
import com.macromedia.generator.protocol.fgjdbc.FgjdbcURLConnection;
import com.macromedia.generator.utils.GenUtils;
import java.io.*;
import java.net.*;

// Referenced classes of package com.macromedia.generator.app:
//            StreamDataSource, FlashEnvironment

public class UrlDataSource extends StreamDataSource
{

    public UrlDataSource()
    {
    }

    public String[][] getData(String s)
    {
        Object obj = null;
        String as[][] = null;
        boolean flag = true;
        if(s == null || s.length() == 0)
        {
            if(env != null)
                env.logMessage("com.macromedia.generator.resources.DataSourceData", "EmptyPath", null);
            return null;
        }
        Mac mac = Mac.getMac();
        if(s.charAt(0) == '#' || s.charAt(0) == '=')
        {
            String s1 = new String();
            int j = s.length();
            for(int k = 1; k < j; k++)
                if(s.startsWith("/n/r", k))
                {
                    s1 = s1 + "\n\r";
                    k += 3;
                } else
                {
                    s1 = s1 + s.charAt(k);
                }

            try
            {
                DataInputStream datainputstream1 = new DataInputStream(new StringBufferInputStream(s1));
                as = super.getData(datainputstream1, s);
                flag = false;
                datainputstream1.close();
            }
            catch(IOException ioexception1)
            {
                String s8 = ioexception1.getLocalizedMessage();
                String s9 = s8 == null ? s : s8 + ": " + s1;
                if(env != null)
                    env.logMessage("com.macromedia.generator.resources.DataSourceData", "IOException", s9);
                as = null;
            }
        } else
        {
            URL url;
            try
            {
                url = new URL(s);
            }
            catch(MalformedURLException _ex)
            {
                File file;
                if(mac != null)
                {
                    String s3 = mac.makeJavaPretty(s);
                    file = new File(s3);
                    if(!file.exists() || !file.isFile())
                        file = new File(s3.substring(1));
                } else
                {
                    file = new File(s);
                }
                try
                {
                    if(!file.isAbsolute())
                        file = new File(env.getDirectory(), file.getPath());
                    if(!file.exists() || !file.isFile())
                        throw new MalformedURLException();
                    String s4 = file.getAbsolutePath();
                    if(s4.startsWith("\\"))
                    {
                        if(!GenUtils.isJava2())
                            url = GenUtils.toURL(file);
                        else
                            url = file.toURL();
                    } else
                    {
                        String s6 = System.getProperty("file.separator");
                        if(s6.length() == 1)
                        {
                            char c = s6.charAt(0);
                            if(c != '/')
                                s4 = s4.replace(c, '/');
                            if(s4.charAt(0) != '/')
                                s4 = '/' + s4;
                        }
                        s4 = "file://" + s4;
                        url = new URL(s4);
                    }
                }
                catch(MalformedURLException _ex2)
                {
                    if(env != null)
                        env.logMessage("com.macromedia.generator.resources.DataSourceData", "InvalidPath", s);
                    url = null;
                }
            }
            if(url != null)
            {
                String s2;
                if(mac != null)
                    s2 = url.toString().trim();
                try
                {
                    URLConnection urlconnection = url.openConnection();
                    if(urlconnection instanceof FgjdbcURLConnection)
                    {
                        FgjdbcURLConnection fgjdbcurlconnection = (FgjdbcURLConnection)urlconnection;
                        fgjdbcurlconnection.setLogWriter(env.logLevel(), env.getLogWriter());
                    } else
                    if(urlconnection instanceof FgjavaURLConnection)
                    {
                        FgjavaURLConnection fgjavaurlconnection = (FgjavaURLConnection)urlconnection;
                        if(env != null)
                            fgjavaurlconnection.setGenInfo(env.getGenInfo());
                    }
                    DataInputStream datainputstream = new DataInputStream(urlconnection.getInputStream());
                    as = super.getData(datainputstream, s);
                    datainputstream.close();
                }
                catch(IOException ioexception)
                {
                    String s5 = ioexception.getLocalizedMessage();
                    String s7 = s5 == null ? s : s5 + ": " + s;
                    if(env != null)
                        env.logMessage("com.macromedia.generator.resources.DataSourceData", "IOException", s7);
                    as = null;
                }
            }
        }
        if(as != null && env != null && env.logLevel() > 2)
        {
            if(flag)
                env.logMessage("com.macromedia.generator.resources.DataSourceData", "DumpData", s);
            int i = as.length;
            StringBuffer stringbuffer = new StringBuffer(128);
            for(int l = 0; l < i; l++)
            {
                stringbuffer.setLength(0);
                stringbuffer.append(l + 1);
                stringbuffer.append(": ");
                int i1 = as[l].length;
                for(int j1 = 0; j1 < i1; j1++)
                {
                    if(j1 > 0)
                        stringbuffer.append(", ");
                    stringbuffer.append(as[l][j1]);
                }

                env.logMessage("com.macromedia.generator.resources.DataSourceData", "DumpRow", stringbuffer.toString());
            }

        }
        return as;
    }

    public static void main(String args[])
    {
        UrlDataSource urldatasource = new UrlDataSource();
        String args1[][] = urldatasource.getData(args[0]);
        int i = args1.length;
        int j = args1[0].length;
        for(int k = 0; k < i; k++)
        {
            for(int l = 0; l < j; l++)
                System.out.print(args1[k][l] + ",");

            System.out.println("");
        }

    }
}