// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 10/2/2001 11:02:32
// 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/fgftp/FgftpDirectoryThread

package com.macromedia.generator.protocol.fgftp;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import sun.net.ftp.FtpClient;

// Referenced classes of package com.macromedia.generator.protocol.fgftp:
//            FgftpURLConnection

class FgftpDirectoryThread extends Thread
{

    FgftpDirectoryThread(FgftpURLConnection fgftpurlconnection, FtpClient ftpclient, URL url, InputStream inputstream, OutputStream outputstream)
    {
        _fld0170 = fgftpurlconnection;
        _fld0171 = ftpclient;
        _fld0172 = url;
        is = inputstream;
        os = new PrintStream(new BufferedOutputStream(outputstream));
    }

    void _mth016D(int i, String s, String s1, URL url)
    {
        os.print("  ");
        os.print("<a href=\"" + url + "\">");
        switch(i)
        {
        case 102: // 'f'
            String s2 = _fld0170._mth0173(url.getFile());
            String s3;
            if(s2 == null)
                s3 = null;
            else
                s3 = _mth0170(s2);
            if(s3 == null)
                s3 = _mth016F("file");
            _mth016E(s3);
            break;

        case 100: // 'd'
            _mth016E(_mth016F("directory"));
            break;
        }
        os.print("\t");
        os.print(s);
        if(i == 100)
            os.print("/");
        else
        if(s1 != null)
            os.print(" (" + s1 + " bytes)");
        os.print("</a>");
        os.print("\n");
    }

    void _mth016E(String s)
    {
        os.print("<img align=\"middle\" src=\"" + s + "\" border=0 width=" + _fld016E + " height=" + _fld016F + ">");
    }

    static String _mth016F(String s)
    {
        return "doc:/lib/images/ftp/" + s + ".gif";
    }

    String _mth0170(String s)
    {
        return (String)_fld016D.get(s);
    }

    public void run()
    {
        try
        {
            is = new BufferedInputStream(is);
            byte abyte0[] = new byte[512];
            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(is));
            String s1 = _fld0172.toExternalForm();
            if(!s1.endsWith("/"))
                s1 = s1 + "/";
            String s2 = "Directory: " + _fld0172.getFile() + "@" + _fld0172.getHost();
            os.println("<html>\n<head>\n<title>" + s2 + "</title>\n</head>");
            os.println("<body>");
            os.println("<h2>" + s2 + "</h2>");
            os.println("<pre>");
            if(_fld0171.welcomeMsg != null)
            {
                os.println(_fld0171.welcomeMsg);
                _fld0171.welcomeMsg = null;
            }
            try
            {
                _mth016D(100, "&lt;Parent Directory&gt;", null, new URL(null, s1 + "../"));
            }
            catch(MalformedURLException _ex) { }
            do
            {
                String s;
                try
                {
                    s = bufferedreader.readLine();
                }
                catch(IOException ioexception)
                {
                    System.err.println("Premature end of FTP directory" + ioexception);
                    break;
                }
                if(s == null)
                    break;
                StringTokenizer stringtokenizer = new StringTokenizer(s, " ");
                try
                {
                    String s3 = stringtokenizer.nextToken();
                    stringtokenizer.nextToken();
                    stringtokenizer.nextToken();
                    stringtokenizer.nextToken();
                    String s4 = stringtokenizer.nextToken();
                    stringtokenizer.nextToken();
                    stringtokenizer.nextToken();
                    stringtokenizer.nextToken();
                    String s5 = stringtokenizer.nextToken();
                    if(!s5.equals(".") && !s5.equals(".."))
                        try
                        {
                            _mth016D(s3.charAt(0) != 'd' ? 102 : 100, s5, s4, new URL(null, s1 + s5));
                        }
                        catch(MalformedURLException _ex) { }
                }
                catch(NoSuchElementException _ex) { }
            } while(true);
            os.println("</pre></body>\n</html>");
        }
        finally
        {
            os.close();
            try
            {
                is.close();
            }
            catch(IOException _ex) { }
            try
            {
                _fld0171.closeServer();
            }
            catch(IOException _ex) { }
        }
    }

    static Hashtable _fld016D;
    static final int _fld016E = Integer.getInteger("hotjava.file.iconwidth", 24).intValue();
    static final int _fld016F = Integer.getInteger("hotjava.file.iconheight", 26).intValue();
    FgftpURLConnection _fld0170;
    FtpClient _fld0171;
    PrintStream os;
    InputStream is;
    URL _fld0172;

    static 
    {
        _fld016D = new Hashtable();
        _fld016D.put("image/gif", _mth016F("gif"));
        _fld016D.put("image/tiff", _mth016F("tiff"));
        _fld016D.put("audio/basic", _mth016F("audio"));
        _fld016D.put("application/octet-stream", _mth016F("compress"));
        _fld016D.put("application/postscript", _mth016F("ps"));
        _fld016D.put("text/plain", _mth016F("text"));
    }
}