// Decompiled by Jad v1.5.7. Copyright 1997-99 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Context.java

package com.symantec.itools.lang;

import java.applet.Applet;
import java.net.MalformedURLException;
import java.net.URL;

public class Context
{

    public Context()
    {
    }

    public static boolean isApplet()
    {
        return applet != null;
    }

    public static boolean isApplication()
    {
        return applet == null;
    }

    public static void setApplet(Applet applet1)
    {
        applet = applet1;
        initialized = true;
    }

    public static Applet getApplet()
    {
        return applet;
    }

    public static void setDocumentBase(URL url)
    {
        if(System.getProperty("java.vendor").startsWith("Netscape") && url.getHost() == "" && System.getProperty("os.name").startsWith("Windows"))
        {
            String s = url.getFile();
            String s1 = s.substring(0, s.indexOf(58) + 1);
            s = s.substring(s.indexOf(58) + 1);
            try
            {
                documentBase = new URL(url.getProtocol(), s1, s);
            }
            catch(MalformedURLException _ex) { }
        }
        else
        {
            documentBase = url;
        }
        initialized = true;
    }

    private static void initializeApp()
    {
        StringBuffer stringbuffer = new StringBuffer(System.getProperty("user.dir"));
        int i = stringbuffer.length();
        try
        {
            char c = System.getProperty("file.separator").charAt(0);
            if(c != '/')
            {
                for(int j = 0; j < i; j++)
                    if(c == stringbuffer.charAt(j))
                        stringbuffer.setCharAt(j, '/');

            }
        }
        catch(StringIndexOutOfBoundsException _ex) { }
        try
        {
            documentBase = new URL("file:///" + stringbuffer + "/");
            return;
        }
        catch(MalformedURLException _ex)
        {
            return;
        }
    }

    public static URL getDocumentBase()
    {
        if(!initialized)
        {
            initializeApp();
            initialized = true;
        }
        if(documentBase != null)
            return documentBase;
        if(applet != null)
            return applet.getDocumentBase();
        else
            return null;
    }

    private static Applet applet;
    private static URL documentBase;
    private static boolean initialized;
}
